aboutsummaryrefslogtreecommitdiff
path: root/bool_test.go
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-05-08 11:54:10 -0400
committerEric Paris <[email protected]>2015-06-22 15:29:55 -0400
commitb319e90e90fa3261384806182c8f147a4d16c46a (patch)
tree3aa6fe2c2f76e0360b07c2e1d31d9aa7c6262a4e /bool_test.go
parent9d0766ead9e237647941f8b8970522f5f0d30aa3 (diff)
Set default values if no arg given
Diffstat (limited to 'bool_test.go')
-rw-r--r--bool_test.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/bool_test.go b/bool_test.go
index a2e1c5d..febf667 100644
--- a/bool_test.go
+++ b/bool_test.go
@@ -59,7 +59,8 @@ func (v *triStateValue) Type() string {
func setUpFlagSet(tristate *triStateValue) *FlagSet {
f := NewFlagSet("test", ContinueOnError)
*tristate = triStateFalse
- f.VarP(tristate, "tristate", "t", "tristate value (true, maybe or false)")
+ flag := f.VarPF(tristate, "tristate", "t", "tristate value (true, maybe or false)")
+ flag.NoOptDefVal = "true"
return f
}
@@ -162,3 +163,18 @@ func TestInvalidValue(t *testing.T) {
t.Fatal("expected an error but did not get any, tristate has value", tristate)
}
}
+
+func TestBoolP(t *testing.T) {
+ b := BoolP("bool", "b", false, "bool value in CommandLine")
+ c := BoolP("c", "c", false, "other bool value")
+ args := []string{"--bool"}
+ if err := CommandLine.Parse(args); err != nil {
+ t.Error("expected no error, got ", err)
+ }
+ if *b != true {
+ t.Errorf("expected b=true got b=%s", b)
+ }
+ if *c != false {
+ t.Errorf("expect c=false got c=%s", c)
+ }
+}