Repository navigation
grep: format unknown option errors to match GNU grep - #226
yunusarda-sudo wants to merge 1 commit into
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #226 +/- ##
==========================================
- Coverage 97.22% 96.90% -0.32%
==========================================
Files 6 6
Lines 2270 2295 +25
Branches 245 250 +5
==========================================
+ Hits 2207 2224 +17
- Misses 63 71 +8
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:
|
6548b28 to
7292357
Compare
7292357 to
5e0782f
Compare
|
The motivation comes from issue #214 opened by @sylvestre: the GNU grep test suite script Additionally, clap was printing the unresolved placeholder |
Fixes #214
Problem
For an unknown option, GNU grep prints one line prefixed with the program name (
grep: unrecognized option '--frobnicate'orgrep: invalid option -- 'j'), followed by:with exit status 2.
Previously,
uu_greprouted unknown arguments tohandle_clap_result_with_exit_code, which output clap's multi-line block starting witherror: unexpected argument ... found, atip:, and the unresolved placeholderUsage: grep-usage. This breaks tests like GNU grep'sfilename-lineno.plthat parse the program prefix from stderr.Solution
clap::error::ErrorKind::UnknownArgumentin argument parsing, extractingContextKind::InvalidArgto detect whether the option was short (-<opt>) or long (--<opt>).unrecognized option '--<opt>'orinvalid option -- '<opt>'followed by the standard usage and help pointers.unknown_option_diagnosticintests/test_grep.rs.