# Commander.js 13.0.0 - Product: Commander.js (https://whatsnew.fyi/product/commander) - Vendor: TJ Holowaychuk - Date: 2024-12-30 - Version: 13.0.0 - Original notes: https://www.npmjs.com/package/commander/v/13.0.0 - Permalink: https://whatsnew.fyi/product/commander/releases/13.0.0 What's New is an index, not a publisher: every entry below links to the vendor's own release notes, which are the authoritative source. Entries are labelled where they are hand-curated sample data, pre-releases, or drawn from a secondary source such as a developer blog. Reuse: the summaries, labels and curation here are © What's New. Quote freely with attribution and a link back; wholesale republication of the corpus is not permitted — terms: https://whatsnew.fyi/terms. The vendors' own release notes remain their publishers'. --- - **added** — Support multiple calls to .parse() with default settings - **added** — Add .saveStateBeforeParse() and .restoreStateBeforeParse() for use by subclasses - **added** — Add style routines like styleTitle() to add color to help using .configureHelp() or Help subclass - **added** — Add color related support in .configureOutput() for getOutHasColors(), getErrHasColors(), and stripColor() - **added** — Add Help property for minWidthToWrap - **added** — Add Help methods for displayWidth(), boxWrap(), preformatted() et al - **changed** — Excess command-arguments cause an error by default - **changed** — Throw during Option construction for unsupported option flags, like multiple characters after single - - **changed** — Throw on multiple calls to .parse() if storeOptionsAsProperties: true - **changed** — Include implicit this in parameters for action handler callback in TypeScript - **removed** — Refactored Help.wrap() into formatItem() and boxWrap() ###### Added - support multiple calls to `.parse()` with default settings ([#2299]) - add `.saveStateBeforeParse()` and `.restoreStateBeforeParse()` for use by subclasses ([#2299]) - style routines like `styleTitle()` to add color to help using `.configureHelp()` or Help subclass ([#2251]) - color related support in `.configureOutput()` for `getOutHasColors()`, `getErrHasColors()`, and `stripColor()` ([#2251]) - Help property for `minWidthToWrap` ([#2251]) - Help methods for `displayWidth()`, `boxWrap()`, `preformatted()` et al ([#2251]) ###### Changed - *Breaking*: excess command-arguments cause an error by default, see migration tips ([#2223]) - *Breaking*: throw during Option construction for unsupported option flags, like multiple characters after single `-` ([#2270]) - note: support for dual long option flags added in Commander 13.1 - *Breaking*: throw on multiple calls to `.parse()` if `storeOptionsAsProperties: true` ([#2299]) - TypeScript: include implicit `this` in parameters for action handler callback ([#2197]) ###### Deleted - *Breaking*: `Help.wrap()` refactored into `formatItem()` and `boxWrap()` ([#2251]) ###### Migration Tips **Excess command-arguments** It is now an error for the user to specify more command-arguments than are expected. (`allowExcessArguments` is now false by default.) Old code: ```js program.option('-p, --port ', 'port number'); program.action((options) => { console.log(program.args); }); ``` Now shows an error: ```console $ node example.js a b c error: too many arguments. Expected 0 arguments but got 3. ``` You can declare the expected arguments. The help will then be more accurate too. Note that declaring new arguments will change what is passed to the action handler. ```js program.option('-p, --port ', 'port number'); program.argument('[args...]', 'remote command and arguments'); // expecting zero or more arguments program.action((args, options) => { console.log(args); }); ``` Or you could suppress the error, useful for minimising changes in legacy code. ```js program.option('-p, --port', 'port number'); program.allowExcessArguments(); program.action((options) => { console.log(program.args); }); ``` **Stricter option flag parsing** Commander now throws an error for option flag combinations that are not supported. In particular, a short flag with multiple characters is now an error. ```js program.option('-ws, --workspace'); // throws error ``` A short option has a single character: ```js program.option('-w, --workspace'); ``` Or from Commander 13.1 you can have an extra long flag instead of a short flag to allow a more memorable shortcut for the full name: ```js program.option('--ws, --workspace'); ```