From 65da20beab3e0596b247efee5ffe55bec8eed4d8 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 13 Jul 2016 14:44:13 -0700 Subject: [PATCH] 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 --- app_test.go | 1 + help.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app_test.go b/app_test.go index 9c6b960..b0b02e6 100644 --- a/app_test.go +++ b/app_test.go @@ -908,6 +908,7 @@ func TestApp_Run_CommandWithSubcommandHasHelpTopic(t *testing.T) { Name: "foo", Description: "descriptive wall of text about how it does foo things", Subcommands: []Command{subCmdBar, subCmdBaz}, + Action: func(c *Context) error { return nil }, } app.Commands = []Command{cmd} diff --git a/help.go b/help.go index 0f4cf14..ba34719 100644 --- a/help.go +++ b/help.go @@ -240,7 +240,7 @@ func checkCommandHelp(c *Context, name string) bool { } func checkSubcommandHelp(c *Context) bool { - if c.GlobalBool("h") || c.GlobalBool("help") { + if c.Bool("h") || c.Bool("help") { ShowSubcommandHelp(c) return true }