Skip to content
Myr

deprecated.md

This file

Path

docs/deprecated.md

226 lines · 6.1 KiB · Markdown

Last changed by

Add public Arguments property (#2010)John Geebefore adoption7d23437

History of this file

Take it

The walk stopped after 200 commits: lines older than c09159d point at it.

Modify return type depending on storeOptionsAsProperties parameter (#1424)John Geebefore adoptionc09159d

lines 1–5why, one step back
1# Deprecated
23These features are deprecated, which means they may go away in a future major version of Commander.4They are currently still available for backwards compatibility, but should not be used in new code.5

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

lines 6–11why, one step back
6- [Deprecated](#deprecated)
7 - [RegExp .option() parameter](#regexp-option-parameter)8 - [noHelp](#nohelp)9 - [Default import of global Command object](#default-import-of-global-command-object)10 - [Callback to .help() and .outputHelp()](#callback-to-help-and-outputhelp)11 - [.on('--help')](#on--help)

Deprecate import from commander/esm.mjs (#1887)John Geebefore adoptionffc7897

lines 12–13why, one step back
12 - [.on('command:\*')](#oncommand)
13 - [.command('\*')](#command)

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

lines 14–15why, one step back
14 - [cmd.description(cmdDescription, argDescriptions)](#cmddescriptioncmddescription-argdescriptions)
15 - [InvalidOptionArgumentError](#invalidoptionargumenterror)

Deprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18

line 16why, one step back
16 - [Short option flag longer than a single character](#short-option-flag-longer-than-a-single-character)

Deprecate import from commander/esm.mjs (#1887)John Geebefore adoptionffc7897

line 17why, one step back
17 - [Import from `commander/esm.mjs`](#import-from-commanderesmmjs)

Add public Arguments property (#2010)John Geebefore adoption7d23437

line 18why, one step back
18 - [cmd.\_args](#cmd_args)

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

line 19why, one step back
19

Modify return type depending on storeOptionsAsProperties parameter (#1424)John Geebefore adoptionc09159d

lines 20–39why, one step back
20## RegExp .option() parameter
2122The `.option()` method allowed a RegExp as the third parameter to restrict what values were accepted.2324```js25program.option('-c,--coffee <type>', 'coffee', /short-white|long-black/);26```2728Removed from README in Commander v3. Deprecated from Commander v7.2930The newer functionality is the Option `.choices()` method, or using a custom option processing function.3132## noHelp3334This was an option passed to `.command()` to hide the command from the built-in help:3536```js37program.command('example', 'examnple command', { noHelp: true });38```39

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

line 40why, one step back
40The option was renamed `hidden` in Commander v5.1. Deprecated from Commander v7.

Modify return type depending on storeOptionsAsProperties parameter (#1424)John Geebefore adoptionc09159d

lines 41–55why, one step back
41
42## Default import of global Command object4344The default import was a global Command object.4546```js47const program = require('commander');48```4950The global Command object is exported as `program` from Commander v5, or import the Command object.5152```js53const { program } = require('commander');54// or55const { Command } = require('commander');

Fixed deprecated documentation typomemothelemobefore adoption3a0ef21

line 56why, one step back
56const program = new Command()

Modify return type depending on storeOptionsAsProperties parameter (#1424)John Geebefore adoptionc09159d

lines 57–58why, one step back
57```
58

Simplify typings (#1520)John Geebefore adoptionad3f947

line 59why, one step back
59- Removed from README in Commander v5.

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

line 60why, one step back
60- Deprecated from Commander v7.

Simplify typings (#1520)John Geebefore adoptionad3f947

line 61why, one step back
61- Removed from TypeScript declarations in Commander v8.

Modify return type depending on storeOptionsAsProperties parameter (#1424)John Geebefore adoptionc09159d

lines 62–103why, one step back
62
63## Callback to .help() and .outputHelp()6465These routines allowed a callback parameter to process the built-in help before display.6667```js68program.outputHelp((text) => {69 return colors.red(text);70});71```7273The newer approach is to directly access the built-in help text using `.helpInformation()`.7475```js76console.error(colors.red(program.helpInformation()));77```7879Deprecated from Commander v7.8081## .on('--help')8283This was the way to add custom help after the built-in help. From Commander v3.0.0 this used the custom long help option flags, if changed.8485```js86program.on('--help', function() {87 console.log('')88 console.log('Examples:');89 console.log(' $ custom-help --help');90 console.log(' $ custom-help -h');91});92```9394The replacement is `.addHelpText()`:9596```js97program.addHelpText('after', `98Examples:99 $ custom-help --help100 $ custom-help -h`101);102```103

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

line 104why, one step back
104Deprecated from Commander v7.

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 105why, one step back
105

Deprecate command:* command and event (#1612)John Geebefore adoptiona546970

lines 106–136why, one step back
106## .on('command:*')
107108This was emitted when the command argument did not match a known subcommand (as part of the implementation of `.command('*')`).109110One use was for adding an error for an unknown subcommand. An error is now the default built-in behaviour.111112A second related use was for making a suggestion for an unknown subcommand. The replacement built-in support is `.showSuggestionAfterError()`,113or for custom behaviour catch the `commander.unknownCommand` error.114115Deprecated from Commander v8.3.116117## .command('*')118119This was used to add a default command to the program.120121```js122program123 .command('*')124 .action(() => console.log('List files by default...'));125```126127You 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.128129```js130program131 .command('list', { isDefault: true })132 .action(() => console.log('List files by default...'));133```134135Removed from README in Commander v5. Deprecated from Commander v8.3.136

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

lines 137–159why, one step back
137## cmd.description(cmdDescription, argDescriptions)
138139This was used to add command argument descriptions for the help.140141```js142program143 .command('price <book>')144 .description('show price of book', {145 book: 'ISBN number for book'146 });147```148149The new approach is to use the `.argument()` method.150151```js152program153 .command('price')154 .description('show price of book')155 .argument('<book>', 'ISBN number for book');156```157158Deprecated from Commander v8.159

Extend .argument() to add default value and custom parse for command-argument (#1508)John Geebefore adoptionf99d6fa

lines 160–188why, one step back
160## InvalidOptionArgumentError
161162This was used for throwing an error from custom option processing, for a nice error message.163164```js165function myParseInt(value, dummyPrevious) {166 // parseInt takes a string and a radix167 const parsedValue = parseInt(value, 10);168 if (isNaN(parsedValue)) {169 throw new commander.InvalidOptionArgumentError('Not a number.');170 }171 return parsedValue;172}173```174175The replacement is `InvalidArgumentError` since can be used now for custom command-argument processing too.176177```js178function myParseInt(value, dummyPrevious) {179 // parseInt takes a string and a radix180 const parsedValue = parseInt(value, 10);181 if (isNaN(parsedValue)) {182 throw new commander.InvalidArgumentError('Not a number.');183 }184 return parsedValue;185}186```187188Deprecated from Commander v8.

Deprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18

lines 189–194why, one step back
189
190## Short option flag longer than a single character191192Short option flags like `-ws` were never supported, but the old README did not make this clear. The README now states that short options are a single character.193194README updated in Commander v3. Deprecated from Commander v9.

Deprecate import from commander/esm.mjs (#1887)John Geebefore adoptionffc7897

lines 195–210why, one step back
195
196## Import from `commander/esm.mjs`197198The first support for named imports required an explicit entry file.199200```js201import { Command } from 'commander/esm.mjs';202```203204This is no longer required, just import directly from the module.205206```js207import { Command } from 'commander';208```209210README updated in Commander v9. Deprecated from Commander v9.

Add public Arguments property (#2010)John Geebefore adoption7d23437

lines 211–226why, one step back
211
212## cmd._args213214This was always private, but was previously the only way to access the command `Argument` array.215216```js217const registeredArguments = program._args;218```219220The registered command arguments are now accessible via `.registeredArguments`.221222```js223const registeredArguments = program.registeredArguments;224```225226Deprecated from Commander v11.