rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[ts-command-line] Support stdin/piping

Open douglasg14b opened this issue 9 months ago • 4 comments

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

douglasg14b avatar Feb 25 '25 19:02 douglasg14b

Seems like a useful feature. How would you expect that to look from an API perspective?

iclanton avatar Feb 26 '25 17:02 iclanton

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.

dmichon-msft avatar Feb 28 '25 22:02 dmichon-msft

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?

dmichon-msft avatar Mar 18 '25 23:03 dmichon-msft

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.

douglasg14b avatar Mar 19 '25 01:03 douglasg14b