Int64Flag.ValueFromContext() as convenient accessor
This commit is contained in:
parent
bf18c00347
commit
18b44dfb29
@ -101,6 +101,11 @@ func (f *Int64Flag) Apply(set *flag.FlagSet) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValueFromContext returns the flag’s value in the given Context.
|
||||||
|
func (f *Int64Flag) ValueFromContext(ctx *Context) int64 {
|
||||||
|
return ctx.Int64(f.Name)
|
||||||
|
}
|
||||||
|
|
||||||
// Int64 looks up the value of a local Int64Flag, returns
|
// Int64 looks up the value of a local Int64Flag, returns
|
||||||
// 0 if not found
|
// 0 if not found
|
||||||
func (c *Context) Int64(name string) int64 {
|
func (c *Context) Int64(name string) int64 {
|
||||||
|
@ -709,6 +709,14 @@ func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInt64FlagValueFromContext(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Int64("myflag", 42, "doc")
|
||||||
|
ctx := NewContext(nil, set, nil)
|
||||||
|
f := &Int64Flag{Name: "myflag"}
|
||||||
|
expect(t, f.ValueFromContext(ctx), int64(42))
|
||||||
|
}
|
||||||
|
|
||||||
var uintFlagTests = []struct {
|
var uintFlagTests = []struct {
|
||||||
name string
|
name string
|
||||||
expected string
|
expected string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user