rushstack
rushstack copied to clipboard
[ts-command-line] Support stdin/piping
Summary
Command line should support stdin to support piping from other CLIs
Repro steps
Crate a CLI, and try and pipe data into it like eco something | tsx ./myCli.ts myCommand
Details
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
| Package name: | @rushstack/ts-command-line |
| Package version? | 4.23.2 |
| Operating system? | Linux |
| Would you consider contributing a PR? | Yes |
Node.js version (node -v)? |
v22 |
Seems like a useful feature. How would you expect that to look from an API perspective?
Ultimately the role of ts-command-line is to be an argument parser, so accepting input from stdin isn't really in scope. Individual actions are free to read from stdin as part of their implementation, but that doesn't require any logic on the part of ts-command-line to make happen.
For example, for the UNIX convention, an argument that asks for a filename might be coded to accept - as a valid value, at which point the underlying action implementation that reads that file should interpret - as a directive to read from stdin instead of a particular file on disk, but from the perspective of ts-command-line, its work ended when it handed you the value - from the parameter.
I assumed you meant as one of the file inputs (as is the standard UNIX convention), did you mean that you want to support piping in the command line arguments?
No, I think I meant the former. Having a built-in way to nab stdin as a built in would be handy, but I see what you mean.