Packages

commander

15.1.0 · 7 Nov 2026MIT785.6M / weekRepositoryHomepagenpmAtom feed

Your version

5.0.0

major14 Mar 2020Where it was published

5.1.0 is the newest release of 5.x.

In short

10 breaking11 new2 fixed7 changed1 internal

  • Breaking

    Support for nested commands with action-handlers (#1 #764 #1149)

  • Breaking

    Preserve argument order in subcommands (#508 #962 #1138)

  • Breaking

    Unknown options included in arguments passed to command action handler

  • Breaking

    Unknown options included in .args

  • Breaking

    args in returned result renamed operands and does not include anything after first unknown option

  • Breaking

    unknown in returned result has arguments after first unknown option including operands, not just options and values

  • Breaking

    Breaking .on('command:*', callback) and other command events passed (changed) results from .parseOptions, i.e. operands and unknown

  • Breaking

    Removed EventEmitter from TypeScript definition for Command, eliminating implicit peer dependency on @types/node

Release note

Added

  • Support for nested commands with action-handlers (#1 #764 #1149)

  • .addCommand() for adding a separately configured command (#764 #1149)

  • Allow a non-executable to be set as the default command (#742 #1149)

  • Implicit help command when there are subcommands (previously only if executables)

  • Customise implicit help command with .addHelpCommand()

  • Display error message for unknown subcommand, by default (#432 #1088 #1149)

  • Display help for missing subcommand, by default (#1088 #1149)

  • 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)

  • .parseOption() includes short flag and long flag expansions

  • .helpInformation() returns help text as a string, previously a private routine

  • .parse() implicitly uses process.argv if arguments not specified

  • Optionally specify where .parse() arguments "from", if not following node conventions (#512 #1172)

  • Suggest help option along with unknown command error

  • TypeScript definition for commands property of Command

  • Export program property

  • createCommand factory method to simplify subclassing

Fixed

  • Preserve argument order in subcommands (#508 #962 #1138)

  • Do not emit command:* for executable subcommands (#809 #1149)

  • Action handler called whether or not there are non-option arguments (#1062 #1149)

  • Combining option short flag and value in single argument now works for subcommands

  • Only add implicit help command when it will not conflict with other uses of argument (#1153 #1149)

  • Implicit help command works with command aliases (#948 #1149)

  • Options are validated whether or not there is an action handler

Changed

  • Breaking

    Breaking .args contains command arguments with just recognised options removed (#1032 #1138)

  • Breaking

    Breaking display error if required argument for command is missing (#995 #1149)

  • Tighten TypeScript definition of custom option processing function passed to .option()

  • Breaking

    Breaking .allowUnknownOption() (#802 #1138)

    • unknown options included in arguments passed to command action handler

    • unknown options included in .args

  • Only recognised option short flags and long flags are expanded (e.g. -ab or --foo=bar)

  • Breaking

    Breaking .parseOptions()

    • args in returned result renamed operands and does not include anything after first unknown option

    • unknown in returned result has arguments after first unknown option including operands, not just options and values

  • Breaking

    Breaking .on('command:*', callback) and other command events passed (changed) results from .parseOptions, i.e. operands and unknown

  • Refactor Option from prototype to class

  • Refactor Command from prototype to class

  • Changes to error handling

    • throw for author error, not just display message

    • preflight for variadic error

    • add tips to missing subcommand executable

  • TypeScript fluent return types changed to be more subclass friendly, return this rather than Command

  • .parseAsync returns Promise<this> to be consistent with .parse()

Removed

  • Breaking

    Removed EventEmitter from TypeScript definition for Command, eliminating implicit peer dependency on @types/node

  • Breaking

    Removed private function normalize (the functionality has been integrated into parseOptions)

  • Breaking

    parseExpectedArgs is now private

Migration Tips

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.

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.

If you use .command('*') to add a default command, you may be be able to switch to isDefault:true with a named command.

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.