Skip to main content

Cli

new Cli​

ts
new Cli(opts: {...})
ts
new Cli(opts: {...})
OptiontypeDescription
binaryLabelstringTool name, as shown in the help message
binaryNamestringBinary name, as shown in the usage line
binaryVersionstringTool version, as shown in --version
enableCapturebooleanIf set, redirect stdout/stderr into the command streams
enableColorsbooleanOverrides the automatic color detection for error messages

Cli#process​

ts
cli.process(input: string[])
ts
cli.process(input: string[])

Turn the given arguments into a partially hydrated command instance. Don't call execute on it, as some fields must still be set before the command can be truly executed. Instead, pass it forward to Cli#run if you wish to truly execute it.

Cli#run​

ts
cli.run(input: Command, context: Context)
cli.run(input: string[], context: Context)
ts
cli.run(input: Command, context: Context)
cli.run(input: string[], context: Context)

Turn the given argument into a command that will be immediately executed and returned. If an error happens during execution Cli#run will catch it and resolve with an exit code 1 instead.

Cli#runExit​

ts
cli.runExit(input: string[], context?: Context)
ts
cli.runExit(input: string[], context?: Context)

Same thing as Cli#run, but catches the result of the command and sets process.exitCode accordingly. Note that it won't directly call process.exit, so the process may stay alive if the event loop isn't empty.