Repository navigation
Conversation
A subcommand that sets no OnUsageError now uses the one of its nearest ancestor that does, the way ArgValidator is already found. An application can then handle usage errors (a wrong flag value, a missing required flag or argument, mutually exclusive flags) once on the root instead of on every command. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mokevnin
added a commit
to getsphericon/sphericon
that referenced
this pull request
Nov 28, 2026
…nd a logged fault (#1898) A wrong flag value, a missing required flag or argument and flags that exclude each other were printed as urfave's help page, then logged by ExitCode as a fault. refuseUsage words them as the command line's other refusals: one line and where the help is. urfave reads OnUsageError only from the command that failed, so newRoot gives it to every command until urfave/cli#2559, which makes it inherited like ArgValidator, ships. Co-authored-by: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What this PR does / why we need it:
OnUsageErroris read only from the command where the usage error happened, whileArgValidatorisalready looked up from the nearest ancestor that sets one. An application that wants one way of
reporting usage errors (a wrong flag value, a missing required flag or argument, mutually exclusive
flags) has to set
OnUsageErroron every command of its tree today, or a subcommand falls back toIncorrect Usageplus help while the error is also returned to the caller.command_run.go:findOnUsageErrorwalks from the command to the root, asfindArgValidatordoes; the four places that called
cmd.OnUsageErroruse it.command.go,funcs.go: the doc comments say the handler is inherited.command_test.go: a subcommand's flag error and required flag reach the root's handler (with thesubcommand as
cmdandisSubcommandtrue), and a subcommand's own handler still wins.godoc-current.txt,testdata/godoc-v3.x.txt: regenerated and promoted withmake v3approve;the diff is the two doc comments only.
Which issue(s) this PR fixes:
None filed; happy to open one if you prefer to discuss it there first.
Special notes for your reviewer:
Behaviour changes only for a subcommand without its own
OnUsageErrorwhose ancestor has one: itused to print
Incorrect Usageand help, and now the ancestor's handler runs. That is what thehandler on the root was most likely meant for, and it matches
ArgValidator, but it is a change inthe v3 series, so please say if you would rather have it opt-in.
Testing
make generate,make vet,make test(99.4% coverage) pass, andmake v3diffis clean aftermake v3approve. The two inheritance tests fail without the change incommand_run.go.Release Notes
🤖 Generated with Claude Code