commander 11.0.0 → 12.0.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/Readme.md CHANGED
@@ -191,7 +191,7 @@ serve --port=80
191
191
 
192
192
  You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.
193
193
 
194
- By default options on the command line are not positional, and can be specified before or after other arguments.
194
+ By default, options on the command line are not positional, and can be specified before or after other arguments.
195
195
 
196
196
  There are additional related routines for when `.opts()` is not enough:
197
197
 
@@ -234,7 +234,7 @@ pizza details:
234
234
  - cheese
235
235
  ```
236
236
 
237
- Multiple boolean short options may be combined together following the dash, and may be followed by a single short option taking a value.
237
+ Multiple boolean short options may be combined following the dash, and may be followed by a single short option taking a value.
238
238
  For example `-d -s -p cheese` may be written as `-ds -p cheese` or even `-dsp cheese`.
239
239
 
240
240
  Options with an expected option-argument are greedy and will consume the following argument whatever the value.
@@ -327,7 +327,7 @@ add cheese type mozzarella
327
327
  Options with an optional option-argument are not greedy and will ignore arguments starting with a dash.
328
328
  So `id` behaves as a boolean option for `--id -5`, but you can use a combined form if needed like `--id=-5`.
329
329
 
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).
331
331
 
332
332
  ### Required option
333
333
 
@@ -379,7 +379,7 @@ Options: { number: [ '1', '2', '3' ], letter: true }
379
379
  Remaining arguments: [ 'operand' ]
380
380
  ```
381
381
 
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).
383
383
 
384
384
  ### Version option
385
385
 
@@ -546,6 +546,8 @@ subcommand is specified ([example](./examples/defaultCommand.js)).
546
546
 
547
547
  You can add alternative names for a command with `.alias()`. ([example](./examples/alias.js))
548
548
 
549
+ `.command()` automatically copies the inherited settings from the parent command to the newly created subcommand. This is only done during creation, any later setting changes to the parent are not inherited.
550
+
549
551
  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.
550
552
 
551
553
  ### Command-arguments
@@ -676,7 +678,7 @@ async function main() {
676
678
  }
677
679
  ```
678
680
 
679
- 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
681
+ 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
680
682
  pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`.
681
683
 
682
684
  ### Stand-alone executable (sub)commands
@@ -764,7 +766,7 @@ shell help spawn
764
766
  shell spawn --help
765
767
  ```
766
768
 
767
- 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.)
769
+ 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.)
768
770
 
769
771
  ### Custom help
770
772
 
@@ -852,8 +854,8 @@ error: unknown option '--hepl'
852
854
  The command name appears in the help, and is also used for locating stand-alone executable subcommands.
853
855
 
854
856
  You may specify the program name using `.name()` or in the Command constructor. For the program, Commander will
855
- fallback to using the script name from the full arguments passed into `.parse()`. However, the script name varies
856
- depending on how your program is launched so you may wish to specify it explicitly.
857
+ fall back to using the script name from the full arguments passed into `.parse()`. However, the script name varies
858
+ depending on how your program is launched, so you may wish to specify it explicitly.
857
859
 
858
860
  ```js
859
861
  program.name('pizza');
@@ -895,7 +897,7 @@ This may require additional disk space.
895
897
 
896
898
  ### .helpOption(flags, description)
897
899
 
898
- 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.
900
+ 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.
899
901
 
900
902
  ```js
901
903
  program
@@ -965,11 +967,13 @@ program.parse(); // Implicit, and auto-detect electron
965
967
  program.parse(['-f', 'filename'], { from: 'user' });
966
968
  ```
967
969
 
970
+ If you want to parse multiple times, create a new program each time. Calling parse does not clear out any previous state.
971
+
968
972
  ### Parsing Configuration
969
973
 
970
974
  If the default parsing does not suit your needs, there are some behaviours to support other usage patterns.
971
975
 
972
- By default program options are recognised before and after subcommands. To only look for program options before subcommands, use `.enablePositionalOptions()`. This lets you use
976
+ By default, program options are recognised before and after subcommands. To only look for program options before subcommands, use `.enablePositionalOptions()`. This lets you use
973
977
  an option for a different purpose in subcommands.
974
978
 
975
979
  Example file: [positional-options.js](./examples/positional-options.js)
@@ -981,8 +985,8 @@ program -b subcommand
981
985
  program subcommand -b
982
986
  ```
983
987
 
984
- By default options are recognised before and after command-arguments. To only process options that come
985
- before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program
988
+ By default, options are recognised before and after command-arguments. To only process options that come
989
+ before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program
986
990
  without needing to use `--` to end the option processing.
987
991
  To use pass through options in a subcommand, the program needs to enable positional options.
988
992
 
@@ -995,15 +999,15 @@ program --port=80 arg
995
999
  program arg --port=80
996
1000
  ```
997
1001
 
998
- 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.
1002
+ 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.
999
1003
 
1000
- By default the argument processing does not display an error for more command-arguments than expected.
1004
+ By default, the argument processing does not display an error for more command-arguments than expected.
1001
1005
  To display an error for excess arguments, use`.allowExcessArguments(false)`.
1002
1006
 
1003
1007
  ### Legacy options as properties
1004
1008
 
1005
1009
  Before Commander 7, the option values were stored as properties on the command.
1006
- This was convenient to code but the downside was possible clashes with
1010
+ This was convenient to code, but the downside was possible clashes with
1007
1011
  existing properties of `Command`. You can revert to the old behaviour to run unmodified legacy code by using `.storeOptionsAsProperties()`.
1008
1012
 
1009
1013
  ```js
@@ -1027,7 +1031,7 @@ See [commander-js/extra-typings](https://github.com/commander-js/extra-typings)
1027
1031
  import { Command } from '@commander-js/extra-typings';
1028
1032
  ```
1029
1033
 
1030
- 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.
1034
+ 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.
1031
1035
 
1032
1036
  ```sh
1033
1037
  node -r ts-node/register pm.ts
@@ -1057,14 +1061,14 @@ You can enable `--harmony` option in two ways:
1057
1061
 
1058
1062
  An executable subcommand is launched as a separate child process.
1059
1063
 
1060
- If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al,
1064
+ If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al.,
1061
1065
  the inspector port is incremented by 1 for the spawned subcommand.
1062
1066
 
1063
1067
  If you are using VSCode to debug executable subcommands you need to set the `"autoAttachChildProcesses": true` flag in your launch.json configuration.
1064
1068
 
1065
1069
  ### npm run-script
1066
1070
 
1067
- 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
1071
+ 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
1068
1072
  `--` to stop the npm option parsing and pass through all the arguments.
1069
1073
 
1070
1074
  The synopsis for [npm run-script](https://docs.npmjs.com/cli/v9/commands/npm-run-script) explicitly shows the `--` for this reason:
@@ -1087,7 +1091,7 @@ program.error('Custom processing has failed', { exitCode: 2, code: 'my.custom.er
1087
1091
 
1088
1092
  ### Override exit and output handling
1089
1093
 
1090
- By default Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
1094
+ By default, Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
1091
1095
  this behaviour and optionally supply a callback. The default override throws a `CommanderError`.
1092
1096
 
1093
1097
  The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`. The default override behaviour is to throw the error, except for async handling of executable subcommand completion which carries on. The normal display of error messages or version or help
@@ -1103,7 +1107,7 @@ try {
1103
1107
  }
1104
1108
  ```
1105
1109
 
1106
- By default Commander is configured for a command-line application and writes to stdout and stderr.
1110
+ By default, Commander is configured for a command-line application and writes to stdout and stderr.
1107
1111
  You can modify this behaviour for custom applications. In addition, you can modify the display of error messages.
1108
1112
 
1109
1113
  Example file: [configure-output.js](./examples/configure-output.js)
@@ -1129,12 +1133,12 @@ program
1129
1133
  There is more information available about:
1130
1134
 
1131
1135
  - [deprecated](./docs/deprecated.md) features still supported for backwards compatibility
1132
- - [options taking varying arguments](./docs/options-taking-varying-arguments.md)
1136
+ - [options taking varying arguments](./docs/options-in-depth.md)
1133
1137
  - [parsing life cycle and hooks](./docs/parsing-and-hooks.md)
1134
1138
 
1135
1139
  ## Support
1136
1140
 
1137
- The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v16.
1141
+ The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v18.
1138
1142
  (For older versions of Node.js, use an older version of Commander.)
1139
1143
 
1140
1144
  The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
package/index.js CHANGED
@@ -4,24 +4,21 @@ const { CommanderError, InvalidArgumentError } = require('./lib/error.js');
4
4
  const { Help } = require('./lib/help.js');
5
5
  const { Option } = require('./lib/option.js');
6
6
 
7
- // @ts-check
7
+ exports.program = new Command();
8
8
 
9
- /**
10
- * Expose the root command.
11
- */
12
-
13
- exports = module.exports = new Command();
14
- exports.program = exports; // More explicit access to global command.
15
- // Implicit export of createArgument, createCommand, and createOption.
9
+ exports.createCommand = (name) => new Command(name);
10
+ exports.createOption = (flags, description) => new Option(flags, description);
11
+ exports.createArgument = (name, description) => new Argument(name, description);
16
12
 
17
13
  /**
18
14
  * Expose classes
19
15
  */
20
16
 
21
- exports.Argument = Argument;
22
17
  exports.Command = Command;
23
- exports.CommanderError = CommanderError;
18
+ exports.Option = Option;
19
+ exports.Argument = Argument;
24
20
  exports.Help = Help;
21
+
22
+ exports.CommanderError = CommanderError;
25
23
  exports.InvalidArgumentError = InvalidArgumentError;
26
24
  exports.InvalidOptionArgumentError = InvalidArgumentError; // Deprecated
27
- exports.Option = Option;
package/lib/argument.js CHANGED
@@ -1,7 +1,5 @@
1
1
  const { InvalidArgumentError } = require('./error.js');
2
2
 
3
- // @ts-check
4
-
5
3
  class Argument {
6
4
  /**
7
5
  * Initialize a new command argument with the given name and description.
@@ -52,7 +50,7 @@ class Argument {
52
50
  }
53
51
 
54
52
  /**
55
- * @api private
53
+ * @package internal use only
56
54
  */
57
55
 
58
56
  _concatValue(value, previous) {
@@ -66,7 +64,7 @@ class Argument {
66
64
  /**
67
65
  * Set the default value, and optionally supply the description to be displayed in the help.
68
66
  *
69
- * @param {any} value
67
+ * @param {*} value
70
68
  * @param {string} [description]
71
69
  * @return {Argument}
72
70
  */
@@ -132,7 +130,7 @@ class Argument {
132
130
  *
133
131
  * @param {Argument} arg
134
132
  * @return {string}
135
- * @api private
133
+ * @private
136
134
  */
137
135
 
138
136
  function humanReadableArgName(arg) {