Skip to content
Myr

deprecated.md

This file

Path

docs/deprecated.md

260 lines · 7.3 KiB · Markdown

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1–6why, 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.56- [Deprecated](#deprecated)

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 7–17why, one step back
7 - [RegExp .option() parameter](#regexp-option-parameter)
8 - [noHelp](#nohelp)9 - [Callback to .help() and .outputHelp()](#callback-to-help-and-outputhelp)10 - [.on('--help')](#on--help)11 - [.on('command:\*')](#oncommand)12 - [.command('\*')](#command)13 - [cmd.description(cmdDescription, argDescriptions)](#cmddescriptioncmddescription-argdescriptions)14 - [InvalidOptionArgumentError](#invalidoptionargumenterror)15 - [cmd.\_args](#cmd_args)16 - [.addHelpCommand(string|boolean|undefined)](#addhelpcommandstringbooleanundefined)17 - [Removed](#removed)

Add support for dual long options when no short option (#2312)John Geebefore adoption8263b7f

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

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 19why, one step back
19 - [Default import of global Command object](#default-import-of-global-command-object)

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 21why, one step back
21

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 22why, one step back
22### RegExp .option() parameter

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 23–33why, one step back
23
24The `.option()` method allowed a RegExp as the third parameter to restrict what values were accepted.2526```js27program.option('-c,--coffee <type>', 'coffee', /short-white|long-black/);28```2930Removed from README in Commander v3. Deprecated from Commander v7.3132The newer functionality is the Option `.choices()` method, or using a custom option processing function.33

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 34why, one step back
34### noHelp

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 35–38why, one step back
35
36This was an option passed to `.command()` to hide the command from the built-in help:3738```js

Merge branch 'fix/grammar' of github.com:aweebit/commander.js into aweebit-fix/grammarJohn Geebefore adoption591fc4b

line 39why, one step back
39program.command('example', 'example command', { noHelp: true });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 44why, one step back
44### Callback to .help() and .outputHelp()

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 45–61why, one step back
45
46These routines allowed a callback parameter to process the built-in help before display.4748```js49program.outputHelp((text) => {50 return colors.red(text);51});52```5354The newer approach is to directly access the built-in help text using `.helpInformation()`.5556```js57console.error(colors.red(program.helpInformation()));58```5960Deprecated from Commander v7.61

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 62why, one step back
62### .on('--help')

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 63–86why, one step back
63
64This 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.6566```js67program.on('--help', function() {68 console.log('')69 console.log('Examples:');70 console.log(' $ custom-help --help');71 console.log(' $ custom-help -h');72});73```7475The replacement is `.addHelpText()`:7677```js78program.addHelpText('after', `79Examples:80 $ custom-help --help81 $ custom-help -h`82);83```8485Deprecated from Commander v7.86

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 87why, one step back
87### .on('command:*')

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 88–97why, one step back
88
89This was emitted when the command argument did not match a known subcommand (as part of the implementation of `.command('*')`).9091One use was for adding an error for an unknown subcommand. An error is now the default built-in behaviour.9293A second related use was for making a suggestion for an unknown subcommand. The replacement built-in support is `.showSuggestionAfterError()`,94or for custom behaviour catch the `commander.unknownCommand` error.9596Deprecated from Commander v8.3.97

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 98why, one step back
98### .command('*')

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 99–117why, one step back
99
100This was used to add a default command to the program.101102```js103program104 .command('*')105 .action(() => console.log('List files by default...'));106```107108You 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.109110```js111program112 .command('list', { isDefault: true })113 .action(() => console.log('List files by default...'));114```115116Removed from README in Commander v5. Deprecated from Commander v8.3.117

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 118why, one step back
118### cmd.description(cmdDescription, argDescriptions)

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 119–140why, one step back
119
120This was used to add command argument descriptions for the help.121122```js123program124 .command('price <book>')125 .description('show price of book', {126 book: 'ISBN number for book'127 });128```129130The new approach is to use the `.argument()` method.131132```js133program134 .command('price')135 .description('show price of book')136 .argument('<book>', 'ISBN number for book');137```138139Deprecated from Commander v8.140

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 141why, one step back
141### InvalidOptionArgumentError

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 142–170why, one step back
142
143This was used for throwing an error from custom option processing, for a nice error message.144145```js146function myParseInt(value, dummyPrevious) {147 // parseInt takes a string and a radix148 const parsedValue = parseInt(value, 10);149 if (isNaN(parsedValue)) {150 throw new commander.InvalidOptionArgumentError('Not a number.');151 }152 return parsedValue;153}154```155156The replacement is `InvalidArgumentError` since can be used now for custom command-argument processing too.157158```js159function myParseInt(value, dummyPrevious) {160 // parseInt takes a string and a radix161 const parsedValue = parseInt(value, 10);162 if (isNaN(parsedValue)) {163 throw new commander.InvalidArgumentError('Not a number.');164 }165 return parsedValue;166}167```168169Deprecated from Commander v8.170

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 171why, one step back
171### cmd._args

Add public Arguments property (#2010)John Geebefore adoption7d23437

lines 172–185why, one step back
172
173This was always private, but was previously the only way to access the command `Argument` array.174175```js176const registeredArguments = program._args;177```178179The registered command arguments are now accessible via `.registeredArguments`.180181```js182const registeredArguments = program.registeredArguments;183```184185Deprecated from Commander v11.

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 186–206why, one step back
186
187### .addHelpCommand(string|boolean|undefined)188189This was originally used with a variety of parameters, but not by passing a Command object despite the "add" name.190191```js192program.addHelpCommand('assist [command]');193program.addHelpCommand('assist', 'show assistance');194program.addHelpCommand(false);195196```197198In new code you configure the help command with `.helpCommand()`. Or use `.addHelpCommand()` which now takes a Command object, like `.addCommand()`.199200```js201program.helpCommand('assist [command]');202program.helpCommand('assist', 'show assistance');203program.helpCommand(false);204205program.addHelpCommand(new Command('assist').argument('[command]').description('show assistance'));206```

Fill in detail on addHelpCommand deprecation (#2221)John Geebefore adoption4fcb276

lines 207–210why, one step back
207
208- Removed from README in Commander v12.209- Deprecated from Commander v12.210

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 211why, one step back
211## Removed

Add support for dual long options when no short option (#2312)John Geebefore adoption8263b7f

lines 212–220why, one step back
212
213### Short option flag longer than a single character214215Short 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.216217- README updated in Commander v3.218- Deprecated from Commander v9.219- Throws an exception in Commander v13. Deprecated and gone!220- Replacement added in Commander v13.1 with support for dual long options, like `--ws, --workspace`.

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 221–242why, one step back
221
222### Default import of global Command object223224The default import was a global Command object.225226```js227const program = require('commander');228```229230The global Command object is exported as `program` from Commander v5, or import the Command object.231232```js233const { program } = require('commander');234// or235const { Command } = require('commander');236const program = new Command()237```238239- Removed from README in Commander v5.240- Deprecated from Commander v7.241- Removed from TypeScript declarations in Commander v8.242- Removed from CommonJS in Commander v12. Deprecated and gone!

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 243–260why, one step back
243
244### Import from `commander/esm.mjs`245246The first support for named imports required an explicit entry file.247248```js249import { Command } from 'commander/esm.mjs';250```251252This is no longer required, just import directly from the module.253254```js255import { Command } from 'commander';256```257258- README updated in Commander v9. Deprecated from Commander v9.259- Deleted in Command v15. Deprecated and gone!260