rm: match GNU's error for a bad --preserve-root value - #14310
Closed
arbelonson-source wants to merge 1 commit into
Closed
rm: match GNU's error for a bad --preserve-root value#14310arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
--preserve-root validated its value with clap's plain value_parser(["all"]), so an unrecognized value produced clap's own generic wording instead of GNU's single-line 'unrecognized --preserve-root argument: ...' -- notably not the same 'invalid/ambiguous argument ... Valid arguments are: ...' shape used by the other options in this series (uutils#14293, uutils#14303-uutils#14309), and with no abbreviation accepted at all (GNU rejects even 'a'). Resolve the value by hand and report GNU's own, simpler wording. Also fixes the existing test_preserve_root_rejects_unknown_value test, which was asserting clap's wrong wording ('invalid value ...') as though it were correct. AI-assisted-by: Claude Opus 5, via Claude Code
Contributor
|
In this case, our message has more info. |
Contributor
|
Also note that aligning error message with GNU means we introduce a source extracted from GPL program. |
|
GNU testsuite comparison: |
Contributor
|
our error message is better, let's keep it |
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
--preserve-rootvalidates its value with clap's plainvalue_parser(["all"]), so an unrecognized value produces clap's owngeneric wording instead of GNU's:
Found this one while working on
--interactivein the same file(#14309) -- it's the same underlying problem (clap's own wording
instead of GNU's) but not the same class of bug as the rest of this
series (#14293, #14303-#14309): those all had a
ShortcutValueParserproducing a "invalid/ambiguous argument ... Valid arguments are: ..."
shape with abbreviation support.
--preserve-rootuses clap's built-inpossible-values parser instead, GNU's real message is a single,
simpler line with no "Try --help" hint, and no abbreviation is
accepted at all -- GNU rejects even
aforall.Fix
Resolve the value by hand (an exact match against
"all", nothingelse) and report GNU's own wording exactly.
Also fixes the existing
test_preserve_root_rejects_unknown_valuetest, which was asserting clap's wrong wording (
"invalid value 'bogus'") as though it were correct -- it had been written to matchthe bug rather than GNU.
Testing
cargo test -p uu_rm/ fulltests/by-util/test_rm.rssuite: 84 passed, 0 failed.--preserve-root=a).--preserve-rootwithall,a,bogus, empty,All,ALL, and no value at all against GNU rm 9.11 underLC_ALL=C.cargo clippy -p uu_rm --all-targets -- -D warningsandcargo fmt --check: clean.This PR was written with AI assistance (Claude Opus 5, via Claude Code). I've tested the changes but please review the code carefully.