From 4031d4cbc66dd78ff4103483b8225109faadfeef Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Thu, 19 Mar 2026 21:52:12 +0000 Subject: [PATCH 1/3] Call the standard ShowCommandHelp() function for subcommands too --- help.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/help.go b/help.go index 9db9df510c..1bc4a3ac80 100644 --- a/help.go +++ b/help.go @@ -125,16 +125,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") From 27816c3c9b3ee4f8f9d9ccf058eb6c295310071d Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Thu, 19 Mar 2026 22:48:24 +0000 Subject: [PATCH 2/3] Fixed DefaultShowCommandHelp() when all subcommands are hidden --- help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/help.go b/help.go index 1bc4a3ac80..53b43b0531 100644 --- a/help.go +++ b/help.go @@ -296,7 +296,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 { From 159faa08fed0847cc4bda19ed8c85f41c39f1af1 Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Thu, 19 Mar 2026 22:59:45 +0000 Subject: [PATCH 3/3] Fixed test cases --- examples_test.go | 5 ++++- help_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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_test.go b/help_test.go index 6a11bd9e19..f060d2a5fe 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", }, {