parent
d3a4d5467b
commit
e3ace79a91
@ -5,6 +5,7 @@
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- Pluggable flag-level help text rendering via `cli.DefaultFlagStringFunc`
|
||||
- `context.GlobalBoolT` was added as an analogue to `context.GlobalBool`
|
||||
|
||||
### Changed
|
||||
- `Float64Flag`, `IntFlag`, and `DurationFlag` default values are no longer
|
||||
|
@ -104,6 +104,14 @@ func (c *Context) GlobalBool(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Looks up the value of a global bool flag, returns true if no bool flag exists
|
||||
func (c *Context) GlobalBoolT(name string) bool {
|
||||
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||
return lookupBoolT(name, fs)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Looks up the value of a global string flag, returns "" if no string flag exists
|
||||
func (c *Context) GlobalString(name string) string {
|
||||
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||
|
@ -82,6 +82,30 @@ func TestContext_BoolT(t *testing.T) {
|
||||
expect(t, c.BoolT("myflag"), true)
|
||||
}
|
||||
|
||||
func TestContext_GlobalBool(t *testing.T) {
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
|
||||
globalSet := flag.NewFlagSet("test-global", 0)
|
||||
globalSet.Bool("myflag", false, "doc")
|
||||
globalCtx := NewContext(nil, globalSet, nil)
|
||||
|
||||
c := NewContext(nil, set, globalCtx)
|
||||
expect(t, c.GlobalBool("myflag"), false)
|
||||
expect(t, c.GlobalBool("nope"), false)
|
||||
}
|
||||
|
||||
func TestContext_GlobalBoolT(t *testing.T) {
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
|
||||
globalSet := flag.NewFlagSet("test-global", 0)
|
||||
globalSet.Bool("myflag", true, "doc")
|
||||
globalCtx := NewContext(nil, globalSet, nil)
|
||||
|
||||
c := NewContext(nil, set, globalCtx)
|
||||
expect(t, c.GlobalBoolT("myflag"), true)
|
||||
expect(t, c.GlobalBoolT("nope"), false)
|
||||
}
|
||||
|
||||
func TestContext_Args(t *testing.T) {
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool("myflag", false, "doc")
|
||||
|
Loading…
Reference in New Issue
Block a user