denoland / denoland/deno_task_shell

[feature request] Support xargs -I <replace_str>

Open
#77 4 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
139
Forks
25
PR merge metrics
No merged PRs in 30d

Description

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](https://man7.org/linux/man-pages/man1/xargs.1p.html#OPTIONS) to be added.

Eg:

```sh
$ 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:

```sh
$ 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:

```sh
$ 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:

```jsonc
{
"tasks": {
"hello": "echo -e 'a\nb\nc'|xargs cp -t dist"
}
}
```

```sh
$ 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/issues/2257#issuecomment-488217638)
- https://github.com/denoland/deno_task_shell/issues/78

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.