Correctly show help message if -h is provided to subcommand

Currently, if an action is specified on a subcommand, it ignores the
`-h` and `--help` flags if passed to the subcommand, e.g.:

`foo bar -h`

would call the default action on `bar` rather than show the help
documentation.

Fixes #477
This commit is contained in:
Jesse Szwedko 2016-07-13 14:44:13 -07:00
parent 73aa67b7a2
commit 65da20beab
2 changed files with 2 additions and 1 deletions

View File

@ -908,6 +908,7 @@ func TestApp_Run_CommandWithSubcommandHasHelpTopic(t *testing.T) {
Name: "foo", Name: "foo",
Description: "descriptive wall of text about how it does foo things", Description: "descriptive wall of text about how it does foo things",
Subcommands: []Command{subCmdBar, subCmdBaz}, Subcommands: []Command{subCmdBar, subCmdBaz},
Action: func(c *Context) error { return nil },
} }
app.Commands = []Command{cmd} app.Commands = []Command{cmd}

View File

@ -240,7 +240,7 @@ func checkCommandHelp(c *Context, name string) bool {
} }
func checkSubcommandHelp(c *Context) bool { func checkSubcommandHelp(c *Context) bool {
if c.GlobalBool("h") || c.GlobalBool("help") { if c.Bool("h") || c.Bool("help") {
ShowSubcommandHelp(c) ShowSubcommandHelp(c)
return true return true
} }