dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
964 stars 33 forks source link

feat: add `.pipe(...)` for piping stdout of a command to another command #218

Closed dsherret closed 5 months ago

dsherret commented 5 months ago

Adds a new .pipe(...) method for piping one command to another. The critical part of this is that .pipe(...) returns the provided command and not the original command. This allows for chaining multiple commands together like so:

const result = const lineCount = await $`echo 1 && echo 2`
  .pipe($`wc -l`)
  .text(); // text of the result of wc -l

I was initially thinking this should be:

await $`echo 1`
  .stdout($`deno eval 'await Deno.stdin.readable.pipeTo(Deno.stderr.writable);'`);

...however, it gets confusing about what command someone is acting on when both .stdout and stderr are set and it becomes ambiguous about what the return value of those methods are.

Closes #137