Add a prepared subcommand.
See .command() for creating an attached subcommand which inherits settings from its parent.
this
command for chaining
Override default decision whether to add implicit help command.
this
command for chaining
Add additional text to be displayed with the built-in help.
Position is 'before' or 'after' to affect just this command, and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
Set an alias for the command.
You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
this
command for chaining
Get alias for the command.
Set aliases for the command.
Only the first alias is shown in the auto-generated help.
this
command for chaining
Get aliases for the command.
Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
this
command for chaining
Allow unknown options on the command line.
this
command for chaining
Define argument syntax for command.
The default is that the argument is required, and you can explicitly indicate this with <> around the name. Put [] around the name for an optional argument.
this
command for chaining
Define argument syntax for command, adding multiple at once (without descriptions).
See also .argument().
this
command for chaining
Alter parsing of short flags with optional values.
this
command for chaining
Define a command, implemented using an action handler.
command name and arguments, args are <required>
or [optional]
and last may also be variadic...
configuration options
new command
Define a command, implemented in a separate executable file.
command name and arguments, args are <required>
or [optional]
and last may also be variadic...
description of executable command
configuration options
this
command for chaining
The default output goes to stdout and stderr. You can customise this for special applications. You can also customise the display of errors by overriding outputError.
The configuration properties are all functions:
// functions to change where being written, stdout and stderr
writeOut(str)
writeErr(str)
// matching functions to specify width for wrapping help
getOutHelpWidth()
getErrHelpWidth()
// functions based on what is being written out
outputError(str, write) // used for displaying errors, and not used for displaying help
Get configuration
Factory routine to create a new unattached argument.
See .argument() for creating an attached argument, which uses this routine to create the argument. You can override createArgument to return a custom argument.
Factory routine to create a new unattached command.
See .command() for creating an attached subcommand, which uses this routine to create the command. You can override createCommand to customise subcommands.
You can customise the help with a subclass of Help by overriding createHelp, or by overriding Help properties using configureHelp().
Factory routine to create a new unattached option.
See .option() for creating an attached option, which uses this routine to create the option. You can override createOption to return a custom option.
Enable positional options. Positional means global options are specified before subcommands which lets subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
The default behaviour is non-positional and global options may appear anywhere on the command line.
this
command for chaining
Display error message and exit (or call exitOverride).
Set the directory for searching for executable subcommands of this command.
this
command for chaining
Get the executable search directory.
Register callback to use as replacement for calling process.exit.
Retrieve option value.
Retrieve option value source.
Output help information and exit.
Outputs built-in help, and custom text added using .addHelpText()
.
Return command help documentation.
You can pass in flags and a description to override the help flags and help description for your command. Pass in false to disable the built-in help option.
Set the name of the command.
this
command for chaining
Get the name of the command.
Set the name of the command from script filename, such as process.argv[1], or require.main.filename, or __filename.
(Used internally and public although not documented in README.)
this
command for chaining
Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
Define option with flags
, description
and optional
coercion fn
.
The flags
string contains the short and/or long flags,
separated by comma, a pipe or space. The following are all valid
all will output this way when --help
is used.
"-p, --pepper"
"-p|--pepper"
"-p --pepper"
this
command for chaining
Return an object containing local option values as key-value pairs
Return an object containing merged local and global option values as key-value pairs.
Output help information for this command.
Outputs built-in help, and custom text added using .addHelpText()
.
Parse argv
, setting options and invoking commands when defined.
The default expectation is that the arguments are from node and have the application as argv[0] and the script being run in argv[1], with user parameters after that.
this
command for chaining
Parse argv
, setting options and invoking commands when defined.
Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
The default expectation is that the arguments are from node and have the application as argv[0] and the script being run in argv[1], with user parameters after that.
Promise
Parse options from argv
removing known options,
and return argv split into operands and unknown arguments.
argv => operands, unknown
--known kkk op => [op], []
op --known kkk => [op], []
sub --unknown uuu op => [sub], [--unknown uuu op]
sub -- --unknown uuu op => [sub --unknown uuu op], []
Pass through options that come after command-arguments rather than treat them as command-options, so actual command-options come before command-arguments. Turning this on for a subcommand requires positional options to have been enabled on the program (parent commands).
The default behaviour is non-positional and options may appear before or after command-arguments.
this
command for chaining
Define a required option, which must have a value after parsing. This usually means the option must be specified on the command line. (Otherwise the same as .option().)
The flags
string contains the short and/or long flags, separated by comma, a pipe or space.
Store option value.
Store option value and where the value came from.
Display the help or a custom message after an error occurs.
Display suggestion of similar commands for unknown commands, or options for unknown options.
Whether to store option values as properties on command object, or store separately (specify false). In both cases the option values can be accessed using .opts().
this
command for chaining
Set the summary. Used when listed as subcommand of parent.
this
command for chaining
Get the summary.
Set the command usage.
this
command for chaining
Get the command usage.
Set the program version to str
.
This method auto-registers the "-V, --version" flag which will print the version number when passed.
You can optionally supply the flags and description to override the defaults.
Generated using TypeDoc
Register callback
fn
for the command.