cut: match GNU's error for a bad --whitespace-delimited value - #14312
Closed
arbelonson-source wants to merge 1 commit into
Closed
cut: match GNU's error for a bad --whitespace-delimited value#14312arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
--whitespace-delimited validated its value with a plain
ShortcutValueParser, so an unrecognized value produced clap's own
generic wording instead of GNU's ('invalid argument ... for
--whitespace-delimited / Valid arguments are: / - 'trimmed' / ...').
Resolve the value against the option's own (single-choice) list by
hand, accepting any unambiguous abbreviation the way GNU does --
including the empty string, e.g. --whitespace-delimited=: with only
one choice, the empty string (a prefix of every choice, same as the
other options fixed in this series) names it unambiguously, so it
resolves to 'trimmed' rather than erroring. An existing test
(test_whitespace_delimited_long_and_trimmed) already asserted this
exact behavior for '' and caught my first attempt, which mirrored the
other fixes' guard against a *genuinely* ambiguous empty value and
wrongly rejected it here where there is nothing to be ambiguous with.
AI-assisted-by: Claude Opus 5, via Claude Code
Contributor
|
No meaning change. Please stop aligning error message with GNU by removing clap. |
|
GNU testsuite comparison: |
This was referenced Aug 31, 2026
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
--whitespace-delimitedvalidates its value with a plainShortcutValueParser, so an unrecognized value produces clap's owngeneric wording instead of GNU's:
Fix
Same fix already shipped across this series (#14293, #14303-#14311):
resolve the value against the option's own choice list by hand,
accepting any unambiguous abbreviation the way GNU does.
One thing specific to this option, since it has only a single
choice: the empty string (
--whitespace-delimited=) is a prefix ofevery choice, same as it is for the other options in this series --
but here there's only one choice for it to be a prefix of, so it
names it unambiguously rather than being ambiguous. GNU accepts it and
treats it exactly like
=trimmed:An existing test (
test_whitespace_delimited_long_and_trimmed, whichalready looped over
["trimmed", "tri", ""]) caught my first attemptat this fix immediately -- I'd carried over the same
not-empty-unless-otherwise-resolvable guard from the other options in
this series, which is correct where multiple choices make an empty
value genuinely ambiguous, but wrong here where there's nothing to be
ambiguous with.
Testing
cargo test -p uu_cut/ fulltests/by-util/test_cut.rssuite: 83 passed, 0 failed.--whitespace-delimitedvalue (valid, abbreviated, empty, invalid) against GNU cut 9.11 underLC_ALL=C, including the trimming behavior (not just the error path) for the empty-value case.cargo clippy -p uu_cut --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.