Optional
callback: ((this, cmd) => void)Optional
parent: CommandBuilder<unknown[], OptionValues>Readonly
$Protected
Readonly
featuresReadonly
metaReadonly
parentStatic
dataReturns whether a command's last argument is variadic.
Get the command at the root of the command tree.
Register callback function for the command to execute when invoked.
Rest
...args: any[]Override default decision whether to add implicit help command.
Optional
enableOrNameAndArgs: string | booleanOptional
description: stringthis
command for chaining
addHelpCommand() // force on
addHelpCommand(false); // force off
addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
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.
Protected
addSet 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.
Set aliases for the command. This overwrites all previously set aliases. Only the first alias is shown in the auto-generated help.
Rest
...aliases: string[]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
Create a new argument.
argument name
Optional
description: stringdescribe the argument
Protected
assertProtected
assertProtected
assertProtected
assertAutomatically set 'short' and 'long' names to options that don't have one assigned yet.
First, it tries to assign a short name based on the first letter of the option's attribute name Both lower and upper case are tried. If these is not available, the next letter of the option name is tried.
If none of the letters of the option name are available, the option is skipped until all other options have had letters from their names attempted assigned. Those that remain are assigned the first available letter of the alphabet + 0-9. If there are 64 options for the command and no more alphanumeric characters are available, the option is not assigned a short name.
Makes aliases for the command. The idea is to be able to navigate the command tree by only typing the first letter(s) of the command names.
Example: A command 'cola' would get these aliases: ['c', 'co', 'col']. However, if there are package clashes with sibling subcommands that start with the same letter, eg. like 'cola' and 'coal' where the first two letters clash, cola's aliases are reduced to only ['col'] and similarly for 'coal'.
This method creates the aliases, ensuring there are no clashes with sublings, why it is important that the entire command tree is built before invoking this method.
Protected
combineCreate a subcommand.
You can customise the help by overriding Help properties using configureHelp(), or with a subclass of Help by overriding createHelp().
Protected
debugSet the description. If more than one sentence or string is given, then the first will be used as summary and the whole text as description.
Rest
...lines: string[]description lines
Optional
options: { Optional
debug?: booleanOptional
disableOptional
disableOptional
disableEnable 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.
Optional
positional: booleanthis
command for chaining
Set the directory for searching for executable subcommands of this command.
Register callback to use as replacement for calling process.exit.
Optional
callback: ((err) => void)Rest
...args: any[]Get a command's ancestors, optionally starting from the command itself.
Optional
options: { Optional
includeOptional
options: { Optional
includeOptional
options: { Optional
includeOptional
options: { Optional
includeProtected
getProtected
getProtected
getProtected
getReturns an array of sibling CommandBuilder objects.
The same as .option() except that the option will be inherited by subcommands.
Optional
description: stringOptional
cb: ((opt, cmd) => void)Protected
handleProtected
hasRest
...names: string[]Protected
hideAdd hook for life cycle event.
Protected
inheritProtected
initializeProtected
initializeCreate a native subcommand.
Define option with flags
, description
, and optional argument parsing function or defaultValue
or both.
The flags
string contains the short and/or long flags, separated by comma, a pipe or space. A required
option-argument is indicated by <>
and an optional option-argument by []
.
Optional
description: stringprogram
.option('-p, --pepper', 'add pepper')
.option('-p, --pizza-type <TYPE>', 'type of pizza') // required argument
.option('-c, --cheese [CHEESE]', 'add extra cheese') // optional
Optional
cb: ((opt, cmd) => void)Protected
padParse 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.
Optional
argv: readonly string[]Optional
options: ParseOptionsthis
command for chaining
program.parse(process.argv);
program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
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.
Optional
argv: readonly string[]Optional
options: ParseOptionsPromise
program.parseAsync(process.argv);
program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
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.
Optional
passThrough: booleanthis
command for chaining
Store option value.
Store option value and where the value came from.
Display the help or a custom message after an error occurs.
Optional
displayHelp: string | booleanDisplay suggestion of similar commands for unknown commands, or options for unknown options.
Optional
displaySuggestion: booleanRest
...names: string[]Set the command usage.
Rest
...examples: { 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
Wrapper around the
See
Command class, for more intuitive construction.