Deprecate command:* command and event (#1612)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by GitHub · parent c1472bc · Browse files · 3 files·+45 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+45 added−18 removed
- other:+45 added−18 removed
Provenance
- Commit
a546970- Tree
82a66c0- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
c1472bc
3 files changed+45 added−18 removed
modified:docs/deprecated.md+45 added-4 removed
123456789101112131415161718192012 unmodified lines3334353626373839404111 unmodified lines5354555646575859606135 unmodified lines9798991009010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713 unmodified lines15115215315411315515615715827 unmodified lines# Deprecated
These features are deprecated, which means they may go away in a future major version of Commander.They are currently still available for backwards compatibility, but should not be used in new code.
- [Deprecated](#deprecated) - [RegExp .option() parameter](#regexp-option-parameter) - [noHelp](#nohelp) - [Default import of global Command object](#default-import-of-global-command-object) - [Callback to .help() and .outputHelp()](#callback-to-help-and-outputhelp) - [.on('--help')](#on--help) - [.on('command:*')](#oncommand) - [.command('*')](#command) - [cmd.description(cmdDescription, argDescriptions)](#cmddescriptioncmddescription-argdescriptions) - [InvalidOptionArgumentError](#invalidoptionargumenterror)
## RegExp .option() parameter
The `.option()` method allowed a RegExp as the third parameter to restrict what values were accepted.
12 unmodified lines```jsprogram.command('example', 'examnple command', { noHelp: true });```
The option was renamed `hidden` in Commander v5.1. Deprecated from Commander v7. The option was renamed `hidden` in Commander v5.1. Deprecated from Commander v7.
## Default import of global Command object
The default import was a global Command object.11 unmodified linesconst program = new Command()```
- Removed from README in Commander v5.- Deprecated from Commander v7. - Deprecated from Commander v7.- Removed from TypeScript declarations in Commander v8.
## Callback to .help() and .outputHelp()
35 unmodified lines $ custom-help -h`);```
Deprecated from Commander v7. Deprecated from Commander v7.
## .on('command:*')
This was emitted when the command argument did not match a known subcommand (as part of the implementation of `.command('*')`).
One use was for adding an error for an unknown subcommand. An error is now the default built-in behaviour.
A second related use was for making a suggestion for an unknown subcommand. The replacement built-in support is `.showSuggestionAfterError()`,or for custom behaviour catch the `commander.unknownCommand` error.
Deprecated from Commander v8.3.
## .command('*')
This was used to add a default command to the program.
```jsprogram .command('*') .action(() => console.log('List files by default...'));```
You may now pass a configuration option of `isDefault: true` when adding a command, whether using a subcommand with an action handler or a stand-alone executable subcommand.
```jsprogram .command('list', { isDefault: true }) .action(() => console.log('List files by default...'));```
Removed from README in Commander v5. Deprecated from Commander v8.3.
## cmd.description(cmdDescription, argDescriptions)
This was used to add command argument descriptions for the help.
13 unmodified lines .description('show price of book') .argument('<book>', 'ISBN number for book');```
Deprecated from Commander v8.
## InvalidOptionArgumentError
27 unmodified linesmodified:Readme_zh-CN.md-7 removed
729 unmodified lines730 ```js731 program.on('option:verbose', function () {732 process.env.VERBOSE = this.opts().verbose;733 });734-735-program.on('command:*', function (operands) {736- console.error(`error: unknown command '${operands[0]}'`);737- const availableCommands = program.commands.map(cmd => cmd.name());738- mySuggestBestMatch(operands[0], availableCommands);739- process.exitCode = 1;740-});734 ```735 736 ## 零碎知识737 221 unmodified linesmodified:Readme.md-7 removed
776 unmodified lines777 ```js778 program.on('option:verbose', function () {779 process.env.VERBOSE = this.opts().verbose;780 });781-782-program.on('command:*', function (operands) {783- console.error(`error: unknown command '${operands[0]}'`);784- const availableCommands = program.commands.map(cmd => cmd.name());785- mySuggestBestMatch(operands[0], availableCommands);786- process.exitCode = 1;787-});781 ```782 783 ## Bits and pieces784 230 unmodified lines