#!/bin/bash set -e export NO_COLOR=1 RUST_PARALLEL="./target/debug/rust-parallel" VERSION=$($RUST_PARALLEL -V | cut -f2 -d' ') echo "## Manual for rust-parallel $VERSION" echo ' 1. [Command line](#command-line) 1. [Commands from arguments](#commands-from-arguments) 1. [Commands from stdin](#commands-from-stdin) 1. [Command and initial arguments on command line](#command-and-initial-arguments-on-command-line) 1. [Reading multiple inputs](#reading-multiple-inputs) 1. [Parallelism](#parallelism) 1. [Dry run](#dry-run) 1. [Debug logging](#debug-logging) 1. [Error handling](#error-handling) 1. [Timeout](#timeout) 1. [Path cache](#path-cache) 1. [Progress bar](#progress-bar) 1. [Regular Expression](#regular-expression) 1. [Named Capture Groups](#named-capture-groups) 1. [Numbered Capture Groups](#numbered-capture-groups) 1. [Capture Group Special Characters](#capture-group-special-characters) 1. [Shell Commands](#shell-commands) 1. [Bash Function](#bash-function) 1. [Function Setup](#function-setup) 1. [Demo of command line arguments](#demo-of-command-line-arguments) 1. [Demo of function and command line arguments from stdin](#demo-of-function-and-command-line-arguments-from-stdin) 1. [Demo of function and initial arguments on command line, additional arguments from stdin](#demo-of-function-and-initial-arguments-on-command-line-additional-arguments-from-stdin) ' echo '## Command line' echo '``` $ rust-parallel --help' $RUST_PARALLEL --help echo '```' echo '## Commands from arguments The `:::` separator can be used to run the [Cartesian Product](https://en.wikipedia.org/wiki/Cartesian_product) of command line arguments. This is similar to the `:::` behavior in GNU Parallel. ' echo '``` $ rust-parallel echo ::: A B ::: C D ::: E F G' $RUST_PARALLEL echo ::: A B ::: C D ::: E F G echo ' $ rust-parallel echo hello ::: larry curly moe' $RUST_PARALLEL echo hello ::: larry curly moe echo ' # run gzip -k on all *.html files in current directory $ rust-parallel gzip -k ::: *.html ```' echo '## Commands from stdin Run complete commands from stdin. ' echo '``` $ cat >./test <./test<./test <./test <&1 RET_VAL=$? set -e echo ' $ echo $?' echo $RET_VAL echo '```' echo 'The `--exit-on-error` option can be used to exit after one command fails. rust-parallel waits for in-progress commands to finish before exiting and then exits with status 1.' echo '``` $ head -100 /usr/share/dict/words | rust-parallel --exit-on-error cat' set +e head -100 /usr/share/dict/words | $RUST_PARALLEL --exit-on-error cat 2>&1 RET_VAL=$? set -e echo ' $ echo $?' echo $RET_VAL echo '```' echo ' ## Timeout The `-t`/`--timeout-seconds` option can be used to specify a command timeout in seconds. If any command times out this is considered a command failure (see [error handling](#error-handling)). ' echo '```' echo '$ rust-parallel -t 0.5 sleep ::: 0 3 5' set +e $RUST_PARALLEL -t 0.5 sleep ::: 0 3 5 RET_VAL=$? set -e echo ' $ echo $?' echo $RET_VAL echo '```' echo ' ## Path Cache By default as commands are run the full paths are resolved using [which](https://github.com/harryfei/which-rs). Resolved paths are stored in a cache to prevent duplicate resolutions. This is generally [good for performance](https://github.com/aaronriekenberg/rust-parallel/wiki/Benchmarks). The path cache can be disabled using the `--disable-path-cache` option. ' echo '## Progress bar The `-p`/`--progress-bar` option can be used to enable a graphical progress bar. This is best used for commands which are running for at least a few seconds, and which do not produce output to stdout or stderr. In the below commands `-d all` is used to discard all output from commands run. Progress styles can be chosen with the `PROGRESS_STYLE` environment variable. If `PROGRESS_STYLE` is not set it defaults to `light_bg`. The following progress styles are available: * `PROGRESS_STYLE=light_bg` good for light terminal background with colors, spinner, and steady tick enabled: ![light_bg](https://github.com/aaronriekenberg/rust-parallel/blob/main/screenshots/light_background_progress_bar.png) * `PROGRESS_STYLE=dark_bg` good for dark terminal background with colors, spinner, and steady tick enabled: ![dark_bg](https://github.com/aaronriekenberg/rust-parallel/blob/main/screenshots/dark_background_progress_bar.png) * `PROGRESS_STYLE=simple` good for simple or non-ansi terminals/jobs with colors, spinner, and steady tick disabled: ![simple](https://github.com/aaronriekenberg/rust-parallel/blob/main/screenshots/simple_progress_bar.png) ## Regular Expression Regular expressions can be specified by the `-r` or `--regex` command line argument. [Named or numbered capture groups](https://docs.rs/regex/latest/regex/#grouping-and-flags) are expanded with data values from the current input before the command is executed. ### Named Capture Groups In these examples using command line arguments `{url}` and `{filename}` are named capture groups. `{0}` is a numbered capture group. ' echo '```' echo -e '$ rust-parallel -r \x27(?P.*),(?P.*)\x27 echo got url={url} filename={filename} ::: URL1,filename1 URL2,filename2' $RUST_PARALLEL -r '(?P.*),(?P.*)' echo got url={url} filename={filename} ::: URL1,filename1 URL2,filename2 echo echo -e '$ rust-parallel -r \x27(?P.*) (?P.*)\x27 echo got url={url} filename={filename} full input={0} ::: URL1 URL2 ::: filename1 filename2' $RUST_PARALLEL -r '(?P.*) (?P.*)' echo got url={url} filename={filename} full input={0} ::: URL1 URL2 ::: filename1 filename2 echo '```' echo '### Numbered Capture Groups In the next example input file arguments `{0}` `{1}` `{2}` `{3}` are numbered capture groups, and the input is a csv file:' echo '```' echo '$ cat >./test <./test <./test <./test <.*) (?P.*)\x27 \x27FOO={arg1}; BAR={arg2}; echo "FOO = ${FOO}, BAR = ${BAR}, shell pid = $$, date = $(date)"\x27 ::: A B ::: CAT DOG' $RUST_PARALLEL -s -r '(?P.*) (?P.*)' 'FOO={arg1}; BAR={arg2}; echo "FOO = ${FOO}, BAR = ${BAR}, shell pid = $$, date = $(date)"' ::: A B ::: CAT DOG echo '```' echo '## Bash Function `-s` shell mode can be used to invoke an arbitrary bash function. Similar to normal commands bash functions can be called using stdin, input files, or from command line arguments.' echo '### Function Setup Define a bash fuction `logargs` that logs all arguments and make visible with `export -f`: ' echo '```' echo '$ logargs() { echo "logargs got $@" }' logargs() { echo "logargs got $@" } echo ' $ export -f logargs' export -f logargs echo '```' echo '### Demo of command line arguments: ' echo '``` $ rust-parallel -s logargs ::: A B C ::: D E F' $RUST_PARALLEL -s logargs ::: A B C ::: D E F echo '```' echo '### Demo of function and command line arguments from stdin:' echo '``` $ cat >./test <./test <./test <./test <