Skip to content

Accept -iARG without an equals sign in xargs - #1077

Open
Wooohaaa wants to merge 1 commit into
uutils:mainfrom
Wooohaaa:fix/xargs-i-without-equals
Open

Wooohaaa wants to merge 1 commit into
uutils:mainfrom
Wooohaaa:fix/xargs-i-without-equals

Conversation

@Wooohaaa

Copy link
Copy Markdown

Fixes #594. GNU accepts -iARG as a short form of -I ARG, but clap's optional value for -i required -i=ARG and rejected the attached form. Normalizes -iARG to -i=ARG before parsing, leaving a bare -i unchanged. Regression test covers attached, equals and bare forms.

GNU accepts `-iARG` as a short form of `-I ARG`, but clap's optional value
for `-i` required `-i=ARG` and rejected the attached form. Normalize `-iARG`
to `-i=ARG` before parsing, leaving a bare `-i` unchanged. Adds a regression
test covering attached, equals and bare forms.

Fixes uutils#594
Comment thread src/xargs/mod.rs
// parsing while leaving a bare `-i` unchanged.
let normalized: Vec<String> = args
.iter()
.map(|arg| {

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.

this also rewrites the command's arguments: xargs grep -ifoo will run grep -i=foo
please stop at the first non-option argument (and at --)

Comment thread src/xargs/mod.rs
let normalized: Vec<String> = args
.iter()
.map(|arg| {
if arg.starts_with("-i") && arg.len() > 2 && !arg.starts_with("-i=") {

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.

could use strip_prefix("-i"), no? clippy will probably complain about the slicing

Comment thread tests/test_xargs.rs
.args(&["-i", "echo", "{}"])
.pipe_in("123\n")
.succeeds()
.stdout_only("123\n");

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.

please add a test where the command itself gets a -iXXX argument, e.g. xargs echo -ifoo

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.

xargs: support -i option without an equals sign before the argument

2 participants