Repository navigation
grep: accept unambiguous abbreviations of long options - #239
Conversation
| .get_arguments() | ||
| .filter(|arg| names(arg).any(|n| n.starts_with(name))); | ||
| let arg = match (exact, prefixed.next(), prefixed.next()) { | ||
| (Some(arg), _, _) | (None, Some(arg), None) => arg, |
There was a problem hiding this comment.
That seems a little convoluted to me...
And in what way does this get_arguments() logic produce values that are different from LONG_OPTS_WITH_VALUE?
There was a problem hiding this comment.
Because LONG_OPTS_WITH_VALUE only held full, exact option names (e.g. regexp). When an unambiguous abbreviation like --reg -7 is passed, infer_long_args(true) in clap matches it to regexp, but the shorthand pre-pass did not recognize --reg in LONG_OPTS_WITH_VALUE and erroneously expanded -7 to -C 7. Reading from Command lets the pre-pass match the exact prefix resolution that clap will perform.
There was a problem hiding this comment.
??? Are you saying it was impossible to implement a prefix test? :D
There was a problem hiding this comment.
Not impossible, I overcomplicated it. Done in #259.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #239 +/- ##
==========================================
+ Coverage 97.12% 97.15% +0.02%
==========================================
Files 6 6
Lines 2227 2249 +22
Branches 241 243 +2
==========================================
+ Hits 2163 2185 +22
Misses 64 64
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performanceWarning uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed. 1 warning
Comparing Footnotes
|
| } | ||
|
|
||
| // Only built when a long option shows up. | ||
| let cmd = std::cell::LazyCell::new(uu_app); |
There was a problem hiding this comment.
uu_app() is now built twice, here and in uumain
could we build it once in uumain and pass it to expand_num_shorthand?
There was a problem hiding this comment.
Good catch, updated! uu_app() is now built once in uumain and passed as &app to expand_num_shorthand.
49087e4 to
a9b4881
Compare
|
Thanks for your PR |
GNU grep accepts any unambiguous prefix of a long option (
--coufor--count,--reg=x,--max 1); an ambiguous one such as--cois a usage error. We only accepted the full names.uu_app()now sets clap'sinfer_long_args. The-NUMpre-pass also has to know when an abbreviated option takes the next argument as its value, otherwise--reg -7would turn-7into-C 7. Instead of keeping a second hand-written list of value options, it now asks theCommandfor the option, using the same rule as clap: an exact name wins, otherwise the prefix must pick a single option. This keeps--binary -1as the--binaryflag followed by-1.The new test fails on main and checks the cases from the issue plus
--binary-f,--colo=and the exact-name case against GNU grep 3.11.Closes #156