Merge pull request #397 from codegangsta/add-global-boolt
Add context.GlobalBoolT
This commit is contained in:
commit
8ef3b8f7bb
@ -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`
|
||||
- Support for hiding commands by setting `Hidden: true` -- this will hide the
|
||||
commands in help output
|
||||
|
||||
|
@ -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