Skip to content

Commit add88b8

Browse files
Adding pipe mode to generate_manual.sh, README.md. Add test_pipe_mode_wc_blocksize_100kib.
1 parent e08a9a3 commit add88b8

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Listed in [Awesome Rust - utilities](https://github.com/rust-unofficial/awesome-
1919
Similar interface to [GNU Parallel](https://www.gnu.org/software/parallel/parallel_examples.html) or [xargs](https://man7.org/linux/man-pages/man1/xargs.1.html) plus useful features:
2020
* More than 10x faster than GNU Parallel [in benchmarks](https://github.com/aaronriekenberg/rust-parallel/wiki/Benchmarks)
2121
* Run commands from [stdin](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#commands-from-stdin), [input files](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#reading-multiple-inputs), or [`:::` arguments](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#commands-from-arguments)
22+
* [Pipe mode](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#pipe-mode) to read blocks from stdin and pass to parallel commands automatically.
2223
* Automatic parallelism to all cpus, or [configure manually](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#parallelism)
2324
* Transform inputs with [variables](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#automatic-variables) or [regular expressions](https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#regular-expression)
2425
* Prevent [output interleaving](https://github.com/aaronriekenberg/rust-parallel/wiki/Output-Interleaving) and maintain input order with `-k`/`--keep-order`

scripts/generate_manual.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ echo '
1515
1. [Commands from stdin](#commands-from-stdin)
1616
1. [Command and initial arguments on command line](#command-and-initial-arguments-on-command-line)
1717
1. [Reading multiple inputs](#reading-multiple-inputs)
18+
1. [Pipe Mode](#pipe-mode)
1819
1. [Parallelism](#parallelism)
1920
1. [Keep Output Order](#keep-output-order)
2021
1. [Dry run](#dry-run)
@@ -142,6 +143,30 @@ rm -f test
142143

143144
echo '```'
144145

146+
echo '## Pipe Mode
147+
148+
The `--pipe` option can be used to enable pipe mode.
149+
150+
In pipe mode input from stdin is split into blocks and each block is passed to a separate instance of the command via stdin. Command instances are run in parallel.
151+
152+
The default block size is 1 MiB, which can be changed with the `--block-size` option.
153+
154+
Here we use `--pipe` to run `wc -l`
155+
'
156+
157+
echo '```'
158+
echo '$ cat /usr/share/dict/words | rust-parallel --pipe wc -l'
159+
cat /usr/share/dict/words | $RUST_PARALLEL --pipe wc -l
160+
echo '```'
161+
162+
echo 'Here we use pipe mode with with a smaller block size of 500 KiB:'
163+
164+
echo '```'
165+
echo '$ cat /usr/share/dict/words | rust-parallel --pipe --block-size=500KiB wc -l'
166+
cat /usr/share/dict/words | $RUST_PARALLEL --pipe --block-size=500KiB wc -l
167+
echo '```'
168+
169+
145170
echo '
146171
## Parallelism
147172

tests/integration_tests.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,26 @@ E"#;
671671
}
672672

673673
#[test]
674-
fn test_pipe_mode_wc_blocksize1() {
674+
fn test_pipe_mode_wc_blocksize_100kib() {
675+
let stdin = r#"A
676+
B
677+
C
678+
D
679+
E"#;
680+
rust_parallel()
681+
.write_stdin(stdin)
682+
.arg("--pipe")
683+
.arg("--block-size=100KiB")
684+
.arg("wc")
685+
.arg("-l")
686+
.assert()
687+
.success()
688+
.stdout(predicate::str::contains("5\n").count(1))
689+
.stderr(predicate::str::is_empty());
690+
}
691+
692+
#[test]
693+
fn test_pipe_mode_wc_blocksize_1() {
675694
let stdin = r#"A
676695
B
677696
C

0 commit comments

Comments
 (0)