deprecated.md
This file
Path
docs/deprecated.md
192 lines · 5.3 KiB · Markdown
Last changed by
Deprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18
History of this fileTake it
Deprecated functionality (#1349)John Geebefore adoption9f5aabc
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
lines 6–15why, one step back6- [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)12 - [.on('command:*')](#oncommand)13 - [.command('*')](#command)14 - [cmd.description(cmdDescription, argDescriptions)](#cmddescriptioncmddescription-argdescriptions)15 - [InvalidOptionArgumentError](#invalidoptionargumenterror)Deprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18
line 16why, one step back16 - [Short option flag longer than a single character](#short-option-flag-longer-than-a-single-character)Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 17why, one step back17Deprecated functionality (#1349)John Geebefore adoption9f5aabc
lines 18–27why, one step back18## RegExp .option() parameter1920The `.option()` method allowed a RegExp as the third parameter to restrict what values were accepted.2122```js23program.option('-c,--coffee <type>', 'coffee', /short-white|long-black/);24```2526Removed from README in Commander v3. Deprecated from Commander v7.27Fix typo in new docs (#1415)John Geebefore adoption1db83b6
line 28why, one step back28The newer functionality is the Option `.choices()` method, or using a custom option processing function.Deprecated functionality (#1349)John Geebefore adoption9f5aabc
lines 29–37why, one step back2930## noHelp3132This was an option passed to `.command()` to hide the command from the built-in help:3334```js35program.command('example', 'examnple command', { noHelp: true });36```37Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 38why, one step back38The option was renamed `hidden` in Commander v5.1. Deprecated from Commander v7.Deprecated functionality (#1349)John Geebefore adoption9f5aabc
lines 39–53why, one step back3940## Default import of global Command object4142The default import was a global Command object.4344```js45const program = require('commander');46```4748The global Command object is exported as `program` from Commander v5, or import the Command object.4950```js51const { program } = require('commander');52// or53const { Command } = require('commander');Fixed deprecated documentation typomemothelemobefore adoption3a0ef21
line 54why, one step back54const program = new Command()Deprecated functionality (#1349)John Geebefore adoption9f5aabc
lines 55–56why, one step back55```56Simplify typings (#1520)John Geebefore adoptionad3f947
line 57why, one step back57- Removed from README in Commander v5.Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 58why, one step back58- Deprecated from Commander v7.Simplify typings (#1520)John Geebefore adoptionad3f947
line 59why, one step back59- Removed from TypeScript declarations in Commander v8.Deprecated functionality (#1349)John Geebefore adoption9f5aabc
lines 60–101why, one step back6061## Callback to .help() and .outputHelp()6263These routines allowed a callback parameter to process the built-in help before display.6465```js66program.outputHelp((text) => {67 return colors.red(text);68});69```7071The newer approach is to directly access the built-in help text using `.helpInformation()`.7273```js74console.error(colors.red(program.helpInformation()));75```7677Deprecated from Commander v7.7879## .on('--help')8081This 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.8283```js84program.on('--help', function() {85 console.log('')86 console.log('Examples:');87 console.log(' $ custom-help --help');88 console.log(' $ custom-help -h');89});90```9192The replacement is `.addHelpText()`:9394```js95program.addHelpText('after', `96Examples:97 $ custom-help --help98 $ custom-help -h`99);100```101Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
line 102why, one step back102Deprecated from Commander v7.More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 103why, one step back103Deprecate command:* command and event (#1612)John Geebefore adoptiona546970
lines 104–134why, one step back104## .on('command:*')105106This was emitted when the command argument did not match a known subcommand (as part of the implementation of `.command('*')`).107108One use was for adding an error for an unknown subcommand. An error is now the default built-in behaviour.109110A second related use was for making a suggestion for an unknown subcommand. The replacement built-in support is `.showSuggestionAfterError()`,111or for custom behaviour catch the `commander.unknownCommand` error.112113Deprecated from Commander v8.3.114115## .command('*')116117This was used to add a default command to the program.118119```js120program121 .command('*')122 .action(() => console.log('List files by default...'));123```124125You 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.126127```js128program129 .command('list', { isDefault: true })130 .action(() => console.log('List files by default...'));131```132133Removed from README in Commander v5. Deprecated from Commander v8.3.134More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
lines 135–157why, one step back135## cmd.description(cmdDescription, argDescriptions)136137This was used to add command argument descriptions for the help.138139```js140program141 .command('price <book>')142 .description('show price of book', {143 book: 'ISBN number for book'144 });145```146147The new approach is to use the `.argument()` method.148149```js150program151 .command('price')152 .description('show price of book')153 .argument('<book>', 'ISBN number for book');154```155156Deprecated from Commander v8.157Extend .argument() to add default value and custom parse for command-argument (#1508)John Geebefore adoptionf99d6fa
lines 158–186why, one step back158## InvalidOptionArgumentError159160This was used for throwing an error from custom option processing, for a nice error message.161162```js163function myParseInt(value, dummyPrevious) {164 // parseInt takes a string and a radix165 const parsedValue = parseInt(value, 10);166 if (isNaN(parsedValue)) {167 throw new commander.InvalidOptionArgumentError('Not a number.');168 }169 return parsedValue;170}171```172173The replacement is `InvalidArgumentError` since can be used now for custom command-argument processing too.174175```js176function myParseInt(value, dummyPrevious) {177 // parseInt takes a string and a radix178 const parsedValue = parseInt(value, 10);179 if (isNaN(parsedValue)) {180 throw new commander.InvalidArgumentError('Not a number.');181 }182 return parsedValue;183}184```185186Deprecated from Commander v8.Deprecate multi-character short flags (#1718)John Geebefore adoptionacbbe18
lines 187–192why, one step back187188## Short option flag longer than a single character189190Short 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.191192README updated in Commander v3. Deprecated from Commander v9.