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_test.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_test.go')
| -rw-r--r-- | bool_test.go | 18 |
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) + } +} |
