Fix global flags processing on top level

This fixes a regression introduced by #227. When looking up global flags by walking up the parent context's we need to consider the special case when we are starting at the very top and there is no parent context to start the traversal.

Fixes #252
This commit is contained in:
Fabian Ruff
2015-06-29 23:20:27 +02:00
parent ad480243a8
commit a2d4ae5939
2 changed files with 34 additions and 10 deletions

View File

@@ -627,6 +627,23 @@ func TestAppCommandNotFound(t *testing.T) {
expect(t, subcommandRun, false)
}
func TestGlobalFlag(t *testing.T) {
var globalFlag string
var globalFlagSet bool
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.StringFlag{Name: "global, g", Usage: "global"},
}
app.Action = func(c *cli.Context) {
globalFlag = c.GlobalString("global")
globalFlagSet = c.GlobalIsSet("global")
}
app.Run([]string{"command", "-g", "foo"})
expect(t, globalFlag, "foo")
expect(t, globalFlagSet, true)
}
func TestGlobalFlagsInSubcommands(t *testing.T) {
subcommandRun := false
parentFlag := false