diff --git a/help.go b/help.go index 37b1091126..c5a993fd90 100644 --- a/help.go +++ b/help.go @@ -124,8 +124,7 @@ func helpCommandAction(ctx context.Context, cmd *Command) error { } // Case 3, 5 - if (len(cmd.Commands) == 1 && !cmd.HideHelp) || - (len(cmd.Commands) == 0 && cmd.HideHelp) { + if len(cmd.VisibleCommands()) == 0 { tmpl := cmd.CustomHelpTemplate if tmpl == "" { diff --git a/help_test.go b/help_test.go index fad4242128..6a11bd9e19 100644 --- a/help_test.go +++ b/help_test.go @@ -797,6 +797,52 @@ GLOBAL OPTIONS: assert.Contains(t, output.String(), expected, "expected output to include global options") } +func TestShowSubcommandHelp_GlobalOptions_HideHelpCommand(t *testing.T) { + cmd := &Command{ + Flags: []Flag{ + &StringFlag{ + Name: "foo", + }, + }, + Commands: []*Command{ + { + Name: "frobbly", + HideHelpCommand: true, + Flags: []Flag{ + &StringFlag{ + Name: "bar", + Local: true, + }, + }, + Action: func(context.Context, *Command) error { + return nil + }, + }, + }, + } + + output := &bytes.Buffer{} + cmd.Writer = output + + _ = cmd.Run(buildTestContext(t), []string{"foo", "frobbly", "--help"}) + + expected := `NAME: + foo frobbly + +USAGE: + foo frobbly [options] + +OPTIONS: + --bar string + --help, -h show help + +GLOBAL OPTIONS: + --foo string +` + + assert.Contains(t, output.String(), expected, "expected output to include global options") +} + func TestShowSubcommandHelp_SubcommandUsageText(t *testing.T) { cmd := &Command{ Commands: []*Command{