可选description: string只读commands只读options只读registeredDefine argument syntax for command, adding a prepared argument.
this command for chaining
Add a prepared subcommand.
See .command() for creating an attached subcommand which inherits settings from its parent.
可选opts: CommandOptionsthis command for chaining
Add prepared custom help command.
Supply your own option to use for the built-in help option. This is an alternative to using helpOption() to customise the flags and description etc.
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.
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.
Add a prepared Option.
See .option() and .requiredOption() for creating and attaching an option in a single call.
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.
可选allowExcess: booleanthis command for chaining
Allow unknown options on the command line.
可选allowUnknown: booleanthis 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.
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.
可选description: string可选defaultValue: unknownthis command for chaining
Alter parsing of short flags with optional values.
可选combine: booleanthis 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...
可选opts: CommandOptionsconfiguration 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
可选opts: ExecutableCommandOptionsconfiguration options
this command for chaining
You can customise the help by overriding Help properties using configureHelp(), or with a subclass of Help by overriding createHelp().
Get configuration
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
Copy settings that are useful to have in common across root command and subcommands.
(Used internally when adding a command using .command() so subcommands inherit parent settings.)
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.
可选description: stringFactory 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.
可选name: stringYou 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.
可选description: stringSet the description.
this command for chaining
Get the description.
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.
可选positional: booleanthis command for chaining
Display error message and exit (or call exitOverride).
可选errorOptions: ErrorOptionsGet the executable search directory.
Register callback to use as replacement for calling process.exit.
可选callback: (err: CommanderError) => voidRetrieve option value.
Get source of option value.
Get source of option value. See also .optsWithGlobals().
Output help information and exit.
Outputs built-in help, and custom text added using .addHelpText().
可选context: HelpContextCustomise or override default help command. By default a help command is automatically added if your command has subcommands.
可选description: stringCustomise or override default help command. By default a help command is automatically added if your command has subcommands.
Return command help documentation.
可选context: HelpContextYou 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.
可选flags: string | boolean可选description: string初始化,不包括命令
对命令初始化,增加aliases,summary,description等信息
Set the name of the command.
this command for chaining
Get the name of the command.
Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
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 [].
See the README for more details, and see also addOption() and requiredOption().
可选description: string可选defaultValue: string | boolean | string[]this command for chaining
program
.option('-p, --pepper', 'add pepper')
.option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
.option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
.option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
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 [].
See the README for more details, and see also addOption() and requiredOption().
this command for chaining
program
.option('-p, --pepper', 'add pepper')
.option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
.option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
.option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
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().
可选context: HelpContextParse argv, setting options and invoking commands when defined.
Use parseAsync instead of parse if any of your action handlers are async.
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 and argv[1] is the script being run, with user arguments after that'electron': argv[0] is the application and argv[1] varies depending on whether the electron application is packaged'user': just user arguments可选argv: readonly string[]可选parseOptions: ParseOptionsthis command for chaining
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 and argv[1] is the script being run, with user arguments after that'electron': argv[0] is the application and argv[1] varies depending on whether the electron application is packaged'user': just user arguments可选argv: readonly string[]可选parseOptions: ParseOptionsPromise
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]
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.
可选passThrough: booleanthis 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.
可选description: string可选defaultValue: string | boolean | string[]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.
可选displayHelp: string | booleanDisplay suggestion of similar commands for unknown commands, or options for unknown options.
可选displaySuggestion: booleanWhether 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
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
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().
可选storeAsProperties: booleanthis 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.
可选flags: string可选description: stringGet the program version.
终端交互 参考:https://www.npmjs.com/package/commander