shred: match GNU's error for a bad --remove value - #14307
Closed
arbelonson-source wants to merge 1 commit into
Closed
shred: match GNU's error for a bad --remove value#14307arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
--remove validated its value with a plain ShortcutValueParser, so an
unrecognized or ambiguous value produced clap's own generic wording
instead of GNU's ('invalid argument ... for --remove / Valid
arguments are: / - 'unlink' / ...').
Resolve the value against the option's own choice list by hand,
accepting any unambiguous abbreviation the way GNU does, checking for
an exact match first since one choice ('wipe') is itself a prefix of
another ('wipesync') -- without that check, --remove=wipe would
wrongly report itself as ambiguous. Moved this resolution above the
missing-file-operand check: GNU validates an option's own value during
option parsing, before it looks at operands at all, so 'shred
--remove=wip' (no file) reports the ambiguous argument, not a missing
operand.
AI-assisted-by: Claude Opus 5, via Claude Code
Contributor
|
see #14308 (comment) |
|
GNU testsuite comparison: |
Contributor
|
our error message is good enough, no need for the extra complexity |
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
--removevalidates its value with a plainShortcutValueParser, soan unrecognized or ambiguous value produces clap's own generic
wording instead of GNU's:
Fix
Resolve the value against the option's own choice list by hand,
accepting any unambiguous abbreviation the way GNU does. Two things
this needed that the other utilities in this same series (#14293,
#14303, #14304, #14305, #14306) didn't:
wipe) isitself a prefix of another (
wipesync) -- without that check,--remove=wipewould wrongly report itself as ambiguous between thetwo. (Caught by this repo's own existing
test_shred_remove_wipetest, which was already asserting the correct, non-ambiguous
behavior.)
validates an option's own value during option parsing, before it
ever looks at operands, so
shred --remove=wip(no file at all)reports the ambiguous argument, not a missing operand. Doing the
validation later, in
uumain's own logic, had silently changed thatordering.
Testing
cargo test -p uu_shred/ fulltests/by-util/test_shred.rssuite: 29 passed, 0 failed.test_invalid_remove_arg/test_ambiguous_remove_argtests to assert the exact GNU wording instead of just the exit code.--removevalue (all real choices/abbreviations, invalid, ambiguous, empty, and the no-file-operand ordering case) against GNU shred 9.11 underLC_ALL=C.cargo clippy -p uu_shred --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.