Skip to content

fix: accept repeated options like GNU grep - #2

Merged
lhecker merged 1 commit into
mainfrom
fix-repeated-options
May 29, 2026
Merged

lhecker merged 1 commit into
mainfrom
fix-repeated-options

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

GNU grep tolerates options given more than once (boolean flags are idempotent, value options take the last occurrence), but clap rejected them with "cannot be used multiple times" (exit 2). Set args_override_self(true) so clap replaces rather than errors; args with ArgAction::Append (-e/-f/--include/--exclude) still accumulate.

Found by the differential fuzzer (e.g. grep -e .* -E -n -o -n -x).

Add a regression test covering repeated booleans, repeated value options (last wins), and that -e still accumulates patterns.

@codecov

codecov Bot commented May 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.96%. Comparing base (f781350) to head (c2cac0a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #2   +/-   ##
=======================================
  Coverage   94.95%   94.96%           
=======================================
  Files           6        6           
  Lines        1408     1409    +1     
  Branches      140      140           
=======================================
+ Hits         1337     1338    +1     
  Misses         69       69           
  Partials        2        2           
Flag Coverage Δ
macOS_latest 95.77% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 95.77% <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 Sentry.
📢 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.

@sylvestre
sylvestre marked this pull request as ready for review May 28, 2026 21:47
@sylvestre
sylvestre requested review from Copilot and lhecker May 28, 2026 21:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Enables GNU grep-compatible handling of repeated CLI options by configuring clap to override (rather than error) on repeated flags, while preserving accumulation semantics for ArgAction::Append args. Adds a regression test covering booleans, value options, and append options.

Changes:

  • Add .args_override_self(true) to the top-level uu_app() clap Command.
  • Add repeated_options_are_accepted regression test covering -n -n, -i -i, -m 5 -m 1, and -e a -e b.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/lib.rs Enables clap's args_override_self so repeated options replace instead of error.
tests/test_grep.rs Adds regression test verifying repeated booleans, last-wins value option, and -e accumulation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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.

Ah nice catch!

@sylvestre
sylvestre force-pushed the fix-repeated-options branch from 3d78ca7 to 8793b49 Compare May 29, 2026 19:21
@sylvestre

Copy link
Copy Markdown
Contributor Author

fuzzers rock!

GNU grep tolerates options given more than once (boolean flags are
idempotent, value options take the last occurrence), but clap rejected
them with "cannot be used multiple times" (exit 2). Set
args_override_self(true) so clap replaces rather than errors; args with
ArgAction::Append (-e/-f/--include/--exclude) still accumulate.

Found by the differential fuzzer (e.g. `grep -e .* -E -n -o -n -x`).

Add a regression test covering repeated booleans, repeated value options
(last wins), and that -e still accumulates patterns.
@sylvestre
sylvestre force-pushed the fix-repeated-options branch from 8793b49 to c2cac0a Compare May 29, 2026 19:44
@lhecker
lhecker merged commit c50c045 into main May 29, 2026
16 checks passed
@lhecker
lhecker deleted the fix-repeated-options branch May 29, 2026 20:22
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.

3 participants