diff options
| author | Eric Paris <[email protected]> | 2015-06-22 14:30:36 -0500 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-06-22 14:30:36 -0500 |
| commit | 6ff05c5c0bd3aa363f22fa43042e9cbd1663ab4a (patch) | |
| tree | e27225869f2771ded175b16e1ce51e8f9cdcbdf6 /bool.go | |
| parent | 9d0766ead9e237647941f8b8970522f5f0d30aa3 (diff) | |
| parent | 469982769211123a1718ad9edf5d03bd39aed547 (diff) | |
Merge pull request #20 from eparis/optional-args
Fix '--flag arg' and Allow flags to take optional arguments
Diffstat (limited to 'bool.go')
| -rw-r--r-- | bool.go | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -50,31 +50,31 @@ func (f *FlagSet) GetBool(name string) (bool, error) { // 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) { - f.VarP(newBoolValue(value, p), name, "", usage) + f.BoolVarP(p, name, "", value, usage) } // Like BoolVar, but accepts a shorthand letter that can be used after a single dash. func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { - f.VarP(newBoolValue(value, p), name, shorthand, usage) + flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) + flag.NoOptDefVal = "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 BoolVar(p *bool, name string, value bool, usage string) { - CommandLine.VarP(newBoolValue(value, p), name, "", usage) + BoolVarP(p, name, "", value, usage) } // Like BoolVar, but accepts a shorthand letter that can be used after a single dash. func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { - CommandLine.VarP(newBoolValue(value, p), name, shorthand, usage) + flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) + flag.NoOptDefVal = "true" } // Bool defines a bool flag with specified name, default value, and usage string. // The return value is the address of a bool variable that stores the value of the flag. func (f *FlagSet) Bool(name string, value bool, usage string) *bool { - p := new(bool) - f.BoolVarP(p, name, "", value, usage) - return p + return f.BoolP(name, "", value, usage) } // Like Bool, but accepts a shorthand letter that can be used after a single dash. @@ -87,10 +87,11 @@ func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool // Bool defines a bool flag with specified name, default value, and usage string. // The return value is the address of a bool variable that stores the value of the flag. func Bool(name string, value bool, usage string) *bool { - return CommandLine.BoolP(name, "", value, usage) + return BoolP(name, "", value, usage) } // Like Bool, but accepts a shorthand letter that can be used after a single dash. func BoolP(name, shorthand string, value bool, usage string) *bool { - return CommandLine.BoolP(name, shorthand, value, usage) + b := CommandLine.BoolP(name, shorthand, value, usage) + return b } |
