Allow optional flags by asking if its been set/present on the command line

This commit is contained in:
fraenkel
2013-12-18 12:09:16 -06:00
parent 5b3346951a
commit f88df0aa5a
2 changed files with 24 additions and 1 deletions

View File

@@ -45,3 +45,14 @@ func TestContext_Args(t *testing.T) {
expect(t, len(c.Args()), 2)
expect(t, c.Bool("myflag"), true)
}
func TestContext_IsSet(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
set.String("otherflag", "hello world", "doc")
c := cli.NewContext(nil, set, set)
set.Parse([]string{"--myflag", "bat", "baz"})
expect(t, c.IsSet("myflag"), true)
expect(t, c.IsSet("otherflag"), false)
expect(t, c.IsSet("bogusflag"), false)
}