|
|
@ -69,9 +69,31 @@ func TestContext_IsSet(t *testing.T) {
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set.Bool("myflag", false, "doc")
|
|
|
|
set.Bool("myflag", false, "doc")
|
|
|
|
set.String("otherflag", "hello world", "doc")
|
|
|
|
set.String("otherflag", "hello world", "doc")
|
|
|
|
c := cli.NewContext(nil, set, set)
|
|
|
|
globalSet := flag.NewFlagSet("test", 0)
|
|
|
|
|
|
|
|
globalSet.Bool("myflagGlobal", true, "doc")
|
|
|
|
|
|
|
|
c := cli.NewContext(nil, set, globalSet)
|
|
|
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
|
|
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
|
|
|
|
|
|
|
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
|
|
|
expect(t, c.IsSet("myflag"), true)
|
|
|
|
expect(t, c.IsSet("myflag"), true)
|
|
|
|
expect(t, c.IsSet("otherflag"), false)
|
|
|
|
expect(t, c.IsSet("otherflag"), false)
|
|
|
|
expect(t, c.IsSet("bogusflag"), false)
|
|
|
|
expect(t, c.IsSet("bogusflag"), false)
|
|
|
|
|
|
|
|
expect(t, c.IsSet("myflagGlobal"), false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestContext_GlobalIsSet(t *testing.T) {
|
|
|
|
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
|
|
|
|
set.Bool("myflag", false, "doc")
|
|
|
|
|
|
|
|
set.String("otherflag", "hello world", "doc")
|
|
|
|
|
|
|
|
globalSet := flag.NewFlagSet("test", 0)
|
|
|
|
|
|
|
|
globalSet.Bool("myflagGlobal", true, "doc")
|
|
|
|
|
|
|
|
globalSet.Bool("myflagGlobalUnset", true, "doc")
|
|
|
|
|
|
|
|
c := cli.NewContext(nil, set, globalSet)
|
|
|
|
|
|
|
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
|
|
|
|
|
|
|
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
|
|
|
|
|
|
|
expect(t, c.GlobalIsSet("myflag"), false)
|
|
|
|
|
|
|
|
expect(t, c.GlobalIsSet("otherflag"), false)
|
|
|
|
|
|
|
|
expect(t, c.GlobalIsSet("bogusflag"), false)
|
|
|
|
|
|
|
|
expect(t, c.GlobalIsSet("myflagGlobal"), true)
|
|
|
|
|
|
|
|
expect(t, c.GlobalIsSet("myflagGlobalUnset"), false)
|
|
|
|
|
|
|
|
expect(t, c.GlobalIsSet("bogusGlobal"), false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|