Command
Constructors
new Command()
new Command(name?): CommandParameters
| Parameter | Type |
|---|---|
|
|
Returns
Overrides
CommanderCommand.constructorProperties
| Property | Modifier | Type | Default value | Overrides |
|---|---|---|---|---|
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
| ‐ | ||
|
| ‐ | ||
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| | |
|
|
| ‐ | |
|
|
| | |
|
| | ||
|
|
| | |
| typeof |
| ‐ |
Accessors
app
Get Signature
get app(): typeof ApplicationReturns
typeof Application
in
Get Signature
get in(): InputReturns
log
Get Signature
get log(): LoggerReturns
Logger
out
Get Signature
get out(): OutputReturns
Methods
_outputHelpIfRequested()
_outputHelpIfRequested(args): voidParameters
| Parameter | Type |
|---|---|
|
|
Returns
void
action()
action(fn): thisRegister callback fn for the command.
Parameters
| Parameter | Type |
|---|---|
| ( |
Returns
this
this command for chaining
Example
program
.command('serve')
.description('start service')
.action(function() {
// do work here
});Overrides
CommanderCommand.actionaddGlobalOptions()
addGlobalOptions(cmd): CommandParameters
| Parameter | Type |
|---|---|
|
Returns
addSubCommand()
Call Signature
addSubCommand(name): thisParameters
| Parameter | Type |
|---|---|
|
|
Returns
this
Returns instance of subcommand
Returns instance of subcommand
Call Signature
addSubCommand(
name,
description,
_arguments?): thisParameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
this
Returns instance of subcommand
Returns the current command for chaining
configureHelp()
Call Signature
configureHelp(): HelpConfigurationYou can customise the help by overriding Help properties using configureHelp(), or with a subclass of Help by overriding createHelp().
Returns
Overrides
CommanderCommand.configureHelpCall Signature
configureHelp(configuration): thisGet configuration
Parameters
| Parameter | Type |
|---|---|
|
Returns
this
Overrides
CommanderCommand.configureHelpcreateArgument()
createArgument(name, description?): ArgumentFactory 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.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
Argument
Overrides
CommanderCommand.createArgumentcreateCommand()
createCommand(name?): CommandFactory 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.
Parameters
| Parameter | Type |
|---|---|
|
|
Returns
Overrides
CommanderCommand.createCommandcreateHelp()
createHelp(): HelpYou can customise the help with a subclass of Help by overriding createHelp, or by overriding Help properties using configureHelp().
Returns
Overrides
CommanderCommand.createHelpcreateOption()
createOption(flags, description?): OptionFactory 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.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
Option
Overrides
CommanderCommand.createOptionexamples()
Call Signature
examples(): stringReturns
string
Call Signature
examples(examples): thisParameters
| Parameter | Type |
|---|---|
|
|
Returns
this
executableFile()
Call Signature
executableFile(): stringReturns
string
Call Signature
executableFile(executableFile): thisParameters
| Parameter | Type |
|---|---|
|
|
Returns
this
getExecutableFileCommand()
getExecutableFileCommand(): Promise<Command>Commander was never meant to load subcommands as modules. Commander runs subcommands as child processes
So this way is abit of hacky way to load a subcommand as a module
Returns
Promise<Command>
importAllExecutableSubCommands()
importAllExecutableSubCommands(inheritSettings, inheritGlobalOptions): Promise<Command[]>Parameters
| Parameter | Type | Default value |
|---|---|---|
|
|
|
|
|
|
Returns
Promise<Command[]>
parse()
parse(argv?, parseOptions?): thisParameters
| Parameter | Type |
|---|---|
| readonly |
|
|
Returns
this
Returns instance of subcommand
Overrides
CommanderCommand.parseparseAsync()
parseAsync(argv?, parseOptions?): Promise<any>Parse argv, setting options and invoking commands when defined.
Call with no parameters to parse process.argv. Detects Electron and special node options like node --eval. Easy mode!
Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are from:
'node': default,argv[0]is the application andargv[1]is the script being run, with user arguments after that'electron':argv[0]is the application andargv[1]varies depending on whether the electron application is packaged'user': just user arguments
Parameters
| Parameter | Type |
|---|---|
| readonly |
|
|
Returns
Promise<any>
Promise
Example
await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]Overrides
CommanderCommand.parseAsync