stdrun
Create a CLI with a single function
Usage
A basic program using stdrun
looks like this:
// example.jsvar run text = { return text` Arguments: `}
Which you can then run in your terminal:
$ node example.js --yes some stuff --target="./path/to/somewhere"
Arguments: --yes, some, stuff, --target=./path/to/somewhere
Streams
You can do more than just text though. If your function returns a node stream, its output is gradually rendered to the terminal.
var fs = var run = { return fs}
stdin
You can also read the stdin
stream. The cleanest way to do so is using asynchronous iteration.
var run = { for { chunk }}
Errors
Commands can output two kinds of errors. Critical errors that terminate the program should use throw
. Other non-critical errors are yielded as normal values from an iterator. Both types of errors are sent to stderr
.
var run text = { if mode === 'panic' throw 'Panic!' 'Something went wrong.' }
Subcommands
Subcommands are supported too:
// commands.jsvar main sub text =
Which you can execute like so:
$ node commands.js hello
world
$ node commands.js nested
ping
$ node commands.js nested deeper
pong
$ node commands.js
everything else
License
Apache-2.0