diff options
| author | Filipe Brandenburger <[email protected]> | 2015-01-16 10:43:36 -0800 |
|---|---|---|
| committer | Filipe Brandenburger <[email protected]> | 2015-01-16 11:42:10 -0800 |
| commit | c75d600940b76354bc18d26d10c0ecd03b31f758 (patch) | |
| tree | 58e0a58ade178186c7a9e69e99edb3b60dc7056a /bool.go | |
| parent | 99bcedf5411e47380739c8999a6ae3fdd0739fa3 (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.go | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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 @@ -25,6 +32,8 @@ func (b *boolValue) Type() string { 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) { |
