aaronriekenberg / rust-parallel

Fast command line app in rust/tokio to run commands in parallel. Similar interface to GNU parallel or xargs plus useful features. Listed in Awesome Rust utilities.
MIT License
146 stars 7 forks source link

Does this support one command and multi args like parallel #2

Closed majian4work closed 1 year ago

majian4work commented 1 year ago
rust-parallel cli ::: arg1 arg2 arg3 ...

does this expand to

cli arg1
cli arg2
cli arg3
...
aaronriekenberg commented 1 year ago

Hi @Ma-Jian1 -

So far rust-parallel does not support the ::: syntax you showed.

This is supported by GNU Parallel.

May I ask what is your use-case is for this? What cli application do you run with this?

There are 2 ways to do a similar thing now with rust-parallel - see more details below.

Thanks for your question!

Working solutions in rust-parallel v1.0.0:

  1. You could put the cli and arguments into a file and pass to rust-parallel via stdin:
$ cat >./input <<EOL
cli arg1
cli arg2
cli arg3
EOL

$ cat ./input | rust-parallel
  1. You could put just arguments in the file and put the cli command as a command line argument:
    
    $ cat >./input <<EOL
    arg1
    arg2
    arg3
    EOL

$ cat ./input | rust-parallel cli

majian4work commented 1 year ago

I want to install a bunch of rust cli tools, such as just, erdtree, starship, bottom etc cargo install --locked just, erdtree, starship ... seems don't run in parallel, so it's too slow. gun parallel will spawn a sub-process for every target which is fast. but maybe not safe (maybe locked) HERE Doc may be workable, but it's a little cumbersome.

aaronriekenberg commented 1 year ago

Will work on adding support for ::: option to spawn commands from command line arguments.

Seems like Itertools::multi_cartesian_product is a good fit for getting all combinations of command line arguments if there are multiple ::: options.

parallel echo ::: A B ::: C D E ::: F G

Thanks!

aaronriekenberg commented 1 year ago

Working on this in a branch: https://github.com/aaronriekenberg/rust-parallel/tree/input_channel

Things are beginning to work in this branch but not ready for release just yet. Getting close 😄

Compare this:

rust-parallel -c  echo ::: A B  ::: B C ::: D E F

With gnu parallel:

parallel echo ::: A B  ::: B C ::: D E F
aaronriekenberg commented 1 year ago

Version 1.1.0 released today has this change: https://github.com/aaronriekenberg/rust-parallel/releases/tag/v1.1.0

See these demos for examples: https://github.com/aaronriekenberg/rust-parallel#commands-from-arguments-mode https://github.com/aaronriekenberg/rust-parallel#commands-from-arguments-mode-bash-function

Thanks!