[feature request] Support xargs -I <replace_str>
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
- Briefly mentioned on the original xargs issue
- https://github.com/denoland/deno_task_shell/issues/78
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.
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.
@niedzielski thanks! I'll keep it open for now as a "suggestion" to see what other use cases come up.