Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

dsherret
Copy link
Owner

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

@dsherret dsherret merged commit 3fefbdc into main Jan 26, 2024
4 checks passed
@dsherret dsherret deleted the feat_pipe_method branch January 26, 2024 18:20
@sigmaSd sigmaSd mentioned this pull request Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How about adding pipe function to command
1 participant