Rargs: a possible xargs replacement that brings regex support


#1

I’d like to announce the first release of rargs, an alternative to xargs and parallel that brings pattern matching support.

When we use xargs to handle some input in batch, we often want to capture parts of the input and use them to form new commands to execute. With rargs it is quite easy, for example:

  • Batch rename: echo script.sh.bak | rargs -p '(.*)\.bak' mv {0} {1} will execute mv script.sh.bak script.sh
  • parse csv files: echo 'a,b, c,d' | rargs -d ', *' echo {2..:-} results in b-c-d

Basically, rargs allows us to specify either regex pattern(via -p) or regex delimiter(via -d) to capture groups from the input. Later the groups can be referred to by the range syntax {start..end:separator}. For more usages, please check the README.

Questions and contributions are welcome! Feel free to reply here or add new issues on Github! Thanks!


#2

This seems handy.

Now, putting on my CLI-WG hat on::

  • Why does the project CI only build for Linux/Mac and not Windows?
  • What was your motivation for doing end-to-end tests in Python rather than something like assert_cli?
  • And in case you didn’t fill out the survey, what parts of the process either slowed you down, were rough, or you hesitated to do because of the work invloved?

#3

Why does the project CI only build for Linux/Mac and not Windows?

I copied the ci scripts from my another project. Turned out it use rust-everywhere instead of trust. I’ve updated it.

What was your motivation for doing end-to-end tests in Python rather than something like assert_cli?

Wow. I did not notice its existence! I’ve rewritten the tests with it, covered all my needs (except that assert_cmd! did not take raw strings(r"").

what parts of the process either slowed you down, were rough, or you hesitated to do because of the work invloved?

For me, it is argument parsing. I use structopt which is pretty cool to work with. It uses clap.rs under the hood which is powerful and feature-rich.

However rargs will need special treatment of the arguments, (e.g. in rargs echo -e 'hello', -e should belongs to echo not rargs). And it took me so long to dig out all the right feature of clap.rs.


#4

Thanks for the feedback.

This also shows we need to improve discoverability which I think we do have plans for.