Skip to content

Commit

Permalink
Merge pull request #53 from choria-io/52
Browse files Browse the repository at this point in the history
(#52) improve handling of duplicate command errors
  • Loading branch information
ripienaar authored Aug 25, 2024
2 parents d612d92 + 687c692 commit 9e56157
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ func (a *Application) MustParseWithUsage(args []string) (command string) {
fmt.Fprintf(a.errorWriter, "error: %v, use --help for full help including flags and arguments\n\n", err)
ut = a.errorUsageTemplate

case errorIs(err, ErrRequiredArgument, ErrRequiredFlag, ErrUnknownLongFlag, ErrUnknownShortFlag, ErrExpectedFlagArgument, ErrFlagCannotRepeat, ErrUnexpectedArgument):
case errorIs(err, ErrRequiredArgument, ErrRequiredFlag, ErrUnknownLongFlag, ErrUnknownShortFlag, ErrExpectedFlagArgument, ErrFlagCannotRepeat, ErrUnexpectedArgument, ErrDuplicateCommand):
fmt.Fprintf(a.errorWriter, "error: %v\n\n", err)

default:
Expand Down
2 changes: 1 addition & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (c *cmdGroup) init() error {
defaults = append(defaults, cmd.name)
}
if seen[cmd.name] {
return fmt.Errorf("duplicate command %q", cmd.name)
return fmt.Errorf("%w %q", ErrDuplicateCommand, cmd.name)
}
seen[cmd.name] = true
for _, alias := range cmd.aliases {
Expand Down
3 changes: 3 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ var (

// ErrUnexpectedArgument indicates an unexpected argument was encountered
ErrUnexpectedArgument = errors.New("unexpected argument")

// ErrDuplicateCommand indicates that a command was defined multiple times
ErrDuplicateCommand = errors.New("duplicate command")
)

0 comments on commit 9e56157

Please sign in to comment.