Skip to content

Commit 5e6457b

Browse files
committed
Fix issue 2260: Try not to break custom Help cmds.
Expand the check for the default help command to look at more than just the name.
1 parent fd14621 commit 5e6457b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

command_run.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
141141
var rargs Args = &stringSliceArgs{v: osArgs}
142142
var args Args = &stringSliceArgs{rargs.Tail()}
143143

144-
if cmd.isCompletionCommand || cmd.Name == helpName {
144+
if cmd.isCompletionCommand || isHelpCommand(cmd) {
145145
tracef("special command detected, skipping pre-parse (cmd=%[1]q)", cmd.Name)
146146
cmd.parsedArgs = args
147147
return ctx, cmd.Action(ctx, cmd)
@@ -365,3 +365,22 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
365365
tracef("returning deferErr (cmd=%[1]q) %[2]q", cmd.Name, deferErr)
366366
return ctx, deferErr
367367
}
368+
369+
func isHelpCommand(cmd *Command) bool {
370+
if cmd.Name != helpName {
371+
return false
372+
}
373+
if len(cmd.Aliases) != 1 {
374+
return false
375+
}
376+
if cmd.Aliases[0] != helpAlias {
377+
return false
378+
}
379+
if cmd.Usage != UsageCommandHelp {
380+
return false
381+
}
382+
if cmd.ArgsUsage != ArgsUsageCommandHelp {
383+
return false
384+
}
385+
return true
386+
}

0 commit comments

Comments
 (0)