Skip to content

grep: test long options against a prefix list - #259

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-long-opt-prefix-list
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-long-opt-prefix-list

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

Follow-up to #239, as lhecker suggested there: instead of walking Command::get_arguments(), keep LONG_OPTS_WITH_VALUE and test the (possibly abbreviated) name by prefix. --binary is special-cased since it is a flag and also a prefix of --binary-files. A unit test keeps the list in sync with uu_app(), and expand_num_shorthand no longer needs the Command.

…'s arguments

Follow-up to uutils#239 as suggested by lhecker: keep the list of long options
taking a value and match the (possibly abbreviated) name by prefix. A unit
test keeps the list in sync with uu_app(), and uu_app() is built once again.
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.22%. Comparing base (bf6f25e) to head (1c0125e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #259      +/-   ##
==========================================
- Coverage   97.22%   97.22%   -0.01%     
==========================================
  Files           6        6              
  Lines        2270     2267       -3     
  Branches      245      244       -1     
==========================================
- Hits         2207     2204       -3     
  Misses         63       63              
Flag Coverage Δ
macOS_latest 98.13% <100.00%> (-0.01%) ⬇️
ubuntu_latest 98.13% <100.00%> (-0.01%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-long-opt-prefix-list (1c0125e) with main (bf6f25e)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@lhecker lhecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread src/lib.rs
Comment on lines +1027 to 1035
/// the next argument. `name` may be any prefix of an option, as accepted by
/// `infer_long_args`. A prefix that is ambiguous is rejected by clap anyway.
fn long_option_takes_next_arg(name: &[u8]) -> bool {
// `--binary` is a flag of its own, though also a prefix of `--binary-files`.
name != b"binary"
&& LONG_OPTS_WITH_VALUE
.iter()
.any(|opt| opt.as_bytes().starts_with(name))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is correct. E.g. --e should not match exclude, because it is not unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants