commander 7.0.0-2 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,25 +8,51 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8
8
  <!-- markdownlint-disable MD024 -->
9
9
  <!-- markdownlint-disable MD004 -->
10
10
 
11
- ## [7.0.0-2] (2020-12-14)
11
+ ## [7.0.0] (2021-01-15)
12
+
13
+ ### Added
14
+
15
+ - `.enablePositionalOptions()` to let program and subcommand reuse same option ([#1427])
16
+ - `.passThroughOptions()` to pass options through to other programs without needing `--` ([#1427])
17
+ - `.allowExcessArguments(false)` to show an error message if there are too many command-arguments on command line for the action handler ([#1409])
18
+ - `.configureOutput()` to modify use of stdout and stderr or customise display of errors ([#1387])
19
+ - use `.addHelpText()` to add text before or after the built-in help, for just current command or also for all subcommands ([#1296])
20
+ - enhance Option class ([#1331])
21
+ - allow hiding options from help
22
+ - allow restricting option arguments to a list of choices
23
+ - allow setting how default value is shown in help
24
+ - `.createOption()` to support subclassing of automatically created options (like `.createCommand()`) ([#1380])
25
+ - refactor the code generating the help into a separate public Help class ([#1365])
26
+ - support sorting subcommands and options in help
27
+ - support specifying wrap width (columns)
28
+ - allow subclassing Help class
29
+ - allow configuring Help class without subclassing
12
30
 
13
31
  ### Changed
14
32
 
15
- - *Breaking:* options are stored safely by default, not as properties on the command
33
+ - *Breaking:* options are stored safely by default, not as properties on the command ([#1409])
16
34
  - this especially affects accessing options on program, use `program.opts()`
17
35
  - revert behaviour with `.storeOptionsAsProperties()`
18
- - *Breaking:* action handlers are passed options and command separately
19
-
20
- ### Added
36
+ - *Breaking:* action handlers are passed options and command separately ([#1409])
37
+ - deprecated callback parameter to `.help()` and `.outputHelp()` (removed from README) ([#1296])
38
+ - *Breaking:* errors now displayed using `process.stderr.write()` instead of `console.error()`
39
+ - deprecate `.on('--help')` (removed from README) ([#1296])
40
+ - initialise the command description to empty string (previously undefined) ([#1365])
41
+ - document and annotate deprecated routines ([#1349])
21
42
 
22
- - *Breaking:* error message if there are too many command-arguments on command line for the action handler
23
- - if should be allowed then declare extra arguments, or use `.allowExcessArguments()`
43
+ ### Fixed
24
44
 
45
+ - wrapping bugs in help ([#1365])
46
+ - first line of command description was wrapping two characters early
47
+ - pad width calculation was not including help option and help command
48
+ - pad width calculation was including hidden options and commands
49
+ - improve backwards compatibility for custom command event listeners ([#1403])
50
+
25
51
  ### Deleted
26
52
 
27
- - *Breaking:* `.passCommandToAction()`
53
+ - *Breaking:* `.passCommandToAction()` ([#1409])
28
54
  - no longer needed as action handler is passed options and command
29
- - *Breaking:* "extra arguments" parameter to action handler
55
+ - *Breaking:* "extra arguments" parameter to action handler ([#1409])
30
56
  - if being used to detect excess arguments, there is now an error displayed by default
31
57
 
32
58
  ### Migration Tips
@@ -96,75 +122,18 @@ program
96
122
  });
97
123
  ```
98
124
 
99
- **excess command-arguments**
100
-
101
- There is now an error if there are too many command-arguments on the command line (only checked if there is an action handler).
102
- If the extra arguments are supported by your command then you can either declare the expected arguments, or allow excess arguments.
103
-
104
- ```js
105
- // Old code before Commander 7
106
- program
107
- .action(() => {});
108
- program.parse(['a', 'b', 'c'], { from: 'user' }); // now causes an error
109
- ```
110
-
111
- ```js
112
- // New code, declare arguments
113
- program
114
- .arguments('[args...]')
115
- .action(() => {});
116
- ```
125
+ ## [7.0.0-2] (2020-12-14)
117
126
 
118
- ```js
119
- // New code, allow excess arguments
120
- program
121
- .allowExcessArguments()
122
- .action(() => {});
123
- ```
127
+ (Released in 7.0.0)
124
128
 
125
129
  ## [7.0.0-1] (2020-11-21)
126
130
 
127
- ### Added
128
-
129
- - `.createOption()` to support subclassing of automatically created options (like `.createCommand()`) ([#1380])
130
- - `.configureOutput()` to modify use of stdout and stderr or customise display of errors ([#1387])
131
-
132
- ### Breaking changes relative to 7.0.0-0
133
-
134
- - rework new `Help.wrap()` for simpler usage pattern (#1395)
135
- - rename new "columns" properties (#1396)
136
- - `Help.columns` -> `helpWidth`
137
- - `getOutColumns()` -> `getOutHelpWidth()`
138
- - `getErrColumns()` -> `getErrHelpWidth()`
131
+ (Released in 7.0.0)
139
132
 
140
133
  ## [7.0.0-0] (2020-10-25)
141
134
 
142
- ### Added
143
-
144
- - use `.addHelpText()` to add text before or after the built-in help, for just current command or also for all subcommands ([#1296])
145
- - enhance Option class ([#1331])
146
- - allow hiding options from help
147
- - allow restricting option arguments to a list of choices
148
- - allow setting how default value is shown in help
149
- - refactor the code generating the help into a separate public Help class ([#1365])
150
- - support sorting subcommands and options in help
151
- - support specifying wrap width (columns)
152
- - allow subclassing Help class
153
- - allow configuring Help class without subclassing
154
-
155
- ### Fixed
156
-
157
- - wrapping bugs in help ([#1365])
158
- - first line of command description was wrapping two characters early
159
- - pad width calculation was not including help option and help command
160
- - pad width calculation was including hidden options and commands
161
-
162
- ### Changed
135
+ (Released in 7.0.0)
163
136
 
164
- - document and annotate deprecated routines ([#1349])
165
- - deprecated callback parameter to `.help()` and `.outputHelp()` (removed from README) ([#1296])
166
- - deprecate `.on('--help')` (removed from README) ([#1296])
167
- - initialise the command description to empty string (previously undefined) ([#1365])
168
137
  ## [6.2.1] (2020-12-13)
169
138
 
170
139
  ### Fixed
@@ -404,9 +373,13 @@ to expand `-fb` to `-f -b` rather than `-f b`.
404
373
  [#1380]: https://github.com/tj/commander.js/pull/1380
405
374
  [#1387]: https://github.com/tj/commander.js/pull/1387
406
375
  [#1390]: https://github.com/tj/commander.js/pull/1390
376
+ [#1403]: https://github.com/tj/commander.js/pull/1403
377
+ [#1409]: https://github.com/tj/commander.js/pull/1409
378
+ [#1427]: https://github.com/tj/commander.js/pull/1427
407
379
 
408
380
  [Unreleased]: https://github.com/tj/commander.js/compare/master...develop
409
- [7.0.0-1]: https://github.com/tj/commander.js/compare/v7.0.0-1...v7.0.0-2
381
+ [7.0.0]: https://github.com/tj/commander.js/compare/v6.2.1...v7.0.0
382
+ [7.0.0-2]: https://github.com/tj/commander.js/compare/v7.0.0-1...v7.0.0-2
410
383
  [7.0.0-1]: https://github.com/tj/commander.js/compare/v7.0.0-0...v7.0.0-1
411
384
  [7.0.0-0]: https://github.com/tj/commander.js/compare/v6.2.0...v7.0.0-0
412
385
  [6.2.1]: https://github.com/tj/commander.js/compare/v6.2.0..v6.2.1
package/Readme.md CHANGED
@@ -35,6 +35,7 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
35
35
  - [Custom event listeners](#custom-event-listeners)
36
36
  - [Bits and pieces](#bits-and-pieces)
37
37
  - [.parse() and .parseAsync()](#parse-and-parseasync)
38
+ - [Parsing Configuration](#parsing-configuration)
38
39
  - [Legacy options as properties](#legacy-options-as-properties)
39
40
  - [TypeScript](#typescript)
40
41
  - [createCommand()](#createcommand)
@@ -84,7 +85,7 @@ For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.
84
85
 
85
86
  You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.
86
87
 
87
- Options on the command line are not positional, and can be specified before or after other arguments.
88
+ By default options on the command line are not positional, and can be specified before or after other arguments.
88
89
 
89
90
  ### Common option types, boolean and value
90
91
 
@@ -482,7 +483,8 @@ async function main() {
482
483
  }
483
484
  ```
484
485
 
485
- A command's options and arguments on the command line are validated when the command is used. Any unknown options or unexpected command-arguments will be reported as an error, or you can suppress these checks with `.allowUnknownOption()` and `.allowExcessArguments()`.
486
+ A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments will be reported as an error. You can suppress the unknown option checks with `.allowUnknownOption()`. By default it is not an error to
487
+ pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`.
486
488
 
487
489
  ### Stand-alone executable (sub)commands
488
490
 
@@ -684,6 +686,41 @@ program.parse(); // Implicit, and auto-detect electron
684
686
  program.parse(['-f', 'filename'], { from: 'user' });
685
687
  ```
686
688
 
689
+ ### Parsing Configuration
690
+
691
+ If the default parsing does not suit your needs, there are some behaviours to support other usage patterns.
692
+
693
+ By default program options are recognised before and after subcommands. To only look for program options before subcommands, use `.enablePositionalOptions()`. This lets you use
694
+ an option for a different purpose in subcommands.
695
+
696
+ Example file: [positional-options.js](./examples/positional-options.js)
697
+
698
+ With positional options, the `-b` is a program option in the first line and a subcommand option in the second:
699
+
700
+ ```sh
701
+ program -b subcommand
702
+ program subcommand -b
703
+ ```
704
+
705
+ By default options are recognised before and after command-arguments. To only process options that come
706
+ before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program
707
+ without needing to use `--` to end the option processing.
708
+ To use pass through options in a subcommand, the program needs to enable positional options.
709
+
710
+ Example file: [pass-through-options.js](./examples/pass-through-options.js)
711
+
712
+ With pass through options, the `--port=80` is a program option in the line and passed through as a command-argument in the second:
713
+
714
+ ```sh
715
+ program --port=80 arg
716
+ program arg --port=80
717
+ ```
718
+
719
+ By default the option processing shows an error for an unknown option. To have an unknown option treated as an ordinary command-argument and continue looking for options, use `.allowUnknownOption()`. This lets you mix known and unknown options.
720
+
721
+ By default the argument processing does not display an error for more command-arguments than expected.
722
+ To display an error for excess arguments, use`.allowExcessArguments(false)`.
723
+
687
724
  ### Legacy options as properties
688
725
 
689
726
  Before Commander 7, the option values were stored as properties on the command.
@@ -722,7 +759,7 @@ const program = createCommand();
722
759
 
723
760
  `createCommand` is also a method of the Command object, and creates a new command rather than a subcommand. This gets used internally
724
761
  when creating subcommands using `.command()`, and you may override it to
725
- customise the new subcommand (examples using [subclass](./examples/custom-command-class.js) and [function](./examples/custom-command-function.js)).
762
+ customise the new subcommand (example file [custom-command-class.js](./examples/custom-command-class.js)).
726
763
 
727
764
  ### Import into ECMAScript Module
728
765
 
@@ -865,8 +902,8 @@ More samples can be found in the [examples](https://github.com/tj/commander.js/t
865
902
 
866
903
  ## Support
867
904
 
868
- The current version of Commander is fully supported on Long Term Support versions of Node, and is likely to work with Node 6 but not tested.
869
- (For versions of Node below Node 6, use Commander 3.x or 2.x.)
905
+ The current version of Commander is fully supported on Long Term Support versions of node, and requires at least node v10.
906
+ (For older versions of node, use an older version of Commander. Commander version 2.x has the widest support.)
870
907
 
871
908
  The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
872
909
 
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  const EventEmitter = require('events').EventEmitter;
6
- const spawn = require('child_process').spawn;
6
+ const childProcess = require('child_process');
7
7
  const path = require('path');
8
8
  const fs = require('fs');
9
9
 
@@ -311,22 +311,22 @@ class Help {
311
311
 
312
312
  /**
313
313
  * Wrap the given string to width characters per line, with lines after the first indented.
314
- * Do not wrap if insufficient room for wrapping, or string is manually formatted.
314
+ * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
315
315
  *
316
316
  * @param {string} str
317
317
  * @param {number} width
318
318
  * @param {number} indent
319
+ * @param {number} [minColumnWidth=40]
319
320
  * @return {string}
320
321
  *
321
322
  */
322
323
 
323
- wrap(str, width, indent) {
324
+ wrap(str, width, indent, minColumnWidth = 40) {
324
325
  // Detect manually wrapped and indented strings by searching for line breaks
325
326
  // followed by multiple spaces/tabs.
326
327
  if (str.match(/[\n]\s+/)) return str;
327
328
  // Do not wrap if not enough room for a wrapped column of text (as could end up with a word per line).
328
329
  const columnWidth = width - indent;
329
- const minColumnWidth = 40;
330
330
  if (columnWidth < minColumnWidth) return str;
331
331
 
332
332
  const leadingStr = str.substr(0, indent);
@@ -535,7 +535,7 @@ class Command extends EventEmitter {
535
535
  this.options = [];
536
536
  this.parent = null;
537
537
  this._allowUnknownOption = false;
538
- this._allowExcessArguments = false;
538
+ this._allowExcessArguments = true;
539
539
  this._args = [];
540
540
  this.rawArgs = null;
541
541
  this._scriptPath = null;
@@ -552,6 +552,8 @@ class Command extends EventEmitter {
552
552
  this._combineFlagAndOptionalValue = true;
553
553
  this._description = '';
554
554
  this._argsDescription = undefined;
555
+ this._enablePositionalOptions = false;
556
+ this._passThroughOptions = false;
555
557
 
556
558
  // see .configureOutput() for docs
557
559
  this._outputConfiguration = {
@@ -633,6 +635,8 @@ class Command extends EventEmitter {
633
635
  cmd._exitCallback = this._exitCallback;
634
636
  cmd._storeOptionsAsProperties = this._storeOptionsAsProperties;
635
637
  cmd._combineFlagAndOptionalValue = this._combineFlagAndOptionalValue;
638
+ cmd._allowExcessArguments = this._allowExcessArguments;
639
+ cmd._enablePositionalOptions = this._enablePositionalOptions;
636
640
 
637
641
  cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor
638
642
  this.commands.push(cmd);
@@ -1123,7 +1127,7 @@ class Command extends EventEmitter {
1123
1127
  };
1124
1128
 
1125
1129
  /**
1126
- * Allow excess arguments on the command line.
1130
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1127
1131
  *
1128
1132
  * @param {Boolean} [allowExcess=true] - if `true` or omitted, no error will be thrown
1129
1133
  * for excess arguments.
@@ -1133,6 +1137,35 @@ class Command extends EventEmitter {
1133
1137
  return this;
1134
1138
  };
1135
1139
 
1140
+ /**
1141
+ * Enable positional options. Positional means global options are specified before subcommands which lets
1142
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1143
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
1144
+ *
1145
+ * @param {Boolean} [positional=true]
1146
+ */
1147
+ enablePositionalOptions(positional = true) {
1148
+ this._enablePositionalOptions = !!positional;
1149
+ return this;
1150
+ };
1151
+
1152
+ /**
1153
+ * Pass through options that come after command-arguments rather than treat them as command-options,
1154
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
1155
+ * positional options to have been enabled on the program (parent commands).
1156
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
1157
+ *
1158
+ * @param {Boolean} [passThrough=true]
1159
+ * for unknown options.
1160
+ */
1161
+ passThroughOptions(passThrough = true) {
1162
+ this._passThroughOptions = !!passThrough;
1163
+ if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
1164
+ throw new Error('passThroughOptions can not be used without turning on enablePositionOptions for parent command(s)');
1165
+ }
1166
+ return this;
1167
+ };
1168
+
1136
1169
  /**
1137
1170
  * Whether to store option values as properties on command object,
1138
1171
  * or store separately (specify false). In both cases the option values can be accessed using .opts().
@@ -1335,15 +1368,15 @@ class Command extends EventEmitter {
1335
1368
  // add executable arguments to spawn
1336
1369
  args = incrementNodeInspectorPort(process.execArgv).concat(args);
1337
1370
 
1338
- proc = spawn(process.argv[0], args, { stdio: 'inherit' });
1371
+ proc = childProcess.spawn(process.argv[0], args, { stdio: 'inherit' });
1339
1372
  } else {
1340
- proc = spawn(bin, args, { stdio: 'inherit' });
1373
+ proc = childProcess.spawn(bin, args, { stdio: 'inherit' });
1341
1374
  }
1342
1375
  } else {
1343
1376
  args.unshift(bin);
1344
1377
  // add executable arguments to spawn
1345
1378
  args = incrementNodeInspectorPort(process.execArgv).concat(args);
1346
- proc = spawn(process.execPath, args, { stdio: 'inherit' });
1379
+ proc = childProcess.spawn(process.execPath, args, { stdio: 'inherit' });
1347
1380
  }
1348
1381
 
1349
1382
  const signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
@@ -1609,11 +1642,38 @@ class Command extends EventEmitter {
1609
1642
  }
1610
1643
  }
1611
1644
 
1612
- // looks like an option but unknown, unknowns from here
1613
- if (arg.length > 1 && arg[0] === '-') {
1645
+ // Not a recognised option by this command.
1646
+ // Might be a command-argument, or subcommand option, or unknown option, or help command or option.
1647
+
1648
+ // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands.
1649
+ if (maybeOption(arg)) {
1614
1650
  dest = unknown;
1615
1651
  }
1616
1652
 
1653
+ // If using positionalOptions, stop processing our options at subcommand.
1654
+ if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1655
+ if (this._findCommand(arg)) {
1656
+ operands.push(arg);
1657
+ if (args.length > 0) unknown.push(...args);
1658
+ break;
1659
+ } else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
1660
+ operands.push(arg);
1661
+ if (args.length > 0) operands.push(...args);
1662
+ break;
1663
+ } else if (this._defaultCommandName) {
1664
+ unknown.push(arg);
1665
+ if (args.length > 0) unknown.push(...args);
1666
+ break;
1667
+ }
1668
+ }
1669
+
1670
+ // If using passThroughOptions, stop processing options at first command-argument.
1671
+ if (this._passThroughOptions) {
1672
+ dest.push(arg);
1673
+ if (args.length > 0) dest.push(...args);
1674
+ break;
1675
+ }
1676
+
1617
1677
  // add arg
1618
1678
  dest.push(arg);
1619
1679
  }
@@ -1665,20 +1725,14 @@ class Command extends EventEmitter {
1665
1725
  };
1666
1726
 
1667
1727
  /**
1668
- * `Option` is missing an argument, but received `flag` or nothing.
1728
+ * `Option` is missing an argument.
1669
1729
  *
1670
1730
  * @param {Option} option
1671
- * @param {string} [flag]
1672
1731
  * @api private
1673
1732
  */
1674
1733
 
1675
- optionMissingArgument(option, flag) {
1676
- let message;
1677
- if (flag) {
1678
- message = `error: option '${option.flags}' argument missing, got '${flag}'`;
1679
- } else {
1680
- message = `error: option '${option.flags}' argument missing`;
1681
- }
1734
+ optionMissingArgument(option) {
1735
+ const message = `error: option '${option.flags}' argument missing`;
1682
1736
  this._displayError(1, 'commander.optionMissingArgument', message);
1683
1737
  };
1684
1738
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commander",
3
- "version": "7.0.0-2",
3
+ "version": "7.0.0",
4
4
  "description": "the complete solution for node.js command-line programs",
5
5
  "keywords": [
6
6
  "commander",
@@ -33,17 +33,13 @@
33
33
  ],
34
34
  "dependencies": {},
35
35
  "devDependencies": {
36
- "@types/jest": "^26.0.16",
37
- "@types/node": "^14.14.10",
38
- "@typescript-eslint/eslint-plugin": "^4.9.0",
39
- "eslint": "^7.15.0",
36
+ "@types/jest": "^26.0.20",
37
+ "@types/node": "^14.14.20",
38
+ "@typescript-eslint/eslint-plugin": "^4.12.0",
39
+ "@typescript-eslint/parser": "^4.12.0",
40
+ "eslint": "^7.17.0",
40
41
  "eslint-config-standard": "^16.0.2",
41
- "eslint-config-standard-with-typescript": "^19.0.1",
42
- "eslint-plugin-import": "^2.22.1",
43
42
  "eslint-plugin-jest": "^24.1.3",
44
- "eslint-plugin-node": "^11.1.0",
45
- "eslint-plugin-promise": "^4.2.1",
46
- "eslint-plugin-standard": "^4.1.0",
47
43
  "jest": "^26.6.3",
48
44
  "standard": "^16.0.3",
49
45
  "typescript": "^4.1.2"
@@ -3,6 +3,7 @@
3
3
 
4
4
  // Using method rather than property for method-signature-style, to document method overloads separately. Allow either.
5
5
  /* eslint-disable @typescript-eslint/method-signature-style */
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
7
 
7
8
  declare namespace commander {
8
9
 
@@ -14,6 +15,7 @@ declare namespace commander {
14
15
  }
15
16
  type CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError;
16
17
 
18
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
17
19
  interface InvalidOptionArgumentError extends CommanderError {
18
20
  }
19
21
  type InvalidOptionArgumentErrorConstructor = new (message: string) => InvalidOptionArgumentError;
@@ -117,9 +119,9 @@ declare namespace commander {
117
119
 
118
120
  /**
119
121
  * Wrap the given string to width characters per line, with lines after the first indented.
120
- * Do not wrap if insufficient room for wrapping, or string is manually formatted.
122
+ * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
121
123
  */
122
- wrap(str: string, width: number, indent: number): string;
124
+ wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;
123
125
 
124
126
  /** Generate the built-in help text. */
125
127
  formatHelp(cmd: Command, helper: Help): string;
@@ -148,6 +150,10 @@ declare namespace commander {
148
150
 
149
151
  type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
150
152
 
153
+ interface OptionValues {
154
+ [key: string]: any;
155
+ }
156
+
151
157
  interface Command {
152
158
  args: string[];
153
159
 
@@ -372,6 +378,8 @@ declare namespace commander {
372
378
  *
373
379
  * @returns `this` command for chaining
374
380
  */
381
+ storeOptionsAsProperties(): this & OptionValues;
382
+ storeOptionsAsProperties(storeAsProperties: true): this & OptionValues;
375
383
  storeOptionsAsProperties(storeAsProperties?: boolean): this;
376
384
 
377
385
  /**
@@ -394,12 +402,33 @@ declare namespace commander {
394
402
  allowUnknownOption(allowUnknown?: boolean): this;
395
403
 
396
404
  /**
397
- * Allow excess arguments on the command line.
405
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
398
406
  *
399
407
  * @returns `this` command for chaining
400
408
  */
401
409
  allowExcessArguments(allowExcess?: boolean): this;
402
410
 
411
+ /**
412
+ * Enable positional options. Positional means global options are specified before subcommands which lets
413
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
414
+ *
415
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
416
+ *
417
+ * @returns `this` command for chaining
418
+ */
419
+ enablePositionalOptions(positional?: boolean): this;
420
+
421
+ /**
422
+ * Pass through options that come after command-arguments rather than treat them as command-options,
423
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
424
+ * positional options to have been enabled on the program (parent commands).
425
+ *
426
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
427
+ *
428
+ * @returns `this` command for chaining
429
+ */
430
+ passThroughOptions(passThrough?: boolean): this;
431
+
403
432
  /**
404
433
  * Parse `argv`, setting options and invoking commands when defined.
405
434
  *
@@ -450,7 +479,7 @@ declare namespace commander {
450
479
  /**
451
480
  * Return an object containing options as key-value pairs
452
481
  */
453
- opts(): { [key: string]: any };
482
+ opts(): OptionValues;
454
483
 
455
484
  /**
456
485
  * Set the description.