ffe66a49ac772f4732132116c3dbdc16f02604207737eaf3bb8649a3859789961ea9f95a837be6b88e2c1adedfbaf843060be7d437ad5399495507fe1d1bf2 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. # Changelog
  2. All notable changes to this project will be documented in this file.
  3. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
  4. and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). (Format adopted after v3.0.0.)
  5. <!-- markdownlint-disable MD024 -->
  6. <!-- markdownlint-disable MD004 -->
  7. ## [7.2.0] (2021-03-26)
  8. ### Added
  9. - TypeScript typing for `parent` property on `Command` ([#1475])
  10. - TypeScript typing for `.attributeName()` on `Option` ([#1483])
  11. - support information in package ([#1477])
  12. ### Changed
  13. - improvements to error messages, README, and tests
  14. - update dependencies
  15. ## [7.1.0] (2021-02-15)
  16. ### Added
  17. - support for named imports from ECMAScript modules ([#1440])
  18. - add `.cjs` to list of expected script file extensions ([#1449])
  19. - allow using option choices and variadic together ([#1454])
  20. ### Fixed
  21. - replace use of deprecated `process.mainModule` ([#1448])
  22. - regression for legacy `command('*')` and call when command line includes options ([#1464])
  23. - regression for `on('command:*', ...)` and call when command line includes unknown options ([#1464])
  24. - display best error for combination of unknown command and unknown option (i.e. unknown command) ([#1464])
  25. ### Changed
  26. - make TypeScript typings tests stricter ([#1453])
  27. - improvements to README and tests
  28. ## [7.0.0] (2021-01-15)
  29. ### Added
  30. - `.enablePositionalOptions()` to let program and subcommand reuse same option ([#1427])
  31. - `.passThroughOptions()` to pass options through to other programs without needing `--` ([#1427])
  32. - `.allowExcessArguments(false)` to show an error message if there are too many command-arguments on command line for the action handler ([#1409])
  33. - `.configureOutput()` to modify use of stdout and stderr or customise display of errors ([#1387])
  34. - use `.addHelpText()` to add text before or after the built-in help, for just current command or also for all subcommands ([#1296])
  35. - enhance Option class ([#1331])
  36. - allow hiding options from help
  37. - allow restricting option arguments to a list of choices
  38. - allow setting how default value is shown in help
  39. - `.createOption()` to support subclassing of automatically created options (like `.createCommand()`) ([#1380])
  40. - refactor the code generating the help into a separate public Help class ([#1365])
  41. - support sorting subcommands and options in help
  42. - support specifying wrap width (columns)
  43. - allow subclassing Help class
  44. - allow configuring Help class without subclassing
  45. ### Changed
  46. - *Breaking:* options are stored safely by default, not as properties on the command ([#1409])
  47. - this especially affects accessing options on program, use `program.opts()`
  48. - revert behaviour with `.storeOptionsAsProperties()`
  49. - *Breaking:* action handlers are passed options and command separately ([#1409])
  50. - deprecated callback parameter to `.help()` and `.outputHelp()` (removed from README) ([#1296])
  51. - *Breaking:* errors now displayed using `process.stderr.write()` instead of `console.error()`
  52. - deprecate `.on('--help')` (removed from README) ([#1296])
  53. - initialise the command description to empty string (previously undefined) ([#1365])
  54. - document and annotate deprecated routines ([#1349])
  55. ### Fixed
  56. - wrapping bugs in help ([#1365])
  57. - first line of command description was wrapping two characters early
  58. - pad width calculation was not including help option and help command
  59. - pad width calculation was including hidden options and commands
  60. - improve backwards compatibility for custom command event listeners ([#1403])
  61. ### Deleted
  62. - *Breaking:* `.passCommandToAction()` ([#1409])
  63. - no longer needed as action handler is passed options and command
  64. - *Breaking:* "extra arguments" parameter to action handler ([#1409])
  65. - if being used to detect excess arguments, there is now an error available by setting `.allowExcessArguments(false)`
  66. ### Migration Tips
  67. The biggest change is the parsed option values. Previously the options were stored by default as properties on the command object, and now the options are stored separately.
  68. If you wish to restore the old behaviour and get running quickly you can call `.storeOptionsAsProperties()`.
  69. To allow you to move to the new code patterns incrementally, the action handler will be passed the command _twice_,
  70. to match the new "options" and "command" parameters (see below).
  71. **program options**
  72. Use the `.opts()` method to access the options. This is available on any command but is used most with the program.
  73. ```js
  74. program.option('-d, --debug');
  75. program.parse();
  76. // Old code before Commander 7
  77. if (program.debug) console.log(`Program name is ${program.name()}`);
  78. ```
  79. ```js
  80. // New code
  81. const options = program.opts();
  82. if (options.debug) console.log(`Program name is ${program.name()}`);
  83. ```
  84. **action handler**
  85. The action handler gets passed a parameter for each command-argument you declared. Previously by default the next parameter was the command object with the options as properties. Now the next two parameters are instead the options and the command. If you
  86. only accessed the options there may be no code changes required.
  87. ```js
  88. program
  89. .command('compress <filename>')
  90. .option('-t, --trace')
  91. // Old code before Commander 7
  92. .action((filename, cmd)) => {
  93. if (cmd.trace) console.log(`Command name is ${cmd.name()}`);
  94. });
  95. ```
  96. ```js
  97. // New code
  98. .action((filename, options, command)) => {
  99. if (options.trace) console.log(`Command name is ${command.name()}`);
  100. });
  101. ```
  102. If you already set `.storeOptionsAsProperties(false)` you may still need to adjust your code.
  103. ```js
  104. program
  105. .command('compress <filename>')
  106. .storeOptionsAsProperties(false)
  107. .option('-t, --trace')
  108. // Old code before Commander 7
  109. .action((filename, command)) => {
  110. if (command.opts().trace) console.log(`Command name is ${command.name()}`);
  111. });
  112. ```
  113. ```js
  114. // New code
  115. .action((filename, options, command)) => {
  116. if (command.opts().trace) console.log(`Command name is ${command.name()}`);
  117. });
  118. ```
  119. ## [7.0.0-2] (2020-12-14)
  120. (Released in 7.0.0)
  121. ## [7.0.0-1] (2020-11-21)
  122. (Released in 7.0.0)
  123. ## [7.0.0-0] (2020-10-25)
  124. (Released in 7.0.0)
  125. ## [6.2.1] (2020-12-13)
  126. ### Fixed
  127. - some tests failed if directory path included a space ([1390])
  128. ## [6.2.0] (2020-10-25)
  129. ### Added
  130. - added 'tsx' file extension for stand-alone executable subcommands ([#1368])
  131. - documented second parameter to `.description()` to describe command arguments ([#1353])
  132. - documentation of special cases with options taking varying numbers of option-arguments ([#1332])
  133. - documentation for terminology ([#1361])
  134. ### Fixed
  135. - add missing TypeScript definition for `.addHelpCommand()' ([#1375])
  136. - removed blank line after "Arguments:" in help, to match "Options:" and "Commands:" ([#1360])
  137. ### Changed
  138. - update dependencies
  139. ## [6.1.0] (2020-08-28)
  140. ### Added
  141. - include URL to relevant section of README for error for potential conflict between Command properties and option values ([#1306])
  142. - `.combineFlagAndOptionalValue(false)` to ease upgrade path from older versions of Commander ([#1326])
  143. - allow disabling the built-in help option using `.helpOption(false)` ([#1325])
  144. - allow just some arguments in `argumentDescription` to `.description()` ([#1323])
  145. ### Changed
  146. - tidy async test and remove lint override ([#1312])
  147. ### Fixed
  148. - executable subcommand launching when script path not known ([#1322])
  149. ## [6.0.0] (2020-07-21)
  150. ### Added
  151. - add support for variadic options ([#1250])
  152. - allow options to be added with just a short flag ([#1256])
  153. - *Breaking* the option property has same case as flag. e.g. flag `-n` accessed as `opts().n` (previously uppercase)
  154. - *Breaking* throw an error if there might be a clash between option name and a Command property, with advice on how to resolve ([#1275])
  155. ### Fixed
  156. - Options which contain -no- in the middle of the option flag should not be treated as negatable. ([#1301])
  157. ## [6.0.0-0] (2020-06-20)
  158. (Released in 6.0.0)
  159. ## [5.1.0] (2020-04-25)
  160. ### Added
  161. - support for multiple command aliases, the first of which is shown in the auto-generated help ([#531], [#1236])
  162. - configuration support in `addCommand()` for `hidden` and `isDefault` ([#1232])
  163. ### Fixed
  164. - omit masked help flags from the displayed help ([#645], [#1247])
  165. - remove old short help flag when change help flags using `helpOption` ([#1248])
  166. ### Changed
  167. - remove use of `arguments` to improve auto-generated help in editors ([#1235])
  168. - rename `.command()` configuration `noHelp` to `hidden` (but not remove old support) ([#1232])
  169. - improvements to documentation
  170. - update dependencies
  171. - update tested versions of node
  172. - eliminate lint errors in TypeScript ([#1208])
  173. ## [5.0.0] (2020-03-14)
  174. ### Added
  175. * support for nested commands with action-handlers ([#1] [#764] [#1149])
  176. * `.addCommand()` for adding a separately configured command ([#764] [#1149])
  177. * allow a non-executable to be set as the default command ([#742] [#1149])
  178. * implicit help command when there are subcommands (previously only if executables) ([#1149])
  179. * customise implicit help command with `.addHelpCommand()` ([#1149])
  180. * display error message for unknown subcommand, by default ([#432] [#1088] [#1149])
  181. * display help for missing subcommand, by default ([#1088] [#1149])
  182. * combined short options as single argument may include boolean flags and value flag and value (e.g. `-a -b -p 80` can be written as `-abp80`) ([#1145])
  183. * `.parseOption()` includes short flag and long flag expansions ([#1145])
  184. * `.helpInformation()` returns help text as a string, previously a private routine ([#1169])
  185. * `.parse()` implicitly uses `process.argv` if arguments not specified ([#1172])
  186. * optionally specify where `.parse()` arguments "from", if not following node conventions ([#512] [#1172])
  187. * suggest help option along with unknown command error ([#1179])
  188. * TypeScript definition for `commands` property of `Command` ([#1184])
  189. * export `program` property ([#1195])
  190. * `createCommand` factory method to simplify subclassing ([#1191])
  191. ### Fixed
  192. * preserve argument order in subcommands ([#508] [#962] [#1138])
  193. * do not emit `command:*` for executable subcommands ([#809] [#1149])
  194. * action handler called whether or not there are non-option arguments ([#1062] [#1149])
  195. * combining option short flag and value in single argument now works for subcommands ([#1145])
  196. * only add implicit help command when it will not conflict with other uses of argument ([#1153] [#1149])
  197. * implicit help command works with command aliases ([#948] [#1149])
  198. * options are validated whether or not there is an action handler ([#1149])
  199. ### Changed
  200. * *Breaking* `.args` contains command arguments with just recognised options removed ([#1032] [#1138])
  201. * *Breaking* display error if required argument for command is missing ([#995] [#1149])
  202. * tighten TypeScript definition of custom option processing function passed to `.option()` ([#1119])
  203. * *Breaking* `.allowUnknownOption()` ([#802] [#1138])
  204. * unknown options included in arguments passed to command action handler
  205. * unknown options included in `.args`
  206. * only recognised option short flags and long flags are expanded (e.g. `-ab` or `--foo=bar`) ([#1145])
  207. * *Breaking* `.parseOptions()` ([#1138])
  208. * `args` in returned result renamed `operands` and does not include anything after first unknown option
  209. * `unknown` in returned result has arguments after first unknown option including operands, not just options and values
  210. * *Breaking* `.on('command:*', callback)` and other command events passed (changed) results from `.parseOptions`, i.e. operands and unknown ([#1138])
  211. * refactor Option from prototype to class ([#1133])
  212. * refactor Command from prototype to class ([#1159])
  213. * changes to error handling ([#1165])
  214. * throw for author error, not just display message
  215. * preflight for variadic error
  216. * add tips to missing subcommand executable
  217. * TypeScript fluent return types changed to be more subclass friendly, return `this` rather than `Command` ([#1180])
  218. * `.parseAsync` returns `Promise<this>` to be consistent with `.parse()` ([#1180])
  219. * update dependencies
  220. ### Removed
  221. * removed EventEmitter from TypeScript definition for Command, eliminating implicit peer dependency on `@types/node` ([#1146])
  222. * removed private function `normalize` (the functionality has been integrated into `parseOptions`) ([#1145])
  223. * `parseExpectedArgs` is now private ([#1149])
  224. ### Migration Tips
  225. If you use `.on('command:*')` or more complicated tests to detect an unrecognised subcommand, you may be able to delete the code and rely on the default behaviour.
  226. If you use `program.args` or more complicated tests to detect a missing subcommand, you may be able to delete the code and rely on the default behaviour.
  227. If you use `.command('*')` to add a default command, you may be be able to switch to `isDefault:true` with a named command.
  228. If you want to continue combining short options with optional values as though they were boolean flags, set `combineFlagAndOptionalValue(false)`
  229. to expand `-fb` to `-f -b` rather than `-f b`.
  230. ## [5.0.0-4] (2020-03-03)
  231. (Released in 5.0.0)
  232. ## [5.0.0-3] (2020-02-20)
  233. (Released in 5.0.0)
  234. ## [5.0.0-2] (2020-02-10)
  235. (Released in 5.0.0)
  236. ## [5.0.0-1] (2020-02-08)
  237. (Released in 5.0.0)
  238. ## [5.0.0-0] (2020-02-02)
  239. (Released in 5.0.0)
  240. ## Older versions
  241. * [4.x](./changelogs/CHANGELOG-4.md)
  242. * [3.x](./changelogs/CHANGELOG-3.md)
  243. * [2.x](./changelogs/CHANGELOG-2.md)
  244. * [1.x](./changelogs/CHANGELOG-1.md)
  245. * [0.x](./changelogs/CHANGELOG-0.md)
  246. [#1]: https://github.com/tj/commander.js/issues/1
  247. [#432]: https://github.com/tj/commander.js/issues/432
  248. [#508]: https://github.com/tj/commander.js/issues/508
  249. [#512]: https://github.com/tj/commander.js/issues/512
  250. [#531]: https://github.com/tj/commander.js/issues/531
  251. [#645]: https://github.com/tj/commander.js/issues/645
  252. [#742]: https://github.com/tj/commander.js/issues/742
  253. [#764]: https://github.com/tj/commander.js/issues/764
  254. [#802]: https://github.com/tj/commander.js/issues/802
  255. [#809]: https://github.com/tj/commander.js/issues/809
  256. [#948]: https://github.com/tj/commander.js/issues/948
  257. [#962]: https://github.com/tj/commander.js/issues/962
  258. [#995]: https://github.com/tj/commander.js/issues/995
  259. [#1032]: https://github.com/tj/commander.js/issues/1032
  260. [#1062]: https://github.com/tj/commander.js/pull/1062
  261. [#1088]: https://github.com/tj/commander.js/issues/1088
  262. [#1119]: https://github.com/tj/commander.js/pull/1119
  263. [#1133]: https://github.com/tj/commander.js/pull/1133
  264. [#1138]: https://github.com/tj/commander.js/pull/1138
  265. [#1145]: https://github.com/tj/commander.js/pull/1145
  266. [#1146]: https://github.com/tj/commander.js/pull/1146
  267. [#1149]: https://github.com/tj/commander.js/pull/1149
  268. [#1153]: https://github.com/tj/commander.js/issues/1153
  269. [#1159]: https://github.com/tj/commander.js/pull/1159
  270. [#1165]: https://github.com/tj/commander.js/pull/1165
  271. [#1169]: https://github.com/tj/commander.js/pull/1169
  272. [#1172]: https://github.com/tj/commander.js/pull/1172
  273. [#1179]: https://github.com/tj/commander.js/pull/1179
  274. [#1180]: https://github.com/tj/commander.js/pull/1180
  275. [#1184]: https://github.com/tj/commander.js/pull/1184
  276. [#1191]: https://github.com/tj/commander.js/pull/1191
  277. [#1195]: https://github.com/tj/commander.js/pull/1195
  278. [#1208]: https://github.com/tj/commander.js/pull/1208
  279. [#1232]: https://github.com/tj/commander.js/pull/1232
  280. [#1235]: https://github.com/tj/commander.js/pull/1235
  281. [#1236]: https://github.com/tj/commander.js/pull/1236
  282. [#1247]: https://github.com/tj/commander.js/pull/1247
  283. [#1248]: https://github.com/tj/commander.js/pull/1248
  284. [#1250]: https://github.com/tj/commander.js/pull/1250
  285. [#1256]: https://github.com/tj/commander.js/pull/1256
  286. [#1275]: https://github.com/tj/commander.js/pull/1275
  287. [#1296]: https://github.com/tj/commander.js/pull/1296
  288. [#1301]: https://github.com/tj/commander.js/issues/1301
  289. [#1306]: https://github.com/tj/commander.js/pull/1306
  290. [#1312]: https://github.com/tj/commander.js/pull/1312
  291. [#1322]: https://github.com/tj/commander.js/pull/1322
  292. [#1323]: https://github.com/tj/commander.js/pull/1323
  293. [#1325]: https://github.com/tj/commander.js/pull/1325
  294. [#1326]: https://github.com/tj/commander.js/pull/1326
  295. [#1331]: https://github.com/tj/commander.js/pull/1331
  296. [#1332]: https://github.com/tj/commander.js/pull/1332
  297. [#1349]: https://github.com/tj/commander.js/pull/1349
  298. [#1353]: https://github.com/tj/commander.js/pull/1353
  299. [#1360]: https://github.com/tj/commander.js/pull/1360
  300. [#1361]: https://github.com/tj/commander.js/pull/1361
  301. [#1365]: https://github.com/tj/commander.js/pull/1365
  302. [#1368]: https://github.com/tj/commander.js/pull/1368
  303. [#1375]: https://github.com/tj/commander.js/pull/1375
  304. [#1380]: https://github.com/tj/commander.js/pull/1380
  305. [#1387]: https://github.com/tj/commander.js/pull/1387
  306. [#1390]: https://github.com/tj/commander.js/pull/1390
  307. [#1403]: https://github.com/tj/commander.js/pull/1403
  308. [#1409]: https://github.com/tj/commander.js/pull/1409
  309. [#1427]: https://github.com/tj/commander.js/pull/1427
  310. [#1440]: https://github.com/tj/commander.js/pull/1440
  311. [#1448]: https://github.com/tj/commander.js/pull/1448
  312. [#1449]: https://github.com/tj/commander.js/pull/1449
  313. [#1453]: https://github.com/tj/commander.js/pull/1453
  314. [#1454]: https://github.com/tj/commander.js/pull/1454
  315. [#1464]: https://github.com/tj/commander.js/pull/1464
  316. [#1475]: https://github.com/tj/commander.js/pull/1475
  317. [#1477]: https://github.com/tj/commander.js/pull/1477
  318. [#1483]: https://github.com/tj/commander.js/pull/1483
  319. [Unreleased]: https://github.com/tj/commander.js/compare/master...develop
  320. [7.2.0]: https://github.com/tj/commander.js/compare/v7.1.0...v7.2.0
  321. [7.1.0]: https://github.com/tj/commander.js/compare/v7.0.0...v7.1.0
  322. [7.0.0]: https://github.com/tj/commander.js/compare/v6.2.1...v7.0.0
  323. [7.0.0-2]: https://github.com/tj/commander.js/compare/v7.0.0-1...v7.0.0-2
  324. [7.0.0-1]: https://github.com/tj/commander.js/compare/v7.0.0-0...v7.0.0-1
  325. [7.0.0-0]: https://github.com/tj/commander.js/compare/v6.2.0...v7.0.0-0
  326. [6.2.1]: https://github.com/tj/commander.js/compare/v6.2.0..v6.2.1
  327. [6.2.0]: https://github.com/tj/commander.js/compare/v6.1.0..v6.2.0
  328. [6.1.0]: https://github.com/tj/commander.js/compare/v6.0.0..v6.1.0
  329. [6.0.0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0
  330. [6.0.0-0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0-0
  331. [5.1.0]: https://github.com/tj/commander.js/compare/v5.0.0..v5.1.0
  332. [5.0.0]: https://github.com/tj/commander.js/compare/v4.1.1..v5.0.0
  333. [5.0.0-4]: https://github.com/tj/commander.js/compare/v5.0.0-3..v5.0.0-4
  334. [5.0.0-3]: https://github.com/tj/commander.js/compare/v5.0.0-2..v5.0.0-3
  335. [5.0.0-2]: https://github.com/tj/commander.js/compare/v5.0.0-1..v5.0.0-2
  336. [5.0.0-1]: https://github.com/tj/commander.js/compare/v5.0.0-0..v5.0.0-1
  337. [5.0.0-0]: https://github.com/tj/commander.js/compare/v4.1.1..v5.0.0-0