Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Support xargs -I <replace_str> #77

Open
niedzielski opened this issue Mar 11, 2023 · 4 comments
Open

[feature request] Support xargs -I <replace_str> #77

niedzielski opened this issue Mar 11, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@niedzielski
Copy link

niedzielski commented Mar 11, 2023

The xargs command is super useful but is too constrained to use for invocations that depend on positional parameters. This feature request asks for the traditional -I/-i/--replace flags to be added.

Eg:

$ echo -e 'a\nb\nc'|xargs -I arg echo 1 arg 2
1 a 2
1 b 2
1 c 2

Unfortunately, -I always constrains the maximum number of lines processed at a time to 1 and approximates the following loop:

$ for i in a b c; do echo 1 $i 2; done
1 a 2
1 b 2
1 c 2

Although both looping and xargs -I provide similar functionality, I think they serve different uses. Simple loops are wanted for simple lists and xargs is wanted for pipes.

Use case

In the absence of this support, task users are at the mercy of the subcommands they call. For example, here's how you would have to do copy with the current version of xargs:

$ echo -e 'a\nb\nc'|xargs cp -t dist

However, many tools don't support non-positional arguments like the target parameter so this isn't an option. Even Deno's own cp command doesn't support -t so this also fails:

{
  "tasks": {
    "hello": "echo -e 'a\nb\nc'|xargs cp -t dist"
  }
}
$ deno task hello
Task hello echo -e 'a
b
c'|xargs cp -t dist
cp: unsupported flag: -t

References

@dsherret
Copy link
Member

It would be good to split these out into two issues. Looping probably won't be implemented because if you are doing loops then you probably shouldn't be writing that in a task and instead use JavaScript for that (deno run ...), but having feature parity with xargs is desirable.

@niedzielski niedzielski changed the title [feature request] Support looping and xargs -I <replace_str> [feature request] Support xargs -I <replace_str> Mar 11, 2023
@niedzielski
Copy link
Author

Thanks, I've made the split. Feel free to close the loop issue if it doesn't make sense--I opened it because I thought it was likely to come up again and it'd be nice to centralize that discussion.

@dsherret dsherret added the enhancement New feature or request label Mar 11, 2023
@dsherret
Copy link
Member

@niedzielski thanks! I'll keep it open for now as a "suggestion" to see what other use cases come up.

@j-murata
Copy link

j-murata commented Aug 28, 2024

Excuse me for interrupting.

I posted denoland/deno#25248 in the Discussions of the deno repository (as I was unaware of the existence of this deno_task_shell repository), but if this xargs -I feature request is implemented in the future, could it be a solution to my problem?

» How do I insert the deno task argument into the middle of that command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants