IntSliceFlag.ValueFromContext() as convenient accessor

This commit is contained in:
Tilo Prütz
2022-04-22 16:49:38 +02:00
parent dcc47855b8
commit 6d7f859008
2 changed files with 13 additions and 0 deletions

View File

@@ -939,6 +939,14 @@ func TestIntSliceFlag_SetFromParentContext(t *testing.T) {
}
}
func TestIntSliceFlagValueFromContext(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Var(NewIntSlice(1, 2, 3), "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &IntSliceFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), []int{1, 2, 3})
}
var int64SliceFlagTests = []struct {
name string
aliases []string