Command
Constructors
new Command()
new Command(name?): Command
Parameters
Parameter | Type |
---|---|
|
|
Returns
Overrides
CommanderCommand.constructor
Properties
Property | Modifier | Type | Default value | Overrides |
---|---|---|---|---|
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
| ‐ | ||
|
| ‐ | ||
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
|
|
| |
|
|
| ‐ | |
|
|
|
| |
|
|
| ||
|
|
|
| |
| typeof |
| ‐ |
Accessors
app
Get Signature
get app(): typeof Application
Returns
typeof Application
in
Get Signature
get in(): Input
Returns
log
Get Signature
get log(): Logger
Returns
Logger
out
Get Signature
get out(): Output
Returns
Methods
_outputHelpIfRequested()
_outputHelpIfRequested(args): void
Parameters
Parameter | Type |
---|---|
|
|
Returns
void
action()
action(fn): this
Register 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.action
addGlobalOptions()
addGlobalOptions(cmd): Command
Parameters
Parameter | Type |
---|---|
|
Returns
addSubCommand()
Call Signature
addSubCommand(name): this
Parameters
Parameter | Type |
---|---|
|
|
Returns
this
Returns instance of subcommand
Returns instance of subcommand
Call Signature
addSubCommand(
name,
description,
_arguments?): this
Parameters
Parameter | Type |
---|---|
|
|
|
|
|
|
Returns
this
Returns instance of subcommand
Returns the current command for chaining
configureHelp()
Call Signature
configureHelp(): HelpConfiguration
You can customise the help by overriding Help properties using configureHelp(), or with a subclass of Help by overriding createHelp().
Returns
Overrides
CommanderCommand.configureHelp
Call Signature
configureHelp(configuration): this
Get configuration
Parameters
Parameter | Type |
---|---|
|
Returns
this
Overrides
CommanderCommand.configureHelp
createArgument()
createArgument(name, description?): Argument
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.
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
Argument
Overrides
CommanderCommand.createArgument
createCommand()
createCommand(name?): Command
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.
Parameters
Parameter | Type |
---|---|
|
|
Returns
Overrides
CommanderCommand.createCommand
createHelp()
createHelp(): Help
You can customise the help with a subclass of Help by overriding createHelp, or by overriding Help properties using configureHelp().
Returns
Overrides
CommanderCommand.createHelp
createOption()
createOption(flags, description?): Option
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.
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
Option
Overrides
CommanderCommand.createOption
examples()
Call Signature
examples(): string
Returns
string
Call Signature
examples(examples): this
Parameters
Parameter | Type |
---|---|
|
|
Returns
this
executableFile()
Call Signature
executableFile(): string
Returns
string
Call Signature
executableFile(executableFile): this
Parameters
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?): this
Parameters
Parameter | Type |
---|---|
| readonly |
|
|
Returns
this
Returns instance of subcommand
Overrides
CommanderCommand.parse
parseAsync()
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