Skip to content

xargs: only take an attached value for -l - #1020

Open
Xnadir wants to merge 1 commit into
uutils:mainfrom
Xnadir:fix/xargs-l-optional-attached
Open

Xnadir wants to merge 1 commit into
uutils:mainfrom
Xnadir:fix/xargs-l-optional-attached

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 17, 2026 •

Copy link
Copy Markdown

-l takes an optional value that GNU xargs only reads when it is attached, so the next argument is the command:

$ printf 'a b\nc\n' | xargs -l echo        # GNU: a b / c
Error: invalid value 'echo' for '-l [<max-lines>]'

Since this PR was opened, #993 added a rewrite that turns -eVALUE into -e=VALUE for clap's require_equals. It reads clusters of short options from the clap Command and stops at the command. So I rebuilt this PR on it: -l gets require_equals, and the rewrite treats -l like -e. That drops this PR's own option lists, handles clusters such as -tl2 and -rl2, and leaves -i to #1026, which extends the same rewrite to every require_equals option.

Tests:

  • xargs_max_lines_l_takes_only_an_attached_value: -l echo, -l2 echo, -l -r echo and the cluster -rl2 echo, checked against GNU xargs 4.11. It fails on main.
  • attach_eof_short_equals_rewrites_attached_max_lines: the rewrite of -l2, -tl2, -0l2 and -lt, and no rewrite for -l echo, a value of -n, or the command's own -l2.

cargo test --test test_xargs passes (53 tests) on Windows.

AI disclosure: written with help from Claude Code.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 15:46

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.32%. Comparing base (8d4d7b7) to head (7645e12).

Files with missing lines Patch % Lines
src/xargs/mod.rs 92.30% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1020      +/-   ##
==========================================
- Coverage   93.32%   93.32%   -0.01%     
==========================================
  Files          37       37              
  Lines        8423     8462      +39     
  Branches      424      429       +5     
==========================================
+ Hits         7861     7897      +36     
  Misses        422      422              
- Partials      140      143       +3     

☔ 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 17, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 15 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

✅ 20 untouched benchmarks


Comparing Xnadir:fix/xargs-l-optional-attached (3909709) with main (7a9df76)

Open in CodSpeed

@github-actions

Copy link
Copy Markdown

Commit 7645e12 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 455 / FAILED: 39 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 452 / FAILED: 42 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +3
  FAILED: -3

Test improvements (3):
  + iARG
  + iquotes
  + savannah-11865

Comment thread src/xargs/mod.rs Outdated
}
continue;
}
let rewritten = ["-l", "-i"].iter().find_map(|&opt| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about clustered flags like -tl2 or -0iX?
with require_equals on -l, -tl2 is now read as -t -l -2, while it works on main.
please handle them and add a test

Comment thread src/xargs/mod.rs Outdated
/// attached: `-l2`, `-iX`. clap would either take the next argument as that
/// value (`xargs -l echo`) or read the attached one as more short options
/// (`-iX` as `-i -X`), so spell the attached form with `=` before parsing.
fn attach_optional_values(args: &[&str]) -> Vec<String> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-e has the same problem (xargs -e echo takes echo as the eof string), could it go through the same path?

Comment thread src/xargs/mod.rs Outdated
"--max-args",
"--max-procs",
"--max-chars",
"--process-slot-var",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--process-slot-var isn't an option we have, is it?

Comment thread src/xargs/mod.rs Outdated
}

/// Short options of xargs that take their value as the next argument.
const SHORT_OPTIONS_WITH_VALUE: &[&str] = &["-a", "-d", "-E", "-I", "-L", "-n", "-P", "-s"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these lists duplicate the clap definitions and will get out of sync.
could they be derived from the Command instead?

Comment thread src/xargs/mod.rs Outdated

#[test]
fn optional_values_are_attached_with_equals() {
let to_vec = |args: &[&str]| attach_optional_values(args);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need this closure? :)

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the PR!
Adding require_equals to -l breaks clustered flags that work on main, like -tl2 (see inline).
Please also add tests that cover the long option and the missing-value branches (codecov).

@Xnadir
Xnadir force-pushed the fix/xargs-l-optional-attached branch from 7645e12 to 3909709 Compare November 26, 2026 01:45
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:45
Like GNU getopt, -l takes an optional value only when it is attached
(-l2), so in `xargs -l echo` echo is the command. Mark -l require_equals
and let the existing rewrite, which reads clusters such as -rl2 from the
clap Command, turn -lVALUE into -l=VALUE as it does for -e.
@Xnadir Xnadir changed the title xargs: only take an attached value for -l and -i xargs: only take an attached value for -l Nov 26, 2026

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

Commit 3909709 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 508 / PASSED: 472 / FAILED: 32 / SKIPPED: 4
  Reference: TOTAL: 508 / PASSED: 471 / FAILED: 33 / SKIPPED: 4

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + tests/find/readdir_race

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