UNPKG

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