init
Initialize your CLI after defining its commands.
This function must be called after all commands have been configured. It will then search for and load your application's configuration file and initialize Yargs which will parse process.argv.
The parsed arguments and configuration are then passed to the appropriate command's handler
.
This function sets the following global parameters:
Calls
yargs.version()
with the version from your application'spackage.json
, ensuring that if the application is invoked with the--version
option, Yargs will print the correct version.Calls
yargs.wrap()
withyargs.terminalWidth()
to instruct Yargs to use the full width of the terminal before wrapping lines.Calls
yargs.help()
, ensuring that if the application is invoked with the--help
flag, Yargs will print usage instructions and exit early without calling ahandler
.
This function accepts an optional callback, SaffronInitCallback
that will be passed the global yargs
object which can be used to perform any additional global configuration of Yargs.
Handling Yargs Output Manually
This callback may optionally return a yargs.ParseCallback
that can can be used to intercept output from Yargs, manipulate it, and write it to an output stream explicitly.
Example:
Last updated