Skip to content

Commit 72e6f7a

Browse files
committed
Merge branch 'develop' into release/12.x
2 parents 5aaca0d + 03dea00 commit 72e6f7a

15 files changed

+110
-58
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const javascriptSettings = {
1616
const typescriptSettings = {
1717
files: ['*.ts', '*.mts'],
1818
parserOptions: {
19-
project: './tsconfig.json'
19+
project: './tsconfig.ts.json'
2020
},
2121
plugins: [
2222
'@typescript-eslint'

Readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ add cheese type mozzarella
327327
Options with an optional option-argument are not greedy and will ignore arguments starting with a dash.
328328
So `id` behaves as a boolean option for `--id -5`, but you can use a combined form if needed like `--id=-5`.
329329

330-
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
330+
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).
331331

332332
### Required option
333333

@@ -379,7 +379,7 @@ Options: { number: [ '1', '2', '3' ], letter: true }
379379
Remaining arguments: [ 'operand' ]
380380
```
381381

382-
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
382+
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).
383383

384384
### Version option
385385

@@ -1131,7 +1131,7 @@ program
11311131
There is more information available about:
11321132

11331133
- [deprecated](./docs/deprecated.md) features still supported for backwards compatibility
1134-
- [options taking varying arguments](./docs/options-taking-varying-arguments.md)
1134+
- [options taking varying arguments](./docs/options-in-depth.md)
11351135
- [parsing life cycle and hooks](./docs/parsing-and-hooks.md)
11361136

11371137
## Support

docs/options-taking-varying-arguments.md renamed to docs/options-in-depth.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Options taking varying numbers of option-arguments
1+
<!-- omit from toc -->
2+
# Options in Depth
23

34
The README covers declaring and using options, and mostly parsing will work the way you and your users expect. This page covers some special cases
45
and subtle issues in depth.
@@ -8,8 +9,10 @@ and subtle issues in depth.
89
- [Alternative: Make `--` part of your syntax](#alternative-make-----part-of-your-syntax)
910
- [Alternative: Put options last](#alternative-put-options-last)
1011
- [Alternative: Use options instead of command-arguments](#alternative-use-options-instead-of-command-arguments)
11-
- [Combining short options, and options taking arguments](#combining-short-options-and-options-taking-arguments)
12-
- [Combining short options as if boolean](#combining-short-options-as-if-boolean)
12+
- [Combining short options, and options taking arguments](#combining-short-options-and-options-taking-arguments)
13+
- [Combining short options as if boolean](#combining-short-options-as-if-boolean)
14+
15+
## Options taking varying numbers of option-arguments
1316

1417
Certain options take a varying number of arguments:
1518

@@ -20,11 +23,11 @@ program
2023
.option('--test [name...]') // 0 or more
2124
```
2225

23-
This page uses examples with options taking 0 or 1 arguments, but the discussions also apply to variadic options taking more arguments.
26+
This section uses examples with options taking 0 or 1 arguments, but the discussions also apply to variadic options taking more arguments.
2427

2528
For information about terms used in this document see: [terminology](./terminology.md)
2629

27-
## Parsing ambiguity
30+
### Parsing ambiguity
2831

2932
There is a potential downside to be aware of. If a command has both
3033
command-arguments and options with varying option-arguments, this introduces a parsing ambiguity which may affect the user of your program.
@@ -73,7 +76,7 @@ ingredient: cheese
7376

7477
If you want to avoid your users needing to learn when to use `--`, there are a few approaches you could take.
7578

76-
### Alternative: Make `--` part of your syntax
79+
#### Alternative: Make `--` part of your syntax
7780

7881
Rather than trying to teach your users what `--` does, you could just make it part of your syntax.
7982

@@ -98,7 +101,7 @@ technique: scrambled
98101
ingredient: cheese
99102
```
100103

101-
### Alternative: Put options last
104+
#### Alternative: Put options last
102105

103106
Commander follows the GNU convention for parsing and allows options before or after the command-arguments, or intermingled.
104107
So by putting the options last, the command-arguments do not get confused with the option-arguments.
@@ -120,7 +123,7 @@ technique: scrambled
120123
ingredient: cheese
121124
```
122125

123-
### Alternative: Use options instead of command-arguments
126+
#### Alternative: Use options instead of command-arguments
124127

125128
This is a bit more radical, but completely avoids the parsing ambiguity!
126129

@@ -178,7 +181,7 @@ halal servings: v
178181

179182
If you wish to use options taking varying arguments as boolean options, you need to specify them separately.
180183

181-
```
184+
```console
182185
$ collect -a -v -l
183186
any servings: true
184187
vegan servings: true
@@ -190,7 +193,7 @@ halal servings: true
190193
Before Commander v5, combining a short option and the value was not supported, and combined short flags were always expanded.
191194
So `-avl` expanded to `-a -v -l`.
192195

193-
If you want backwards compatible behaviour, or prefer combining short options as booleans to combining short option and value,
196+
If you want backwards compatible behaviour, or prefer combining short options as booleans to combining short option and value,
194197
you may change the behavior.
195198

196199
To modify the parsing of options taking an optional value:

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const { CommanderError, InvalidArgumentError } = require('./lib/error.js');
44
const { Help } = require('./lib/help.js');
55
const { Option } = require('./lib/option.js');
66

7-
// @ts-check
8-
97
exports.program = new Command();
108

119
exports.createCommand = (name) => new Command(name);

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const config = {
22
testEnvironment: 'node',
33
collectCoverage: true,
44
transform: {
5-
'^.+\\.tsx?$': 'ts-jest'
5+
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.ts.json' }]
66
},
77
testPathIgnorePatterns: [
88
'/node_modules/'

lib/argument.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const { InvalidArgumentError } = require('./error.js');
22

3-
// @ts-check
4-
53
class Argument {
64
/**
75
* Initialize a new command argument with the given name and description.

lib/command.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const { Help } = require('./help.js');
1010
const { Option, splitOptionFlags, DualOptions } = require('./option.js');
1111
const { suggestSimilar } = require('./suggestSimilar');
1212

13-
// @ts-check
14-
1513
class Command extends EventEmitter {
1614
/**
1715
* Initialize a new `Command`.
@@ -763,9 +761,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
763761
if (this.options.length) {
764762
throw new Error('call .storeOptionsAsProperties() before adding options');
765763
}
766-
if (Object.keys(this._optionValues).length) {
767-
throw new Error('call .storeOptionsAsProperties() before setting option values');
768-
}
764+
// if (Object.keys(this._optionValues).length) {
765+
// throw new Error('call .storeOptionsAsProperties() before setting option values');
766+
// }
769767
this._storeOptionsAsProperties = !!storeAsProperties;
770768
return this;
771769
}

lib/error.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
31
/**
42
* CommanderError class
53
* @class

lib/help.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const { humanReadableArgName } = require('./argument.js');
88
* @typedef { import("./option.js").Option } Option
99
*/
1010

11-
// @ts-check
12-
1311
// Although this is a class, methods are static in style to allow override using subclass or just functions.
1412
class Help {
1513
constructor() {

lib/option.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const { InvalidArgumentError } = require('./error.js');
22

3-
// @ts-check
4-
53
class Option {
64
/**
75
* Initialize a new `Option` with the given `flags` and `description`.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"lint": "npm run lint:javascript && npm run lint:typescript",
2323
"lint:javascript": "eslint index.js esm.mjs \"lib/*.js\" \"tests/**/*.js\"",
2424
"lint:typescript": "eslint typings/*.ts tests/*.ts",
25-
"test": "jest && npm run test-typings",
25+
"test": "jest && npm run typecheck-ts",
2626
"test-esm": "node ./tests/esm-imports-test.mjs",
27-
"test-typings": "tsd",
28-
"typescript-checkJS": "tsc --allowJS --checkJS index.js lib/*.js --noEmit",
29-
"test-all": "npm run test && npm run lint && npm run typescript-checkJS && npm run test-esm"
27+
"typecheck-ts": "tsd && tsc -p tsconfig.ts.json",
28+
"typecheck-js": "tsc -p tsconfig.js.json",
29+
"test-all": "npm run test && npm run lint && npm run typecheck-js && npm run test-esm"
3030
},
3131
"files": [
3232
"index.js",

tests/commander.configureCommand.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ test('when storeOptionsAsProperties() after adding option then throw', () => {
8585
}).toThrow();
8686
});
8787

88-
test('when storeOptionsAsProperties() after setting option value then throw', () => {
89-
const program = new commander.Command();
90-
program.setOptionValue('foo', 'bar');
91-
expect(() => {
92-
program.storeOptionsAsProperties();
93-
}).toThrow();
94-
});
88+
// test('when storeOptionsAsProperties() after setting option value then throw', () => {
89+
// const program = new commander.Command();
90+
// program.setOptionValue('foo', 'bar');
91+
// expect(() => {
92+
// program.storeOptionsAsProperties();
93+
// }).toThrow();
94+
// });

tsconfig.js.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ /*
2+
Simple override including just JavaScript files.
3+
Used by npm run-script typecheck-js
4+
*/
5+
/* Visit https://aka.ms/tsconfig to read more about tsconfig configuration. */
6+
"extends": "./tsconfig.json",
7+
"include": [
8+
/* All JavaScript targets from tsconfig.json include. */
9+
"*.js",
10+
"*.mjs",
11+
"lib/**/*.js"
12+
],
13+
}

tsconfig.json

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
11
{
2-
"compilerOptions": {
3-
"module": "commonjs",
4-
"lib": [
5-
"es6"
6-
],
7-
"noImplicitAny": true,
8-
"noImplicitThis": true,
9-
"strictNullChecks": true,
10-
"types": [
11-
"node",
12-
"jest"
13-
],
14-
"esModuleInterop": true, // Mainly so can test an import problem which only occurs with this option on!
15-
"noEmit": true,
16-
"forceConsistentCasingInFileNames": true
17-
},
18-
"include": ["**/*.ts"],
2+
/*
3+
TypeScript is being used to do type checking across both JavaScript and TypeScript files.
4+
In particular, this picks up some problems in the JSDoc in the JavaScript files, and validates the code
5+
is consistent with the JSDoc.
6+
7+
The settings here are used by VSCode.
8+
9+
See also tsconfig.js.json and tsconfig.ts.json.
10+
*/
11+
/* Visit https://aka.ms/tsconfig to read more about tsconfig configuration. */
12+
"compilerOptions": {
13+
"lib": ["es2021"],
14+
"module": "node16",
15+
"target": "es2021",
16+
17+
"allowJs": true,
18+
"checkJs": true,
19+
20+
/* Strict by default, but dial it down to reduce churn in our JavaScript code. */
21+
"strict": true,
22+
"noImplicitAny": false,
23+
"strictNullChecks": false,
24+
"useUnknownInCatchVariables": false,
25+
26+
"types": [
27+
"node",
28+
"jest"
29+
],
30+
"noEmit": true, /* just type checking and not emitting transpiled files */
31+
"skipLibCheck": false, /* we want to check our hand crafted definitions */
32+
"forceConsistentCasingInFileNames": true,
33+
"esModuleInterop": true /* common TypeScript config */
34+
},
35+
"include": [
36+
/* JavaScript. Should match includes in tsconfig.js.json. */
37+
"*.js",
38+
"*.mjs",
39+
"lib/**/*.js",
40+
/* TypeScript. Should match includes in tsconfig.ts.json. */
41+
"**/*.ts",
42+
"**/*.mts"
43+
],
44+
"exclude": [
45+
"node_modules"
46+
]
1947
}

tsconfig.ts.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ /*
2+
Override to include just TypeScript files and use stricter settings than we do with JavaScript.
3+
Used by:
4+
- npm run-script typecheck-ts
5+
- eslint
6+
*/
7+
/* Visit https://aka.ms/tsconfig to read more about tsconfig configuration. */
8+
"extends": "./tsconfig.json",
9+
"compilerOptions": {
10+
/* Full strict is fine for the TypeScript files, so turn back on the checks we turned off for mixed-use. */
11+
"noImplicitAny": true,
12+
"strictNullChecks": true,
13+
"useUnknownInCatchVariables": true,
14+
},
15+
"include": [
16+
/* All TypeScript targets from tsconfig.json include. */
17+
"**/*.ts",
18+
"**/*.mts"
19+
],
20+
}

0 commit comments

Comments
 (0)