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