Skip to content

Commit

Permalink
Deprecate command:* command and event (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Sep 25, 2021
1 parent c1472bc commit a546970
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
7 changes: 0 additions & 7 deletions Readme.md
Expand Up @@ -778,13 +778,6 @@ You can execute custom actions by listening to command and option events.
program.on('option:verbose', function () {
process.env.VERBOSE = this.opts().verbose;
});
program.on('command:*', function (operands) {
console.error(`error: unknown command '${operands[0]}'`);
const availableCommands = program.commands.map(cmd => cmd.name());
mySuggestBestMatch(operands[0], availableCommands);
process.exitCode = 1;
});
```
## Bits and pieces
Expand Down
7 changes: 0 additions & 7 deletions Readme_zh-CN.md
Expand Up @@ -731,13 +731,6 @@ program.configureHelp({
program.on('option:verbose', function () {
process.env.VERBOSE = this.opts().verbose;
});
program.on('command:*', function (operands) {
console.error(`error: unknown command '${operands[0]}'`);
const availableCommands = program.commands.map(cmd => cmd.name());
mySuggestBestMatch(operands[0], availableCommands);
process.exitCode = 1;
});
```
## 零碎知识
Expand Down
49 changes: 45 additions & 4 deletions docs/deprecated.md
Expand Up @@ -3,6 +3,17 @@
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.
Expand All @@ -23,7 +34,7 @@ This was an option passed to `.command()` to hide the command from the built-in
program.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

Expand All @@ -43,7 +54,7 @@ const 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()
Expand Down Expand Up @@ -87,7 +98,38 @@ Examples:
);
```

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.

```js
program
.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.

```js
program
.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)

Expand All @@ -110,7 +152,6 @@ program
.argument('<book>', 'ISBN number for book');
```


Deprecated from Commander v8.

## InvalidOptionArgumentError
Expand Down

0 comments on commit a546970

Please sign in to comment.