IntFlag.ValueFromContext() as convenient accessor

This commit is contained in:
Tilo Prütz
2022-04-22 16:12:11 +02:00
parent 8bd5fb2390
commit bf18c00347
2 changed files with 13 additions and 0 deletions

View File

@@ -663,6 +663,14 @@ func TestIntFlagApply_SetsAllNames(t *testing.T) {
expect(t, v, 5)
}
func TestIntFlagValueFromContext(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 42, "doc")
ctx := NewContext(nil, set, nil)
f := &IntFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), 42)
}
var int64FlagTests = []struct {
name string
expected string