Int64SliceFlag.ValueFromContext() as convenient accessor
This commit is contained in:
parent
18b44dfb29
commit
dcc47855b8
@ -174,6 +174,11 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValueFromContext returns the flag’s value in the given Context.
|
||||||
|
func (f *Int64SliceFlag) ValueFromContext(ctx *Context) []int64 {
|
||||||
|
return ctx.Int64Slice(f.Name)
|
||||||
|
}
|
||||||
|
|
||||||
// Int64Slice looks up the value of a local Int64SliceFlag, returns
|
// Int64Slice looks up the value of a local Int64SliceFlag, returns
|
||||||
// nil if not found
|
// nil if not found
|
||||||
func (c *Context) Int64Slice(name string) []int64 {
|
func (c *Context) Int64Slice(name string) []int64 {
|
||||||
|
@ -1035,6 +1035,14 @@ func TestInt64SliceFlag_ReturnNil(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInt64SliceFlagValueFromContext(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Var(NewInt64Slice(1, 2, 3), "myflag", "doc")
|
||||||
|
ctx := NewContext(nil, set, nil)
|
||||||
|
f := &Int64SliceFlag{Name: "myflag"}
|
||||||
|
expect(t, f.ValueFromContext(ctx), []int64{1, 2, 3})
|
||||||
|
}
|
||||||
|
|
||||||
var float64FlagTests = []struct {
|
var float64FlagTests = []struct {
|
||||||
name string
|
name string
|
||||||
expected string
|
expected string
|
||||||
|
Loading…
Reference in New Issue
Block a user