aboutsummaryrefslogtreecommitdiff
path: root/flag.go
diff options
context:
space:
mode:
authorFilipe Brandenburger <[email protected]>2015-01-16 10:43:36 -0800
committerFilipe Brandenburger <[email protected]>2015-01-16 11:42:10 -0800
commitc75d600940b76354bc18d26d10c0ecd03b31f758 (patch)
tree58e0a58ade178186c7a9e69e99edb3b60dc7056a /flag.go
parent99bcedf5411e47380739c8999a6ae3fdd0739fa3 (diff)
Add support for custom boolean flags through IsBoolFlag()
This is consistent with Go's native flag parsing module and can be used to implement custom boolean/tri-state flags. Signed-off-by: Filipe Brandenburger <[email protected]>
Diffstat (limited to 'flag.go')
-rw-r--r--flag.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/flag.go b/flag.go
index 47761a0..2e4cac0 100644
--- a/flag.go
+++ b/flag.go
@@ -466,7 +466,7 @@ func (f *FlagSet) parseLongArg(s string, args []string) (a []string, err error)
return
}
if len(split) == 1 {
- if _, ok := flag.Value.(*boolValue); !ok {
+ if bv, ok := flag.Value.(boolFlag); !ok || !bv.IsBoolFlag() {
err = f.failf("flag needs an argument: %s", s)
return
}
@@ -500,7 +500,7 @@ func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error)
}
}
if alreadythere {
- if _, ok := flag.Value.(*boolValue); ok {
+ if bv, ok := flag.Value.(boolFlag); ok && bv.IsBoolFlag() {
f.setFlag(flag, "true", s)
continue
}