Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 2 additions & 10 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand Down