truncate, paste, uniq: let a repeated option override the earlier one - #14258
Open
arbelonson-source wants to merge 1 commit into
Open
truncate, paste, uniq: let a repeated option override the earlier one#14258arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
GNU reads options left to right, so giving one twice keeps the last:
$ truncate -s 1 -s 2 f # GNU truncates to 2
error: the argument '--size <SIZE>' cannot be used multiple times
$ paste -d, -d: f1 f2 # GNU joins with ':'
error: the argument '--delimiters <LIST>' cannot be used multiple times
$ uniq -f 1 -f 2 f # GNU skips 2 fields
error: the argument '--skip-fields <N>' cannot be used multiple times
Set args_override_self, the same way cut already does.
This is not universal: `cut -f1 -f2` and `join -1 1 -1 2` are errors in
GNU too, just different ones, so those are left alone.
|
Binary size comparison: |
|
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.
GNU reads options left to right, so giving the same one twice keeps the last value. These three rejected the repeat outright.
truncate -s 1 -s 2 ferror: the argument '--size <SIZE>' cannot be used multiple timespaste -d, -d: f1 f2:error: the argument '--delimiters <LIST>' cannot be used multiple timesuniq -f 1 -f 2 ferror: the argument '--skip-fields <N>' cannot be used multiple timesFixed with
args_override_self(true), the same waycutalready does it. Foruniqthis covers-sand-was well, both checked against GNU.Found by differential testing against GNU coreutils 9.11.
This is deliberately not applied everywhere.
cut -f1 -f2andjoin -1 1 -1 2are errors in GNU too — just different ones ("only one list may be specified", "incompatible join fields 0, 1") — so those are left alone rather than swept up.cutin particular already documents in a comment why it usesArgAction::Appendto count occurrences.Testing
One regression test per utility. Verified they catch the bug by reverting the three source files alone — all three fail, then pass with them restored.
cargo test --features "truncate,paste,uniq" --no-default-features: 99 passed, 0 failed (96 pre-existing, 3 new)cargo fmt --checkandcargo clippy -p uu_truncate -p uu_paste -p uu_uniq --all-targets: cleantruncate -s 3,paste -d,,uniq -f 1, bareuniq) as regression cover: all 9 match GNUDisclosure
Prepared with AI assistance (Claude Code), per the AI policy in CONTRIBUTING.md. On the GPL point raised there: expected behavior was established by running the installed GNU binaries as a black box and recording their output. I did not read GNU coreutils source. All testing above was run locally.