Added
.argument(name, description)
for adding command-arguments (#1490).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();