Commander.js v8.0.0 Release Notes
Release Date: 2021-06-25 // almost 3 years ago-
โ Added
.argument(name, description)
for adding command-arguments ([#1490])- supports default value for optional command-arguments ([#1508])
- supports custom processing function ([#1508])
.createArgument()
factory method ([#1497]).addArgument()
([#1490])- ๐
Argument
supports.choices()
([#1525]) .showHelpAfterError()
to display full help or a custom message after an error ([#1534])- ๐
.hook()
with support for'preAction'
and'postAction'
callbacks ([#1514]) - client typing of
.opts()
return type using TypeScript generics ([#1539]) - the number of command-arguments is checked for programs without an action handler ([#1502])
.getOptionValue()
and.setOptionValue()
([#1521])
๐ Changed
- ๐จ refactor and simplify TypeScript declarations (with no default export) ([#1520])
- ๐
.parseAsync()
is now declared asasync
([#1513]) - ๐ฅ Breaking:
Help
method.visibleArguments()
returns array ofArgument
([#1490]) - ๐ฅ Breaking: Commander 8 requires Node.js 12 or higher ([#1500])
- ๐ฅ Breaking:
CommanderError
codecommander.invalidOptionArgument
renamedcommander.invalidArgument
([#1508]) - ๐ฅ Breaking: TypeScript declaration for
.addTextHelp()
callback no longer allows result ofundefined
, now juststring
([#1516]) - ๐จ refactor
index.tab
into a file per class ([#1522]) - โ remove help suggestion from "unknown command" error message (see
.showHelpAfteError()
) ([#1534]) Command
property.arg
initialised to empty array (was previously undefined) ([#1529])- โก๏ธ update dependencies
๐ Deprecated
- second parameter of
cmd.description(desc, argDescriptions)
for adding argument descriptions ([#1490])- (use new
.argument(name, description)
instead)
- (use new
InvalidOptionArgumentError
(replaced byInvalidArgumentError
) ([#1508])
โ Removed
- ๐ฅ Breaking: TypeScript declaration for default export of global
Command
object ([#1520])- (still available as named
program
export)
- (still available as named
Migration Tips
If you have a simple program without an action handler, you will now get an error if there are missing command-arguments.
program .option('-d, --debug') .arguments('<file>'); program.parse();
$ node trivial.js error: missing required argument 'file'
๐ If you want to show the help in this situation, you could check the arguments before parsing:
if (process.argv.length === 2) program.help(); program.parse();
Or, you might choose to show the help after any user error:
program.showHelpAfterError();