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
Copy Markdown
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I apologize. This sort of thing is ancillary to my primary role where I deal with 100's of open source project in an environment that doesn't use git. I had hoped to return to this with a short test case, but that hasn't happened.

When I notice things, I try to give back, but I will always have a tendency to just toss things over the wall and walk away. You are welcome to use as much or as little as you wish.

I assumed, if a developer has a need to change the usage message, they probably have a need to parse the arguments. 🤷

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