fix: a
This commit is contained in:
75
node_modules/commander/Readme.md
generated
vendored
75
node_modules/commander/Readme.md
generated
vendored
@@ -37,7 +37,7 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
|
||||
- [.usage](#usage)
|
||||
- [.description and .summary](#description-and-summary)
|
||||
- [.helpOption(flags, description)](#helpoptionflags-description)
|
||||
- [.addHelpCommand()](#addhelpcommand)
|
||||
- [.helpCommand()](#helpcommand)
|
||||
- [More configuration](#more-configuration-2)
|
||||
- [Custom event listeners](#custom-event-listeners)
|
||||
- [Bits and pieces](#bits-and-pieces)
|
||||
@@ -79,7 +79,8 @@ const { program } = require('commander');
|
||||
|
||||
program
|
||||
.option('--first')
|
||||
.option('-s, --separator <char>');
|
||||
.option('-s, --separator <char>')
|
||||
.argument('<string>');
|
||||
|
||||
program.parse();
|
||||
|
||||
@@ -174,7 +175,15 @@ const program = new Command();
|
||||
|
||||
## Options
|
||||
|
||||
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|').
|
||||
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|'). To allow a wider range of short-ish flags than just
|
||||
single characters, you may also have two long options. Examples:
|
||||
|
||||
```js
|
||||
program
|
||||
.option('-p, --port <number>', 'server port number')
|
||||
.option('--trace', 'add extra debugging output')
|
||||
.option('--ws, --workspace <name>', 'use a custom workspace')
|
||||
```
|
||||
|
||||
The parsed options can be accessed by calling `.opts()` on a `Command` object, and are passed to the action handler.
|
||||
|
||||
@@ -678,8 +687,7 @@ async function main() {
|
||||
}
|
||||
```
|
||||
|
||||
A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments will be reported as an error. You can suppress the unknown option checks with `.allowUnknownOption()`. By default, it is not an error to
|
||||
pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`.
|
||||
A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments or excess arguments will be reported as an error. You can suppress the unknown option check with `.allowUnknownOption()`. You can suppress the excess arguments check with `.allowExcessArguments()`.
|
||||
|
||||
### Stand-alone executable (sub)commands
|
||||
|
||||
@@ -696,7 +704,7 @@ Example file: [pm](./examples/pm)
|
||||
program
|
||||
.name('pm')
|
||||
.version('0.1.0')
|
||||
.command('install [name]', 'install one or more packages')
|
||||
.command('install [package-names...]', 'install one or more packages')
|
||||
.command('search [query]', 'search with optional query')
|
||||
.command('update', 'update installed packages', { executableFile: 'myUpdateSubCommand' })
|
||||
.command('list', 'list packages installed', { isDefault: true });
|
||||
@@ -904,38 +912,28 @@ program
|
||||
.helpOption('-e, --HELP', 'read more information');
|
||||
```
|
||||
|
||||
### .addHelpCommand()
|
||||
(Or use `.addHelpOption()` to add an option you construct yourself.)
|
||||
|
||||
A help command is added by default if your command has subcommands. You can explicitly turn on or off the implicit help command with `.addHelpCommand()` and `.addHelpCommand(false)`.
|
||||
### .helpCommand()
|
||||
|
||||
A help command is added by default if your command has subcommands. You can explicitly turn on or off the implicit help command with `.helpCommand(true)` and `.helpCommand(false)`.
|
||||
|
||||
You can both turn on and customise the help command by supplying the name and description:
|
||||
|
||||
```js
|
||||
program.addHelpCommand('assist [command]', 'show assistance');
|
||||
program.helpCommand('assist [command]', 'show assistance');
|
||||
```
|
||||
|
||||
(Or use `.addHelpCommand()` to add a command you construct yourself.)
|
||||
|
||||
### More configuration
|
||||
|
||||
The built-in help is formatted using the Help class.
|
||||
You can configure the Help behaviour by modifying data properties and methods using `.configureHelp()`, or by subclassing using `.createHelp()` if you prefer.
|
||||
You can configure the help by modifying data properties and methods using `.configureHelp()`, or by subclassing Help using `.createHelp()` .
|
||||
|
||||
The data properties are:
|
||||
Simple properties include `sortSubcommands`, `sortOptions`, and `showGlobalOptions`. You can add color using the style methods like `styleTitle()`.
|
||||
|
||||
- `helpWidth`: specify the wrap width, useful for unit tests
|
||||
- `sortSubcommands`: sort the subcommands alphabetically
|
||||
- `sortOptions`: sort the options alphabetically
|
||||
- `showGlobalOptions`: show a section with the global options from the parent command(s)
|
||||
|
||||
You can override any method on the [Help](./lib/help.js) class. There are methods getting the visible lists of arguments, options, and subcommands. There are methods for formatting the items in the lists, with each item having a _term_ and _description_. Take a look at `.formatHelp()` to see how they are used.
|
||||
|
||||
Example file: [configure-help.js](./examples/configure-help.js)
|
||||
|
||||
```js
|
||||
program.configureHelp({
|
||||
sortSubcommands: true,
|
||||
subcommandTerm: (cmd) => cmd.name() // Just show the name, instead of short usage.
|
||||
});
|
||||
```
|
||||
For more detail and examples of changing the displayed text, color, and layout see (./docs/help-in-depth.md)
|
||||
|
||||
## Custom event listeners
|
||||
|
||||
@@ -951,22 +949,24 @@ program.on('option:verbose', function () {
|
||||
|
||||
### .parse() and .parseAsync()
|
||||
|
||||
The first argument to `.parse` is the array of strings to parse. You may omit the parameter to implicitly use `process.argv`.
|
||||
Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
||||
|
||||
If the arguments follow different conventions than node you can pass a `from` option in the second parameter:
|
||||
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 parameters after that
|
||||
- 'electron': `argv[1]` varies depending on whether the electron application is packaged
|
||||
- 'user': all of the arguments from the user
|
||||
- `'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
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
program.parse(process.argv); // Explicit, node conventions
|
||||
program.parse(); // Implicit, and auto-detect electron
|
||||
program.parse(['-f', 'filename'], { from: 'user' });
|
||||
program.parse(); // parse process.argv and auto-detect electron and special node flags
|
||||
program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
||||
program.parse(['--port', '80'], { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
||||
```
|
||||
|
||||
Use parseAsync instead of parse if any of your action handlers are async.
|
||||
|
||||
### Parsing Configuration
|
||||
|
||||
If the default parsing does not suit your needs, there are some behaviours to support other usage patterns.
|
||||
@@ -1092,8 +1092,9 @@ program.error('Custom processing has failed', { exitCode: 2, code: 'my.custom.er
|
||||
By default, Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
|
||||
this behaviour and optionally supply a callback. The default override throws a `CommanderError`.
|
||||
|
||||
The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`. The default override behaviour is to throw the error, except for async handling of executable subcommand completion which carries on. The normal display of error messages or version or help
|
||||
is not affected by the override which is called after the display.
|
||||
The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`.
|
||||
Commander expects the callback to terminate the normal program flow, and will call `process.exit` if the callback returns.
|
||||
The normal display of error messages or version or help is not affected by the override which is called after the display.
|
||||
|
||||
```js
|
||||
program.exitOverride();
|
||||
@@ -1136,7 +1137,7 @@ There is more information available about:
|
||||
|
||||
## Support
|
||||
|
||||
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v16.
|
||||
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v18.
|
||||
(For older versions of Node.js, use an older version of Commander.)
|
||||
|
||||
The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
|
||||
|
||||
Reference in New Issue
Block a user