Merge pull request #227 from databus23/global-flags-from-all-parents

Collect global flags from the full command hierarchy
This commit is contained in:
Jesse Szwedko
2015-06-01 21:25:30 -07:00
6 changed files with 75 additions and 31 deletions

View File

@@ -629,6 +629,7 @@ func TestAppCommandNotFound(t *testing.T) {
func TestGlobalFlagsInSubcommands(t *testing.T) {
subcommandRun := false
parentFlag := false
app := cli.NewApp()
app.Flags = []cli.Flag{
@@ -638,6 +639,9 @@ func TestGlobalFlagsInSubcommands(t *testing.T) {
app.Commands = []cli.Command{
cli.Command{
Name: "foo",
Flags: []cli.Flag{
cli.BoolFlag{Name: "parent, p", Usage: "Parent flag"},
},
Subcommands: []cli.Command{
{
Name: "bar",
@@ -645,15 +649,19 @@ func TestGlobalFlagsInSubcommands(t *testing.T) {
if c.GlobalBool("debug") {
subcommandRun = true
}
if c.GlobalBool("parent") {
parentFlag = true
}
},
},
},
},
}
app.Run([]string{"command", "-d", "foo", "bar"})
app.Run([]string{"command", "-d", "foo", "-p", "bar"})
expect(t, subcommandRun, true)
expect(t, parentFlag, true)
}
func TestApp_Run_CommandWithSubcommandHasHelpTopic(t *testing.T) {