aboutsummaryrefslogtreecommitdiff
path: root/bool.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:27:22 -0800
commit8f20f9e44d9799cc2b51bfb2f6ab857f492aa27d (patch)
treec279a0bda16b11b59f1b162b84ae588c7cd608e4 /bool.go
parente4f7d00f344b0954fa3791a8527d10ba7334eceb (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 'bool.go')
-rw-r--r--bool.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/bool.go b/bool.go
index 60beb54..617971a 100644
--- a/bool.go
+++ b/bool.go
@@ -5,6 +5,13 @@ import (
"strconv"
)
+// optional interface to indicate boolean flags that can be
+// supplied without "=value" text
+type boolFlag interface {
+ Value
+ IsBoolFlag() bool
+}
+
// -- bool Value
type boolValue bool
@@ -21,6 +28,8 @@ func (b *boolValue) Set(s string) error {
func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
+func (b *boolValue) IsBoolFlag() bool { return true }
+
// BoolVar defines a bool flag with specified name, default value, and usage string.
// The argument p points to a bool variable in which to store the value of the flag.
func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {