deprecated.md
This file
Path
docs/deprecated.md
252 lines · 7.0 KiB · Markdown
Last changed by
Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
History of this fileTake it
The walk stopped after 200 commits: lines older than a036bde point at it.
Prepare for 8.1John Geebefore adoptiona036bde
lines 1–5why, one step back1# Deprecated23These 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.5Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 6why, one step back6- [Deprecated](#deprecated)Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 7–20why, one step back7 - [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 - [Short option flag longer than a single character](#short-option-flag-longer-than-a-single-character)16 - [Import from `commander/esm.mjs`](#import-from-commanderesmmjs)17 - [cmd.\_args](#cmd_args)18 - [.addHelpCommand(string|boolean|undefined)](#addhelpcommandstringbooleanundefined)19 - [Removed](#removed)20 - [Default import of global Command object](#default-import-of-global-command-object)Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 21why, one step back21Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 22why, one step back22### RegExp .option() parameterPrepare for 8.1John Geebefore adoptiona036bde
lines 23–33why, one step back2324The `.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.33Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 34why, one step back34### noHelpPrepare for 8.1John Geebefore adoptiona036bde
lines 35–38why, one step back3536This was an option passed to `.command()` to hide the command from the built-in help:3738```jsMerge branch 'fix/grammar' of github.com:aweebit/commander.js into aweebit-fix/grammarJohn Geebefore adoption591fc4b
line 39why, one step back39program.command('example', 'example command', { noHelp: true });Prepare for 8.1John Geebefore adoptiona036bde
lines 40–41why, one step back40```41Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 42why, one step back42The option was renamed `hidden` in Commander v5.1. Deprecated from Commander v7.Prepare for 8.1John Geebefore adoptiona036bde
line 43why, one step back43Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 44why, one step back44### Callback to .help() and .outputHelp()Prepare for 8.1John Geebefore adoptiona036bde
lines 45–61why, one step back4546These 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.61Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 62why, one step back62### .on('--help')Prepare for 8.1John Geebefore adoptiona036bde
lines 63–84why, one step back6364This 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```84Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 85why, one step back85Deprecated from Commander v7.Prepare for 8.1John Geebefore adoptiona036bde
line 86why, one step back86Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 87why, one step back87### .on('command:*')Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
lines 88–97why, one step back8889This 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.97Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 98why, one step back98### .command('*')Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
lines 99–117why, one step back99100This 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.117Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 118why, one step back118### cmd.description(cmdDescription, argDescriptions)Prepare for 8.1John Geebefore adoptiona036bde
lines 119–140why, one step back119120This 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.140Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 141why, one step back141### InvalidOptionArgumentErrorPrepare for 8.1John Geebefore adoptiona036bde
lines 142–169why, one step back142143This 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.Deprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18
line 170why, one step back170Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 171why, one step back171### Short option flag longer than a single characterDeprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18
lines 172–175why, one step back172173Short 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.174175README updated in Commander v3. Deprecated from Commander v9.Deprecate import from commander/esm.mjs (#1887)John Geebefore adoptionffc7897
line 176why, one step back176Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 177why, one step back177### Import from `commander/esm.mjs`Deprecate import from commander/esm.mjs (#1887)John Geebefore adoptionffc7897
lines 178–191why, one step back178179The first support for named imports required an explicit entry file.180181```js182import { Command } from 'commander/esm.mjs';183```184185This is no longer required, just import directly from the module.186187```js188import { Command } from 'commander';189```190191README updated in Commander v9. Deprecated from Commander v9.Add public Arguments property (#2010)John Geebefore adoption7d23437
line 192why, one step back192Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 193why, one step back193### cmd._argsAdd public Arguments property (#2010)John Geebefore adoption7d23437
lines 194–207why, one step back194195This was always private, but was previously the only way to access the command `Argument` array.196197```js198const registeredArguments = program._args;199```200201The registered command arguments are now accessible via `.registeredArguments`.202203```js204const registeredArguments = program.registeredArguments;205```206207Deprecated from Commander v11.Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 208–252why, one step back208209### .addHelpCommand(string|boolean|undefined)210211This was originally used with a variety of parameters, but not by passing a Command object despite the "add" name.212213```js214program.addHelpCommand('assist [command]');215program.addHelpCommand('assist', 'show assistance');216program.addHelpCommand(false);217218```219220In new code you configure the help command with `.helpCommand()`. Or use `.addHelpCommand()` which now takes a Command object, like `.addCommand()`.221222```js223program.helpCommand('assist [command]');224program.helpCommand('assist', 'show assistance');225program.helpCommand(false);226227program.addHelpCommand(new Command('assist').argument('[command]').description('show assistance'));228229```230## Removed231232### Default import of global Command object233234The default import was a global Command object.235236```js237const program = require('commander');238```239240The global Command object is exported as `program` from Commander v5, or import the Command object.241242```js243const { program } = require('commander');244// or245const { Command } = require('commander');246const program = new Command()247```248249- Removed from README in Commander v5.250- Deprecated from Commander v7.251- Removed from TypeScript declarations in Commander v8.252- Removed from CommonJS in Commander v12. Deprecated and gone!