commander
Advanced tools
Changelog
[9.3.0] (2022-05-28)
.summary()
for a short summary to use instead of description when listing subcommands in help ([#1726])Option.implies()
to set other option values when the option is specified ([#1724])string[]
to .options()
default value parameter type for use with variadic options ([#1721])-ws
) ([#1718])Changelog
[9.2.0] (2022-04-15)
String.prototype.substr
([#1706])Changelog
[9.1.0] (2022-03-19)
.conflicts()
to set conflicting options which can not be specified together ([#1678])Changelog
[9.0.0] (2022-01-28)
.executableDir()
for custom search for subcommands ([#1571])Option
to .option()
or .requiredOption()
([#1655])error()
for generating errors from client code just like Commander generated errors, with support for .configureOutput()
, .exitOverride()
, and .showHelpAfterError()
([#1675]).optsWithGlobals()
to return merged local and global options ([#1671])showSuggestionAfterError
is now on by default ([#1657])executableFile
([#1571])executableFile
([#1571]).choices()
([#1667]).parse()
, .parseAsync()
, .aliases()
([#1669])require.main.filename
when script not known from arguments passed to .parse()
(can supply details using .name()
, and .executableDir()
or executableFile
) ([#1571])Changelog
[8.3.0] (2021-10-22)
.getOptionValueSource()
and .setOptionValueWithSource()
, where expected values for source are one of 'default', 'env', 'config', 'cli' ([#1613]).command('*')
, use default command instead ([#1612])on('command:*')
, use .showSuggestionAfterError()
instead ([#1612])Changelog
[8.2.0] (2021-09-10)
.showSuggestionAfterError()
to show suggestions after unknown command or unknown option ([#1590])Option
support for values from environment variables using .env()
([#1587])Option
method argumentRejected
Changelog
[8.1.0] (2021-07-27)
.copyInheritedSettings()
([#1557])Argument
methods for .argRequired()
and .argOptional()
([#1567])Changelog
[8.0.0] (2021-06-25)
.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]).opts()
return type using TypeScript generics ([#1539]).getOptionValue()
and .setOptionValue()
([#1521]).parseAsync()
is now declared as async
([#1513])Help
method .visibleArguments()
returns array of Argument
([#1490])CommanderError
code commander.invalidOptionArgument
renamed commander.invalidArgument
([#1508]).addTextHelp()
callback no longer allows result of undefined
, now just string
([#1516])index.tab
into a file per class ([#1522]).showHelpAfteError()
) ([#1534])Command
property .arg
initialised to empty array (was previously undefined) ([#1529])cmd.description(desc, argDescriptions)
for adding argument descriptions ([#1490])
.argument(name, description)
instead)InvalidOptionArgumentError
(replaced by InvalidArgumentError
) ([#1508])Command
object ([#1520])
program
export)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();