Uint64Flag.ValueFromContext() as convenient accessor
This commit is contained in:
parent
1f621059d3
commit
ca7f26ecb0
@ -825,6 +825,14 @@ func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUint64FlagValueFromContext(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Uint64("myflag", 42, "doc")
|
||||||
|
ctx := NewContext(nil, set, nil)
|
||||||
|
f := &Uint64Flag{Name: "myflag"}
|
||||||
|
expect(t, f.ValueFromContext(ctx), uint64(42))
|
||||||
|
}
|
||||||
|
|
||||||
var durationFlagTests = []struct {
|
var durationFlagTests = []struct {
|
||||||
name string
|
name string
|
||||||
expected string
|
expected string
|
||||||
|
@ -101,6 +101,11 @@ func (f *Uint64Flag) GetEnvVars() []string {
|
|||||||
return f.EnvVars
|
return f.EnvVars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValueFromContext returns the flag’s value in the given Context.
|
||||||
|
func (f *Uint64Flag) ValueFromContext(ctx *Context) uint64 {
|
||||||
|
return ctx.Uint64(f.Name)
|
||||||
|
}
|
||||||
|
|
||||||
// Uint64 looks up the value of a local Uint64Flag, returns
|
// Uint64 looks up the value of a local Uint64Flag, returns
|
||||||
// 0 if not found
|
// 0 if not found
|
||||||
func (c *Context) Uint64(name string) uint64 {
|
func (c *Context) Uint64(name string) uint64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user