Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tj/commander.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 82fcb98cc27164a98e0c5f2c6f54621b5bbceef9
Choose a base ref
...
head repository: tj/commander.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4ef19faac1564743d8c7e3ce89ef8d190e1551b4
Choose a head ref

Commits on Sep 6, 2022

  1. setOptionValue should clear option source (#1795)

    * Have setOptionValue call setOptionValueWithSource instead of the other way around
    
    * Add explicit undefined to pass  tests
    shadowspawn authored Sep 6, 2022
    Copy the full SHA
    84d9201 View commit details
  2. Add implied to option value sources (#1794)

    * TypeScript: add implied to OptionValueSource
    
    * Add implied to JSDoc and TSDoc. Mention config in env priority.
    
    * TypeScript: add undefined to return type of getOptionValueSource
    
    * Reword env description so not  priority ordering as such. More accurately describe behaviour.
    shadowspawn authored Sep 6, 2022
    Copy the full SHA
    72be61c View commit details

Commits on Sep 8, 2022

  1. Copy the full SHA
    8236966 View commit details
  2. Add copyInheritedSettings to README (#1798)

    * Add copyInheritedSettings to README
    
    * Add line break.
    shadowspawn authored Sep 8, 2022
    Copy the full SHA
    471ec40 View commit details

Commits on Sep 30, 2022

  1. Update CHANGELOG for 9.4.1

    shadowspawn authored and abetomo committed Sep 30, 2022
    Copy the full SHA
    c15ae68 View commit details
  2. 9.4.1

    abetomo committed Sep 30, 2022
    Copy the full SHA
    0b4198d View commit details

Commits on Oct 1, 2022

  1. Wrap command description in help (#1804)

    * Wrap command description. Replace trimRight by trimEnd.
    
    * Preserve empty lines when wrapping
    
    * Simplify line end handling
    
    * Translate Windows line endings to keep things sane
    shadowspawn authored Oct 1, 2022
    Copy the full SHA
    186f0c8 View commit details

Commits on Oct 6, 2022

  1. Copy the full SHA
    ef88d70 View commit details

Commits on Oct 31, 2022

  1. Add extra-typings to README (#1814)

    * Add mention of extra-typings
    
    * Reword
    shadowspawn authored Oct 31, 2022
    Copy the full SHA
    1760b42 View commit details

Commits on Nov 7, 2022

  1. Copy the full SHA
    c897329 View commit details

Commits on Nov 17, 2022

  1. Fix some typos (#1821)

    striezel authored Nov 17, 2022
    Copy the full SHA
    8d3c7b5 View commit details

Commits on Nov 25, 2022

  1. Copy the full SHA
    198c6e4 View commit details

Commits on Nov 27, 2022

  1. Copy the full SHA
    f3880f7 View commit details

Commits on Nov 29, 2022

  1. Copy the full SHA
    e0f6173 View commit details
  2. Add Command.options to TypeScript (#1827)

    Make options and commands readonly to discourage direct manipulation.
    
    
    Co-authored-by: Cynthia <cynthia@cynthia.dev>
    Co-authored-by: Marcelo Shima <marceloshima@gmail.com>
    Co-authored-by: Dmitry Maganov <vonagam@gmail.com>
    4 people authored Nov 29, 2022
    Copy the full SHA
    04fc0fd View commit details

Commits on Dec 7, 2022

  1. Support showing global options in help (#1828)

    Add help configuration to show the global options.
    shadowspawn authored Dec 7, 2022
    Copy the full SHA
    0ae5b2f View commit details

Commits on Dec 19, 2022

  1. Copy the full SHA
    5a201ec View commit details
  2. Copy the full SHA
    91bfa8d View commit details

Commits on Dec 27, 2022

  1. *: update dev deps and make tweaks

    - Update the developer dependencies to their latest versions.
    - Remove usage of the `--experimental-modules` CLI flag as it's a no-op now.
    - Change the typings file to make the linters happy.
    VoltrexKeyva authored and abetomo committed Dec 27, 2022
    Copy the full SHA
    5f3f004 View commit details

Commits on Jan 5, 2023

  1. Copy the full SHA
    2326c53 View commit details

Commits on Jan 7, 2023

  1. Update CHANGELOG for 9.5.0

    Including some lint
    shadowspawn authored and abetomo committed Jan 7, 2023
    Copy the full SHA
    f6dd14a View commit details
  2. Fix year for release

    shadowspawn authored and abetomo committed Jan 7, 2023
    Copy the full SHA
    e6d85fc View commit details
  3. 9.5.0

    abetomo committed Jan 7, 2023
    1
    Copy the full SHA
    7a5bd06 View commit details

Commits on Jan 9, 2023

  1. Copy the full SHA
    2bdd631 View commit details

Commits on Jan 14, 2023

  1. Update CHANGELOG (#1840)

    shadowspawn authored Jan 14, 2023
    Copy the full SHA
    d0dac4c View commit details
  2. 10.0.0

    shadowspawn committed Jan 14, 2023
    Copy the full SHA
    8b03ab7 View commit details

Commits on Jan 22, 2023

  1. Copy the full SHA
    869c3c0 View commit details

Commits on Mar 15, 2023

  1. Copy the full SHA
    f4c7349 View commit details

Commits on Mar 29, 2023

  1. Copy the full SHA
    ee78d95 View commit details

Commits on Apr 7, 2023

  1. Describe help description wrapping

    shadowspawn authored and abetomo committed Apr 7, 2023
    Copy the full SHA
    1aa5271 View commit details
  2. Add parsing life cycle and hooks

    shadowspawn authored and abetomo committed Apr 7, 2023
    Copy the full SHA
    28928ed View commit details
  3. Add new documentation to README

    shadowspawn authored and abetomo committed Apr 7, 2023
    1
    Copy the full SHA
    5fbf83a View commit details
  4. Could be multiple hooks, pluralise

    shadowspawn authored and abetomo committed Apr 7, 2023
    Copy the full SHA
    321cd76 View commit details

Commits on Apr 15, 2023

  1. Copy the full SHA
    33195f1 View commit details

Commits on Apr 19, 2023

  1. ci: add 20.x to node-version

    abetomo committed Apr 19, 2023
    1
    Copy the full SHA
    fac9d8c View commit details

Commits on Apr 21, 2023

  1. Copy the full SHA
    63abdac View commit details

Commits on Apr 30, 2023

  1. 1
    Copy the full SHA
    60958df View commit details

Commits on May 4, 2023

  1. trim() input string of .arguments method

    Felarn authored and abetomo committed May 4, 2023
    1
    Copy the full SHA
    2f07c2a View commit details

Commits on May 14, 2023

  1. Copy the full SHA
    ffc7897 View commit details
  2. 2
    Copy the full SHA
    a4c96e6 View commit details

Commits on Jun 16, 2023

  1. Update to minimum of node 16

    - update dependencies
    - fresh package-lock.json
    shadowspawn authored and abetomo committed Jun 16, 2023
    1
    Copy the full SHA
    76d3d11 View commit details
  2. Lint fixes for latest rules

    shadowspawn authored and abetomo committed Jun 16, 2023
    Copy the full SHA
    752900d View commit details
  3. Update CHANGELOG for 11.0.0

    shadowspawn authored and abetomo committed Jun 16, 2023
    Copy the full SHA
    1b8e82d View commit details
  4. Adjust date

    shadowspawn authored and abetomo committed Jun 16, 2023
    1
    Copy the full SHA
    1be6dfa View commit details
  5. Bump version

    shadowspawn authored and abetomo committed Jun 16, 2023
    1
    Copy the full SHA
    4ef19fa View commit details
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ const javascriptSettings = {
};

const typescriptSettings = {
files: ['*.ts'],
files: ['*.ts', '*.mts'],
parserOptions: {
project: './tsconfig.json'
},
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
90 changes: 82 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,61 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
<!-- markdownlint-disable MD024 -->
<!-- markdownlint-disable MD004 -->

## [11.0.0] (2023-06-16)

### Fixed

- help command works when help option is disabled ([#1864])

### Changed

- leading and trailing spaces are now ignored by the .arguments() method ([#1874])
- refine "types" exports for ESM to follow TypeScript guidelines ([#1886])
- *Breaking:* Commander 11 requires Node.js v16 or higher

## [10.0.1] (2023-04-15)

### Added

- improvements to documentation ([#1858], [#1859], [#1860])

### Fixed

- remove unused `Option.optionFlags` property from TypeScript definition ([#1844])

### Changed

- assume boolean option intended if caller passes string instead of hash to `.implies()` ([#1854])

## [10.0.0] (2023-01-13)

### Added

- wrap command description in help ([#1804])

### Changed

- *Breaking:* Commander 10 requires Node.js v14 or higher

## [9.5.0] (2023-01-07)

### Added

- `.getOptionValueSourceWithGlobals()` ([#1832])
- `showGlobalOptions` for `.configureHelp{}` and `Help` ([#1828])

## [9.4.1] (2022-09-30)

### Fixed

- `.setOptionValue()` now also clears option source ([#1795])
- TypeScript: add `implied` to `OptionValueSource` for option values set by using `.implies()` ([#1794])
- TypeScript : add `undefined` to return type of `.getOptionValueSource()` ([#1794])

### Changed

- additions to README

## [9.4.0] (2022-07-15)

### Added
@@ -81,8 +136,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- use command name as prefix for subcommand stand-alone executable name (with fallback to script name for backwards compatibility) ([#1571])
- allow absolute path with `executableFile` ([#1571])
- removed restriction that nested subcommands must specify `executableFile` ([#1571])
- TypeScript: allow passing readonly string array to `.choices()` [(#1667)]
- TypeScript: allow passing readonly string array to `.parse()`, `.parseAsync()`, `.aliases()` [(#1669)]
- TypeScript: allow passing readonly string array to `.choices()` ([#1667])
- TypeScript: allow passing readonly string array to `.parse()`, `.parseAsync()`, `.aliases()` ([#1669])

### Fixed

@@ -92,7 +147,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- *Breaking:* removed internal fallback to `require.main.filename` when script not known from arguments passed to `.parse()` (can supply details using `.name()`, and `.executableDir()` or `executableFile`) ([#1571])


## [9.0.0-1] (2022-01-15)

(Released in 9.0.0)
@@ -274,8 +328,8 @@ program.showHelpAfterError();
### Changed

- *Breaking:* options are stored safely by default, not as properties on the command ([#1409])
- this especially affects accessing options on program, use `program.opts()`
- revert behaviour with `.storeOptionsAsProperties()`
- this especially affects accessing options on program, use `program.opts()`
- revert behaviour with `.storeOptionsAsProperties()`
- *Breaking:* action handlers are passed options and command separately ([#1409])
- deprecated callback parameter to `.help()` and `.outputHelp()` (removed from README) ([#1296])
- *Breaking:* errors now displayed using `process.stderr.write()` instead of `console.error()`
@@ -294,9 +348,9 @@ program.showHelpAfterError();
### Deleted

- *Breaking:* `.passCommandToAction()` ([#1409])
- no longer needed as action handler is passed options and command
- no longer needed as action handler is passed options and command
- *Breaking:* "extra arguments" parameter to action handler ([#1409])
- if being used to detect excess arguments, there is now an error available by setting `.allowExcessArguments(false)`
- if being used to detect excess arguments, there is now an error available by setting `.allowExcessArguments(false)`

### Migration Tips

@@ -381,7 +435,7 @@ program

### Fixed

- some tests failed if directory path included a space ([1390])
- some tests failed if directory path included a space ([#1390])

## [6.2.0] (2020-10-25)

@@ -1053,6 +1107,7 @@ program
[#1490]: https://github.com/tj/commander.js/pull/1490
[#1497]: https://github.com/tj/commander.js/pull/1497
[#1500]: https://github.com/tj/commander.js/pull/1500
[#1502]: https://github.com/tj/commander.js/pull/1502
[#1508]: https://github.com/tj/commander.js/pull/1508
[#1513]: https://github.com/tj/commander.js/pull/1513
[#1514]: https://github.com/tj/commander.js/pull/1514
@@ -1095,6 +1150,19 @@ program
[#1756]: https://github.com/tj/commander.js/pull/1756
[#1763]: https://github.com/tj/commander.js/pull/1763
[#1767]: https://github.com/tj/commander.js/pull/1767
[#1794]: https://github.com/tj/commander.js/pull/1794
[#1795]: https://github.com/tj/commander.js/pull/1795
[#1804]: https://github.com/tj/commander.js/pull/1804
[#1832]: https://github.com/tj/commander.js/pull/1832
[#1828]: https://github.com/tj/commander.js/pull/1828
[#1844]: https://github.com/tj/commander.js/pull/1844
[#1854]: https://github.com/tj/commander.js/pull/1854
[#1858]: https://github.com/tj/commander.js/pull/1858
[#1859]: https://github.com/tj/commander.js/pull/1859
[#1860]: https://github.com/tj/commander.js/pull/1860
[#1864]: https://github.com/tj/commander.js/pull/1864
[#1874]: https://github.com/tj/commander.js/pull/1874
[#1886]: https://github.com/tj/commander.js/pull/1886

<!-- Referenced in 5.x -->
[#1]: https://github.com/tj/commander.js/issues/1
@@ -1135,6 +1203,7 @@ program
[#1248]: https://github.com/tj/commander.js/pull/1248

<!-- Referenced in 4.x -->
[#933]: https://github.com/tj/commander.js/pull/933
[#1027]: https://github.com/tj/commander.js/pull/1027
[#1035]: https://github.com/tj/commander.js/pull/1035
[#1040]: https://github.com/tj/commander.js/pull/1040
@@ -1173,6 +1242,11 @@ program
[#1028]: https://github.com/tj/commander.js/pull/1028

[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
[11.0.0]: https://github.com/tj/commander.js/compare/v10.0.1...v11.0.0
[10.0.1]: https://github.com/tj/commander.js/compare/v10.0.0...v10.0.1
[10.0.0]: https://github.com/tj/commander.js/compare/v9.5.0...v10.0.0
[9.5.0]: https://github.com/tj/commander.js/compare/v9.4.1...v9.5.0
[9.4.1]: https://github.com/tj/commander.js/compare/v9.4.0...v9.4.1
[9.4.0]: https://github.com/tj/commander.js/compare/v9.3.0...v9.4.0
[9.3.0]: https://github.com/tj/commander.js/compare/v9.2.0...v9.3.0
[9.2.0]: https://github.com/tj/commander.js/compare/v9.1.0...v9.2.0
40 changes: 36 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
- [createCommand()](#createcommand)
- [Node options such as `--harmony`](#node-options-such-as---harmony)
- [Debugging stand-alone executable subcommands](#debugging-stand-alone-executable-subcommands)
- [npm run-script](#npm-run-script)
- [Display error](#display-error)
- [Override exit and output handling](#override-exit-and-output-handling)
- [Additional documentation](#additional-documentation)
@@ -330,7 +331,7 @@ For information about possible ambiguous cases, see [options taking varying argu

### Required option

You may specify a required (mandatory) option using `.requiredOption`. The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (say from environment). The method is otherwise the same as `.option` in format, taking flags and description, and optional default value or custom processing.
You may specify a required (mandatory) option using `.requiredOption()`. The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (say from environment). The method is otherwise the same as `.option()` in format, taking flags and description, and optional default value or custom processing.

Example file: [options-required.js](./examples/options-required.js)

@@ -441,6 +442,8 @@ $ extra --disable-server --port 8000
error: option '--disable-server' cannot be used with option '-p, --port <number>'
```

Specify a required (mandatory) option using the `Option` method `.makeOptionMandatory()`. This matches the `Command` method [.requiredOption()](#required-option).

### Custom option processing

You may specify a function to do custom processing of option-arguments. The callback function receives two parameters,
@@ -541,6 +544,10 @@ Configuration options can be passed with the call to `.command()` and `.addComma
remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other
subcommand is specified ([example](./examples/defaultCommand.js)).

You can add alternative names for a command with `.alias()`. ([example](./examples/alias.js))

For safety, `.addCommand()` does not automatically copy the inherited settings from the parent command. There is a helper routine `.copyInheritedSettings()` for copying the settings when they are wanted.

### Command-arguments

For subcommands, you can specify the argument syntax in the call to `.command()` (as shown above). This
@@ -724,6 +731,8 @@ The supported events are:
| `preAction`, `postAction` | before/after action handler for this command and its nested subcommands | `(thisCommand, actionCommand)` |
| `preSubcommand` | before parsing direct subcommand | `(thisCommand, subcommand)` |

For an overview of the life cycle events see [parsing life cycle and hooks](./docs/parsing-and-hooks.md).

## Automated help

The help information is auto-generated based on the information commander already knows about your program. The default
@@ -755,6 +764,8 @@ shell help spawn
shell spawn --help
```

Long descriptions are wrapped to fit the available width. (However, a description that includes a line-break followed by whitespace is assumed to be pre-formatted and not wrapped.)

### Custom help

You can add extra text to be displayed along with the built-in help.
@@ -911,8 +922,9 @@ The data properties are:
- `helpWidth`: specify the wrap width, useful for unit tests
- `sortSubcommands`: sort the subcommands alphabetically
- `sortOptions`: sort the options alphabetically
- `showGlobalOptions`: show a section with the global options from the parent command(s)

There are methods getting the visible lists of arguments, options, and subcommands. There are methods for formatting the items in the lists, with each item having a _term_ and _description_. Take a look at `.formatHelp()` to see how they are used.
You can override any method on the [Help](./lib/help.js) class. There are methods getting the visible lists of arguments, options, and subcommands. There are methods for formatting the items in the lists, with each item having a _term_ and _description_. Take a look at `.formatHelp()` to see how they are used.

Example file: [configure-help.js](./examples/configure-help.js)

@@ -1007,7 +1019,15 @@ program

### TypeScript

If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g.
extra-typings: There is an optional project to infer extra type information from the option and argument definitions.
This adds strong typing to the options returned by `.opts()` and the parameters to `.action()`.
See [commander-js/extra-typings](https://github.com/commander-js/extra-typings) for more.

```
import { Command } from '@commander-js/extra-typings';
```

ts-node: If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g.

```sh
node -r ts-node/register pm.ts
@@ -1042,6 +1062,17 @@ the inspector port is incremented by 1 for the spawned subcommand.

If you are using VSCode to debug executable subcommands you need to set the `"autoAttachChildProcesses": true` flag in your launch.json configuration.

### npm run-script

By default when you call your program using run-script, `npm` will parse any options on the command-line and they will not reach your program. Use
`--` to stop the npm option parsing and pass through all the arguments.

The synopsis for [npm run-script](https://docs.npmjs.com/cli/v9/commands/npm-run-script) explicitly shows the `--` for this reason:

```console
npm run-script <command> [-- <args>]
```

### Display error

This routine is available to invoke the Commander error handling for your own error conditions. (See also the next section about exit handling.)
@@ -1099,10 +1130,11 @@ There is more information available about:

- [deprecated](./docs/deprecated.md) features still supported for backwards compatibility
- [options taking varying arguments](./docs/options-taking-varying-arguments.md)
- [parsing life cycle and hooks](./docs/parsing-and-hooks.md)

## Support

The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v12.20.0.
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v16.
(For older versions of Node.js, use an older version of Commander.)

The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
2 changes: 1 addition & 1 deletion Readme_zh-CN.md
Original file line number Diff line number Diff line change
@@ -1059,7 +1059,7 @@ program
## 支持
当前版本的 Commander 在 LTS 版本的 Node.js 上完全支持。并且至少需要 v12.20.0
当前版本的 Commander 在 LTS 版本的 Node.js 上完全支持。并且至少需要 v16
(使用更低版本 Node.js 的用户建议安装更低版本的 Commander)
社区支持请访问项目的 [Issues](https://github.com/tj/commander.js/issues)。
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ Old versions receive security updates for six months.

| Version | Supported |
| ------- | ------------------------------------------ |
| 8.x | :white_check_mark: support ends 2022-07-31 |
| < 8 | :x: |
| 10.x | :white_check_mark: support ends 2024-01-16 |
| < 10 | :x: |

Pull Requests for security issues will be considered for older versions back to 2.x.

21 changes: 19 additions & 2 deletions docs/deprecated.md
Original file line number Diff line number Diff line change
@@ -9,11 +9,12 @@ They are currently still available for backwards compatibility, but should not b
- [Default import of global Command object](#default-import-of-global-command-object)
- [Callback to .help() and .outputHelp()](#callback-to-help-and-outputhelp)
- [.on('--help')](#on--help)
- [.on('command:*')](#oncommand)
- [.command('*')](#command)
- [.on('command:\*')](#oncommand)
- [.command('\*')](#command)
- [cmd.description(cmdDescription, argDescriptions)](#cmddescriptioncmddescription-argdescriptions)
- [InvalidOptionArgumentError](#invalidoptionargumenterror)
- [Short option flag longer than a single character](#short-option-flag-longer-than-a-single-character)
- [Import from `commander/esm.mjs`](#import-from-commanderesmmjs)

## RegExp .option() parameter

@@ -190,3 +191,19 @@ Deprecated from Commander v8.
Short option flags like `-ws` were never supported, but the old README did not make this clear. The README now states that short options are a single character.

README updated in Commander v3. Deprecated from Commander v9.

## Import from `commander/esm.mjs`

The first support for named imports required an explicit entry file.

```js
import { Command } from 'commander/esm.mjs';
```

This is no longer required, just import directly from the module.

```js
import { Command } from 'commander';
```

README updated in Commander v9. Deprecated from Commander v9.
23 changes: 23 additions & 0 deletions docs/parsing-and-hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Parsing life cycle and hooks

The processing starts with an array of args. Each command processes and removes the options it understands, and passes the remaining args to the next subcommand.
The final command calls the action handler.

Starting with top-level command (program):

- parse options: parse recognised options (for this command) and remove from args
- parse env: look for environment variables (for this command)
- process implied: set any implied option values (for this command)
- if the first arg is a subcommand
- call `preSubcommand` hooks
- pass remaining arguments to subcommand, and process same way

Once reach final (leaf) command:

- check for missing mandatory options
- check for conflicting options
- check for unknown options
- process remaining args as command-arguments
- call `preAction` hooks
- call action handler
- call `postAction` hooks
Loading