shuf: report a bad -i range the way GNU does - #14402
Open
Socialpranker wants to merge 1 commit into
Open
Conversation
A LO-HI that would not parse was rejected by clap, which names the option
and the reason it could not use the value:
$ shuf -i 5-1
error: invalid value '5-1' for '--input-range <LO-HI>': start exceeds end # was
shuf: invalid input range: '5-1' # GNU, and now
GNU names the range as a whole whatever is wrong with it, and adds a
detail only when a bound does not fit: an overflowing bound gets
': Value too large to be stored in data type'.
parse_range moved out of the clap value parser and into uumain, returning
a UResult.
|
GNU testsuite comparison: |
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.
A
LO-HIthat would not parse was rejected by clap's value parser, whichnames the option and the internal reason:
GNU names the range as a whole whatever is wrong with it — a missing
-,a non-numeric bound, an extra
-,LOaboveHI— and adds a detail inexactly one case, a bound that does not fit.
The fix
parse_rangemoves out of.value_parser()and intouumain, returninga
UResultwithUSimpleError::new(1, ...).IntErrorKind::PosOverflowselects the "Value too large" wording; everything else gets the plain one.
The two message keys replace
shuf-error-start-exceeds-endandshuf-error-missing-dash, which had no other user.Five existing assertions pinned the clap wording; they are updated.
How the GNU behavior was established
By running the installed GNU coreutils 9.11 binary (Homebrew,
gshuf) asa black box over eight
-ivalues —5-1,abc,1-,1-2-3,-3,the empty string, an overflowing bound, and the valid
3-3— diffingstderr and exit status against uutils. Seven of the eight now match. I did
not read GNU coreutils source.
Testing
test_shuf_invalid_input_range_messageintests/by-util/test_shuf.rs: five malformed ranges with the exactstderr and exit status 1, plus the overflow case. Mutation-checked:
reverting
shuf.rsand the.ftlmakes six tests fail.cargo test --features shuf --test tests test_shuf: 75 passed, 0 failed.cargo clippy -p uu_shuf --all-targets -- -D warnings: clean.cargo fmt --check: clean.shufinvocations in my harness: mismatches 1 -> 0.
Not in scope
shuf -i -3still stops at clap withunexpected argument '-3' foundwhere GNU takes
-3as the value of-i. That is about hyphen handlingin the parser, not about the message, and is left alone.
Disclosure
Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. Every GNU behavior quoted above came from
running the installed binary, not from reading GPL source. All testing was
run locally.