Skip to content
Myr

deprecated.md

This file

Path

docs/deprecated.md

258 lines · 7.2 KiB · Markdown

Last changed by

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

History of this file

Take it

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

Add more tests for implies (#1730)John Geebefore adoption3103c6b

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–18why, 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 - [Import from `commander/esm.mjs`](#import-from-commanderesmmjs)16 - [cmd.\_args](#cmd_args)17 - [.addHelpCommand(string|boolean|undefined)](#addhelpcommandstringbooleanundefined)18 - [Removed](#removed)

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

line 19why, one step back
19 - [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 20why, one step back
20 - [Default import of global Command object](#default-import-of-global-command-object)

Add more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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 more tests for implies (#1730)John Geebefore adoption3103c6b

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### Import from `commander/esm.mjs`

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

lines 172–185why, one step back
172
173The first support for named imports required an explicit entry file.174175```js176import { Command } from 'commander/esm.mjs';177```178179This is no longer required, just import directly from the module.180181```js182import { Command } from 'commander';183```184185README updated in Commander v9. Deprecated from Commander v9.

Add public Arguments property (#2010)John Geebefore adoption7d23437

line 186why, one step back
186

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

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

Add public Arguments property (#2010)John Geebefore adoption7d23437

lines 188–201why, one step back
188
189This was always private, but was previously the only way to access the command `Argument` array.190191```js192const registeredArguments = program._args;193```194195The registered command arguments are now accessible via `.registeredArguments`.196197```js198const registeredArguments = program.registeredArguments;199```200201Deprecated from Commander v11.

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

lines 202–222why, one step back
202
203### .addHelpCommand(string|boolean|undefined)204205This was originally used with a variety of parameters, but not by passing a Command object despite the "add" name.206207```js208program.addHelpCommand('assist [command]');209program.addHelpCommand('assist', 'show assistance');210program.addHelpCommand(false);211212```213214In new code you configure the help command with `.helpCommand()`. Or use `.addHelpCommand()` which now takes a Command object, like `.addCommand()`.215216```js217program.helpCommand('assist [command]');218program.helpCommand('assist', 'show assistance');219program.helpCommand(false);220221program.addHelpCommand(new Command('assist').argument('[command]').description('show assistance'));222```

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

lines 223–226why, one step back
223
224- Removed from README in Commander v12.225- Deprecated from Commander v12.226

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

line 227why, one step back
227## Removed

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

lines 228–236why, one step back
228
229### Short option flag longer than a single character230231Short 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.232233- README updated in Commander v3.234- Deprecated from Commander v9.235- Throws an exception in Commander v13. Deprecated and gone!236- 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 237–258why, one step back
237
238### Default import of global Command object239240The default import was a global Command object.241242```js243const program = require('commander');244```245246The global Command object is exported as `program` from Commander v5, or import the Command object.247248```js249const { program } = require('commander');250// or251const { Command } = require('commander');252const program = new Command()253```254255- Removed from README in Commander v5.256- Deprecated from Commander v7.257- Removed from TypeScript declarations in Commander v8.258- Removed from CommonJS in Commander v12. Deprecated and gone!