diff --git a/flag_float64.go b/flag_float64.go index 0ac5b43..f2eb040 100644 --- a/flag_float64.go +++ b/flag_float64.go @@ -101,6 +101,11 @@ func (f *Float64Flag) Apply(set *flag.FlagSet) error { return nil } +// ValueFromContext returns the flag’s value in the given Context. +func (f *Float64Flag) ValueFromContext(ctx *Context) float64 { + return ctx.Float64(f.Name) +} + // Float64 looks up the value of a local Float64Flag, returns // 0 if not found func (c *Context) Float64(name string) float64 { diff --git a/flag_test.go b/flag_test.go index 2f41f42..edf9e8e 100644 --- a/flag_test.go +++ b/flag_test.go @@ -1068,6 +1068,14 @@ func TestFloat64FlagApply_SetsAllNames(t *testing.T) { expect(t, v, float64(43.33333)) } +func TestFloat64FlagValueFromContext(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Float64("myflag", 1.23, "doc") + ctx := NewContext(nil, set, nil) + f := &Float64Flag{Name: "myflag"} + expect(t, f.ValueFromContext(ctx), 1.23) +} + var float64SliceFlagTests = []struct { name string aliases []string