diff --git a/examples_test.go b/examples_test.go index afda009ceb..2167fc9f3c 100644 --- a/examples_test.go +++ b/examples_test.go @@ -182,13 +182,16 @@ func ExampleCommand_Run_commandHelp() { // greet describeit - use it to see a description // // USAGE: - // greet describeit [arguments...] + // greet describeit [options] [arguments...] // // DESCRIPTION: // This is how we describe describeit the function // // OPTIONS: // --help, -h show help + // + // GLOBAL OPTIONS: + // --name string a name to say (default: "pat") } func ExampleCommand_Run_noAction() { diff --git a/help.go b/help.go index 0f7f629caf..30d017d3a1 100644 --- a/help.go +++ b/help.go @@ -126,16 +126,8 @@ func helpCommandAction(ctx context.Context, cmd *Command) error { // Case 3, 5 if len(cmd.VisibleCommands()) == 0 { - - tmpl := cmd.CustomHelpTemplate - if tmpl == "" { - tmpl = CommandHelpTemplate - } - tracef("running HelpPrinter with command %[1]q", cmd.Name) - HelpPrinter(cmd.Root().Writer, tmpl, cmd) - - return nil + return ShowCommandHelp(ctx, cmd.parent, cmd.Name) } tracef("running ShowSubcommandHelp") @@ -303,7 +295,7 @@ func DefaultShowCommandHelp(ctx context.Context, cmd *Command, commandName strin tmpl := subCmd.CustomHelpTemplate if tmpl == "" { - if len(subCmd.Commands) == 0 { + if len(subCmd.VisibleCommands()) == 0 { tracef("using CommandHelpTemplate") tmpl = CommandHelpTemplate } else { diff --git a/help_test.go b/help_test.go index e5c72cad68..6ff88fe4e4 100644 --- a/help_test.go +++ b/help_test.go @@ -571,7 +571,7 @@ func TestShowCommandHelp_HelpPrinterCustom(t *testing.T) { fmt.Fprint(w, "yo") }, arguments: []string{"my-app", "help", "my-command"}, - wantTemplate: SubcommandHelpTemplate, + wantTemplate: CommandHelpTemplate, wantOutput: "yo", }, {