Skip to content

Commit bb94d63

Browse files
authored
Merge pull request #2287 from markshep-wbg/fix-command-help
Made command help more consistent
2 parents d525e78 + e7c80ce commit bb94d63

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

examples_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,16 @@ func ExampleCommand_Run_commandHelp() {
182182
// greet describeit - use it to see a description
183183
//
184184
// USAGE:
185-
// greet describeit [arguments...]
185+
// greet describeit [options] [arguments...]
186186
//
187187
// DESCRIPTION:
188188
// This is how we describe describeit the function
189189
//
190190
// OPTIONS:
191191
// --help, -h show help
192+
//
193+
// GLOBAL OPTIONS:
194+
// --name string a name to say (default: "pat")
192195
}
193196

194197
func ExampleCommand_Run_noAction() {

help.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,8 @@ func helpCommandAction(ctx context.Context, cmd *Command) error {
126126

127127
// Case 3, 5
128128
if len(cmd.VisibleCommands()) == 0 {
129-
130-
tmpl := cmd.CustomHelpTemplate
131-
if tmpl == "" {
132-
tmpl = CommandHelpTemplate
133-
}
134-
135129
tracef("running HelpPrinter with command %[1]q", cmd.Name)
136-
HelpPrinter(cmd.Root().Writer, tmpl, cmd)
137-
138-
return nil
130+
return ShowCommandHelp(ctx, cmd.parent, cmd.Name)
139131
}
140132

141133
tracef("running ShowSubcommandHelp")
@@ -301,7 +293,7 @@ func DefaultShowCommandHelp(ctx context.Context, cmd *Command, commandName strin
301293

302294
tmpl := subCmd.CustomHelpTemplate
303295
if tmpl == "" {
304-
if len(subCmd.Commands) == 0 {
296+
if len(subCmd.VisibleCommands()) == 0 {
305297
tracef("using CommandHelpTemplate")
306298
tmpl = CommandHelpTemplate
307299
} else {

help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ func TestShowCommandHelp_HelpPrinterCustom(t *testing.T) {
571571
fmt.Fprint(w, "yo")
572572
},
573573
arguments: []string{"my-app", "help", "my-command"},
574-
wantTemplate: SubcommandHelpTemplate,
574+
wantTemplate: CommandHelpTemplate,
575575
wantOutput: "yo",
576576
},
577577
{

0 commit comments

Comments
 (0)