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 as async ([#1513])
    • ๐Ÿ’ฅ Breaking: Help method .visibleArguments() returns array of Argument ([#1490])
    • ๐Ÿ’ฅ Breaking: Commander 8 requires Node.js 12 or higher ([#1500])
    • ๐Ÿ’ฅ Breaking: CommanderError code commander.invalidOptionArgument renamed commander.invalidArgument ([#1508])
    • ๐Ÿ’ฅ Breaking: TypeScript declaration for .addTextHelp() callback no longer allows result of undefined, now just string ([#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)
    • InvalidOptionArgumentError (replaced by InvalidArgumentError) ([#1508])

    โœ‚ Removed

    • ๐Ÿ’ฅ Breaking: TypeScript declaration for default export of global Command object ([#1520])
      • (still available as named program export)

    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();