aboutsummaryrefslogtreecommitdiff
path: root/bool.go
diff options
context:
space:
mode:
Diffstat (limited to 'bool.go')
-rw-r--r--bool.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/bool.go b/bool.go
index 70e2e0a..ead8dba 100644
--- a/bool.go
+++ b/bool.go
@@ -34,6 +34,19 @@ func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
func (b *boolValue) IsBoolFlag() bool { return true }
+func boolConv(sval string) (interface{}, error) {
+ return strconv.ParseBool(sval)
+}
+
+// GetBool return the bool value of a flag with the given name
+func (f *FlagSet) GetBool(name string) (bool, error) {
+ val, err := f.getFlagType(name, "bool", boolConv)
+ if err != nil {
+ return false, err
+ }
+ return val.(bool), nil
+}
+
// 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) {