Skip to content

OnUsageErrorFunc now handles mutually exclusive flag errors #2147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ayoisaiah
Copy link

What type of PR is this?

  • bug

What this PR does / why we need it:

The PR allows the OnUsageErrorFunc to also handle errors reported by MutuallyExclusiveFlags

Which issue(s) this PR fixes:

Fixes #2146

Release Notes

NONE

@ayoisaiah ayoisaiah requested a review from a team as a code owner May 24, 2025 15:38
@@ -223,7 +223,11 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context

for _, grp := range cmd.MutuallyExclusiveFlags {
if err := grp.check(cmd); err != nil {
_ = ShowSubcommandHelp(cmd)
if cmd.OnUsageError != nil {
err = cmd.OnUsageError(ctx, cmd, err, cmd.parent != nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ayoisaiah Can you add a test case to cover this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

✋ I will cover it with tests and make another PR

@dearchap dearchap closed this Jun 6, 2025
@dearchap
Copy link
Contributor

dearchap commented Jun 6, 2025

Fixed by #2152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OnUsageError function doesn't trigger for errors caused by mutually exclusive flags
3 participants