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: v9.2.0
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: v9.3.0
Choose a head ref
  • 12 commits
  • 24 files changed
  • 7 contributors

Commits on Apr 18, 2022

  1. Copy the full SHA
    acbbe18 View commit details

Commits on Apr 19, 2022

  1. Rework example to avoid graphql warnings (#1719)

    * Rework example to avoid graphql warnings
    
    * Fix help text
    shadowspawn authored Apr 19, 2022
    Copy the full SHA
    a80b984 View commit details

Commits on Apr 21, 2022

  1. ci: add nodejs18 as it is released

    Drop nodejs17 as it will be eol soon.
    abetomo committed Apr 21, 2022
    Copy the full SHA
    06cf751 View commit details

Commits on May 9, 2022

  1. Add string[] to options defaultValue type (#1721)

    Add string[] to Command.option() defaultValue type.
    
    
    Co-authored-by: Caleb ツ Everett <calebev@amazon.com>
    everett1992 and Caleb ツ Everett authored May 9, 2022
    Copy the full SHA
    1b492d9 View commit details

Commits on May 11, 2022

  1. Copy the full SHA
    d660967 View commit details

Commits on May 18, 2022

  1. Add optional summary for short form of subcommand description. (#1726)

    For backwards compatibility, the description is used for the subcommand listing if the summary is missing. So by default there is no change in existing programs.
    shadowspawn authored May 18, 2022
    Copy the full SHA
    cc2db5b View commit details

Commits on May 19, 2022

  1. Copy the full SHA
    b2842dc View commit details

Commits on May 21, 2022

  1. chore: Set permissions for GitHub actions

     Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.
    
    - Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
    
    https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
    
    https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
    
    [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)
    
    Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
    neilnaveen authored and abetomo committed May 21, 2022
    Copy the full SHA
    4094e22 View commit details

Commits on May 22, 2022

  1. Copy the full SHA
    1bab84c View commit details

Commits on May 23, 2022

  1. Copy the full SHA
    3103c6b View commit details

Commits on May 27, 2022

  1. chore: Included githubactions in the dependabot config

    This should help with keeping the GitHub actions updated on new releases. This will also help with keeping it secure.
    
    Dependabot helps in keeping the supply chain secure https://docs.github.com/en/code-security/dependabot
    
    GitHub actions up to date https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
    
    https://github.com/ossf/scorecard/blob/main/docs/checks.md#dependency-update-tool
    Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com>
    naveensrinivasan authored and abetomo committed May 27, 2022
    Copy the full SHA
    e89eca8 View commit details

Commits on May 28, 2022

  1. Prepare for 9.3.0

    shadowspawn authored and abetomo committed May 28, 2022
    Copy the full SHA
    f2aec26 View commit details
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -2,14 +2,17 @@ name: build

on: [push, pull_request]

permissions:
contents: read

jobs:
test:
name: Test on node ${{ matrix.node-version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x, 17.x]
node-version: [12.x, 14.x, 16.x, 18.x]
os: [ubuntu-latest, windows-latest, macos-latest]

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

## [9.3.0] (2022-05-28)

### Added

- `.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])
- updated Chinese README with 9.x changes ([#1727])

### Fixed

- TypeScript: add `string[]` to `.options()` default value parameter type for use with variadic options ([#1721])

### Deprecated

- multi-character short option flag (e.g. `-ws`) ([#1718])

## [9.2.0] (2022-04-15)

### Added
@@ -1057,6 +1073,11 @@ program
[#1706]: https://github.com/tj/commander.js/pull/1706
[#1708]: https://github.com/tj/commander.js/pull/1708
[#1710]: https://github.com/tj/commander.js/pull/1710
[#1718]: https://github.com/tj/commander.js/pull/1718
[#1721]: https://github.com/tj/commander.js/pull/1721
[#1724]: https://github.com/tj/commander.js/pull/1724
[#1726]: https://github.com/tj/commander.js/pull/1726
[#1727]: https://github.com/tj/commander.js/pull/1727

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

[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
[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
[9.1.0]: https://github.com/tj/commander.js/compare/v9.0.0...v9.1.0
[9.0.0]: https://github.com/tj/commander.js/compare/v8.3.0...v9.0.0
68 changes: 43 additions & 25 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
- [Display help from code](#display-help-from-code)
- [.name](#name)
- [.usage](#usage)
- [.description and .summary](#description-and-summary)
- [.helpOption(flags, description)](#helpoptionflags-description)
- [.addHelpCommand()](#addhelpcommand)
- [More configuration](#more-configuration-2)
@@ -57,7 +58,7 @@ For information about terms used in this document see: [terminology](./docs/term

## Installation

```bash
```sh
npm install commander
```

@@ -86,7 +87,7 @@ const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
```

```sh
```console
$ node split.js -s / --fits a/b/c
error: unknown option '--fits'
(Did you mean --first?)
@@ -120,7 +121,7 @@ program.command('split')
program.parse();
```

```sh
```console
$ node string-util.js help split
Usage: string-util split [options] <string>

@@ -180,7 +181,7 @@ Multi-word options such as "--template-engine" are camel-cased, becoming `progra

An option and its option-argument can be separated by a space, or combined into the same argument. The option-argument can follow the short option directly or follow an `=` for a long option.

```bash
```sh
serve -p 80
serve -p80
serve --port 80
@@ -219,7 +220,7 @@ if (options.small) console.log('- small pizza size');
if (options.pizzaType) console.log(`- ${options.pizzaType}`);
```

```bash
```console
$ pizza-options -p
error: option '-p, --pizza-type <type>' argument missing
$ pizza-options -d -s -p vegetarian
@@ -255,7 +256,7 @@ program.parse();
console.log(`cheese: ${program.opts().cheese}`);
```

```bash
```console
$ pizza-options
cheese: blue
$ pizza-options --cheese stilton
@@ -285,7 +286,7 @@ const cheeseStr = (options.cheese === false) ? 'no cheese' : `${options.cheese}
console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
```

```bash
```console
$ pizza-options
You ordered a pizza with sauce and mozzarella cheese
$ pizza-options --sauce
@@ -313,7 +314,7 @@ else if (options.cheese === true) console.log('add cheese');
else console.log(`add cheese type ${options.cheese}`);
```

```bash
```console
$ pizza-options
no cheese
$ pizza-options --cheese
@@ -340,7 +341,7 @@ program
program.parse();
```

```bash
```console
$ pizza
error: required option '-c, --cheese <type>' not specified
```
@@ -365,7 +366,7 @@ console.log('Options: ', program.opts());
console.log('Remaining arguments: ', program.args);
```

```bash
```console
$ collect -n 1 2 3 --letter a b c
Options: { number: [ '1', '2', '3' ], letter: [ 'a', 'b', 'c' ] }
Remaining arguments: []
@@ -387,7 +388,7 @@ The optional `version` method adds handling for displaying the command version.
program.version('0.0.1');
```

```bash
```console
$ ./examples/pizza -V
0.0.1
```
@@ -404,7 +405,7 @@ program.version('0.0.1', '-v, --vers', 'output the current version');
You can add most options using the `.option()` method, but there are some additional features available
by constructing an `Option` explicitly for less common cases.

Example files: [options-extra.js](./examples/options-extra.js), [options-env.js](./examples/options-env.js), [options-conflicts.js](./examples/options-conflicts.js)
Example files: [options-extra.js](./examples/options-extra.js), [options-env.js](./examples/options-env.js), [options-conflicts.js](./examples/options-conflicts.js), [options-implies.js](./examples/options-implies.js)

```js
program
@@ -413,26 +414,28 @@ program
.addOption(new Option('-d, --drink <size>', 'drink size').choices(['small', 'medium', 'large']))
.addOption(new Option('-p, --port <number>', 'port number').env('PORT'))
.addOption(new Option('--donate [amount]', 'optional donation in dollars').preset('20').argParser(parseFloat))
.addOption(new Option('--disable-server', 'disables the server').conflicts('port'));
.addOption(new Option('--disable-server', 'disables the server').conflicts('port'))
.addOption(new Option('--free-drink', 'small drink included free ').implies({ drink: 'small' }));
```

```bash
```console
$ extra --help
Usage: help [options]

Options:
-t, --timeout <delay> timeout in seconds (default: one minute)
-d, --drink <size> drink cup size (choices: "small", "medium", "large")
-p, --port <number> port number (env: PORT)
--donate [amount] optional donation in dollars (preset: 20)
--donate [amount] optional donation in dollars (preset: "20")
--disable-server disables the server
--free-drink small drink included free
-h, --help display help for command

$ extra --drink huge
error: option '-d, --drink <size>' argument 'huge' is invalid. Allowed choices are small, medium, large.

$ PORT=80 extra --donate
Options: { timeout: 60, donate: 20, port: '80' }
$ PORT=80 extra --donate --free-drink
Options: { timeout: 60, donate: 20, port: '80', freeDrink: true, drink: 'small' }

$ extra --disable-server --port 8000
error: option '--disable-server' cannot be used with option '-p, --port <number>'
@@ -489,7 +492,7 @@ if (options.collect.length > 0) console.log(options.collect);
if (options.list !== undefined) console.log(options.list);
```

```bash
```console
$ custom -f 1e2
float: 100
$ custom --integer 2
@@ -728,7 +731,7 @@ help option is `-h,--help`.

Example file: [pizza](./examples/pizza)

```bash
```console
$ node ./examples/pizza --help
Usage: pizza [options]

@@ -744,7 +747,7 @@ Options:
A `help` command is added by default if your command has subcommands. It can be used alone, or with a subcommand name to show
further help for the subcommand. These are effectively the same if the `shell` program has implicit help:

```bash
```sh
shell help
shell --help

@@ -806,19 +809,20 @@ program.showHelpAfterError();
program.showHelpAfterError('(add --help for additional information)');
```

```sh
```console
$ pizza --unknown
error: unknown option '--unknown'
(add --help for additional information)
```

You can also show suggestions after an error for an unknown command or option.
The default behaviour is to suggest correct spelling after an error for an unknown command or option. You
can disable this.

```js
program.showSuggestionAfterError();
program.showSuggestionAfterError(false);
```

```sh
```console
$ pizza --hepl
error: unknown option '--hepl'
(Did you mean --help?)
@@ -864,6 +868,20 @@ The help will start with:
Usage: my-command [global options] command
```

### .description and .summary

The description appears in the help for the command. You can optionally supply a shorter
summary to use when listed as a subcommand of the program.

```js
program
.command("duplicate")
.summary("make a copy")
.description(`Make a copy of the current project.
This may require additional disk space.
`);
```

### .helpOption(flags, description)

By default every command has a help option. You may change the default help flags and description. Pass false to disable the built-in help option.
@@ -991,7 +1009,7 @@ program

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.

```bash
```sh
node -r ts-node/register pm.ts
```

Loading