Skip to content
Open
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
21 changes: 20 additions & 1 deletion command_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
var rargs Args = &stringSliceArgs{v: osArgs}
var args Args = &stringSliceArgs{rargs.Tail()}

if cmd.isCompletionCommand || cmd.Name == helpName {
if cmd.isCompletionCommand || isHelpCommand(cmd) {
tracef("special command detected, skipping pre-parse (cmd=%[1]q)", cmd.Name)
cmd.parsedArgs = args
return ctx, cmd.Action(ctx, cmd)
Expand Down Expand Up @@ -365,3 +365,22 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
tracef("returning deferErr (cmd=%[1]q) %[2]q", cmd.Name, deferErr)
return ctx, deferErr
}

func isHelpCommand(cmd *Command) bool {
if cmd.Name != helpName {
return false
}
if len(cmd.Aliases) != 1 {
return false
}
if cmd.Aliases[0] != helpAlias {
return false
}
if cmd.Usage != UsageCommandHelp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldnt depend on cmd.Usage and cmd.ArgsUsage

return false
}
if cmd.ArgsUsage != ArgsUsageCommandHelp {
return false
}
return true
}