Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
46 changes: 46 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
HideHelpCommand: true,
Flags: []Flag{
&StringFlag{
Name: "foo",
},
},
Commands: []*Command{
{
Name: "frobbly",
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{
Expand Down
Loading