Repository navigation
grep: print GNU's message for an unknown option - #221
VanshajPoonia wants to merge 1 commit into
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #221 +/- ##
==========================================
+ Coverage 97.22% 97.26% +0.03%
==========================================
Files 6 6
Lines 2270 2301 +31
Branches 245 248 +3
==========================================
+ Hits 2207 2238 +31
Misses 63 63
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:
|
|
thanks for looking into this! |
| } | ||
| let arg = err.get(clap::error::ContextKind::InvalidArg)?.to_string(); | ||
| let problem = if arg.starts_with("--") { | ||
| format!("unrecognized option '{arg}'") |
There was a problem hiding this comment.
what about --foo=bar? GNU prints unrecognized option '--foo=bar', i think clap only gives --foo here
could you please check and add it to the test?
There was a problem hiding this comment.
You were right, clap only gives --foo there. I now look up the full argument from argv, so --foo=bar prints unrecognized option '--foo=bar' like GNU. I added --no-such=1 to the test, and squashed everything into one commit.
d787ed1 to
640bb35
Compare
| let given = args | ||
| .iter() | ||
| .filter_map(|a| a.to_str()) | ||
| .find(|a| { |
There was a problem hiding this comment.
this takes the first --foo=… anywhere in argv, so grep --foo -e --foo=x would name --foo=x
ok for me if we accept it, just checking it is known :)
There was a problem hiding this comment.
- Thank you for pointing this out, and I fixed it instead of accepting it :D
- It now names the argument clap actually rejected.
- grep --foo -e --foo=x now says '--foo'.
- I put both of the cases you told in test.
17f1e24 to
2db97f9
Compare
An option grep doesn't know printed clap's "error: unexpected argument" block. Print GNU's three lines instead: "unrecognized option '--foo'" for a long option, with its value when it has one, and "invalid option -- 'j'" for a short one, then the usage and help lines. Exit with 2.
2db97f9 to
b4b7c45
Compare
|
@sylvestre filed #214 for this as a GNU compat bug. GNU's It does make grep's message differ from the clap-style one uucore prints for the other utils. If you'd rather fix this in uucore for every tool, I can move it there. |
An unknown option printed clap's error block with a
tip:and an unresolved usage line:Now it prints what GNU grep prints, still with exit 2:
A short option gives
invalid option -- 'j'and also inside a cluster like-wj.Other parse errors still go through uucore for now. I kept the change in grep as uucore's clap messages are shared with coreutils whose tests expect clap's wording.
New test
unknown_option_is_reported_like_gnu(fails on main).cargo test,cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.Closes #214