diff --git a/flag_float64_slice.go b/flag_float64_slice.go index 984f77f..c987688 100644 --- a/flag_float64_slice.go +++ b/flag_float64_slice.go @@ -175,6 +175,11 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error { return nil } +// ValueFromContext returns the flag’s value in the given Context. +func (f *Float64SliceFlag) ValueFromContext(ctx *Context) []float64 { + return ctx.Float64Slice(f.Name) +} + // Float64Slice looks up the value of a local Float64SliceFlag, returns // nil if not found func (c *Context) Float64Slice(name string) []float64 { diff --git a/flag_test.go b/flag_test.go index edf9e8e..ce9b5a3 100644 --- a/flag_test.go +++ b/flag_test.go @@ -1117,6 +1117,14 @@ func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) { } } +func TestFloat64SliceFlagValueFromContext(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Var(NewFloat64Slice(1.23, 4.56), "myflag", "doc") + ctx := NewContext(nil, set, nil) + f := &Float64SliceFlag{Name: "myflag"} + expect(t, f.ValueFromContext(ctx), []float64{1.23, 4.56}) +} + var genericFlagTests = []struct { name string value Generic