commander 11.1.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 +3 -1
- package/index.js +4 -6
- package/lib/argument.js +2 -2
- package/lib/command.js +126 -68
- package/lib/option.js +5 -6
- package/package.json +7 -7
package/Readme.md
CHANGED
|
@@ -967,6 +967,8 @@ program.parse(); // Implicit, and auto-detect electron
|
|
|
967
967
|
program.parse(['-f', 'filename'], { from: 'user' });
|
|
968
968
|
```
|
|
969
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
|
+
|
|
970
972
|
### Parsing Configuration
|
|
971
973
|
|
|
972
974
|
If the default parsing does not suit your needs, there are some behaviours to support other usage patterns.
|
|
@@ -1136,7 +1138,7 @@ There is more information available about:
|
|
|
1136
1138
|
|
|
1137
1139
|
## Support
|
|
1138
1140
|
|
|
1139
|
-
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least
|
|
1141
|
+
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v18.
|
|
1140
1142
|
(For older versions of Node.js, use an older version of Commander.)
|
|
1141
1143
|
|
|
1142
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,13 +4,11 @@ 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
|
-
|
|
8
|
-
* Expose the root command.
|
|
9
|
-
*/
|
|
7
|
+
exports.program = new Command();
|
|
10
8
|
|
|
11
|
-
exports =
|
|
12
|
-
exports.
|
|
13
|
-
|
|
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);
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* Expose classes
|
package/lib/argument.js
CHANGED
|
@@ -50,7 +50,7 @@ class Argument {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* @
|
|
53
|
+
* @package internal use only
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
_concatValue(value, previous) {
|
|
@@ -130,7 +130,7 @@ class Argument {
|
|
|
130
130
|
*
|
|
131
131
|
* @param {Argument} arg
|
|
132
132
|
* @return {string}
|
|
133
|
-
* @
|
|
133
|
+
* @private
|
|
134
134
|
*/
|
|
135
135
|
|
|
136
136
|
function humanReadableArgName(arg) {
|
package/lib/command.js
CHANGED
|
@@ -110,7 +110,7 @@ class Command extends EventEmitter {
|
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* @returns {Command[]}
|
|
113
|
-
* @
|
|
113
|
+
* @private
|
|
114
114
|
*/
|
|
115
115
|
|
|
116
116
|
_getCommandAndAncestors() {
|
|
@@ -165,7 +165,7 @@ class Command extends EventEmitter {
|
|
|
165
165
|
cmd._hidden = !!(opts.noHelp || opts.hidden); // noHelp is deprecated old name for hidden
|
|
166
166
|
cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor
|
|
167
167
|
if (args) cmd.arguments(args);
|
|
168
|
-
this.
|
|
168
|
+
this._registerCommand(cmd);
|
|
169
169
|
cmd.parent = this;
|
|
170
170
|
cmd.copyInheritedSettings(this);
|
|
171
171
|
|
|
@@ -282,8 +282,10 @@ class Command extends EventEmitter {
|
|
|
282
282
|
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
283
283
|
if (opts.noHelp || opts.hidden) cmd._hidden = true; // modifying passed command due to existing implementation
|
|
284
284
|
|
|
285
|
-
this.
|
|
285
|
+
this._registerCommand(cmd);
|
|
286
286
|
cmd.parent = this;
|
|
287
|
+
cmd._checkForBrokenPassThrough();
|
|
288
|
+
|
|
287
289
|
return this;
|
|
288
290
|
}
|
|
289
291
|
|
|
@@ -392,7 +394,7 @@ class Command extends EventEmitter {
|
|
|
392
394
|
|
|
393
395
|
/**
|
|
394
396
|
* @return {boolean}
|
|
395
|
-
* @
|
|
397
|
+
* @package internal use only
|
|
396
398
|
*/
|
|
397
399
|
|
|
398
400
|
_hasImplicitHelpCommand() {
|
|
@@ -453,7 +455,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
453
455
|
* @param {string} code an id string representing the error
|
|
454
456
|
* @param {string} message human-readable description of the error
|
|
455
457
|
* @return never
|
|
456
|
-
* @
|
|
458
|
+
* @private
|
|
457
459
|
*/
|
|
458
460
|
|
|
459
461
|
_exit(exitCode, code, message) {
|
|
@@ -519,7 +521,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
519
521
|
* @param {string} value
|
|
520
522
|
* @param {*} previous
|
|
521
523
|
* @param {string} invalidArgumentMessage
|
|
522
|
-
* @
|
|
524
|
+
* @private
|
|
523
525
|
*/
|
|
524
526
|
|
|
525
527
|
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
@@ -534,6 +536,49 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
534
536
|
}
|
|
535
537
|
}
|
|
536
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Check for option flag conflicts.
|
|
541
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
542
|
+
*
|
|
543
|
+
* @param {Option} option
|
|
544
|
+
* @api private
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
_registerOption(option) {
|
|
548
|
+
const matchingOption = (option.short && this._findOption(option.short)) ||
|
|
549
|
+
(option.long && this._findOption(option.long));
|
|
550
|
+
if (matchingOption) {
|
|
551
|
+
const matchingFlag = (option.long && this._findOption(option.long)) ? option.long : option.short;
|
|
552
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
553
|
+
- already used by option '${matchingOption.flags}'`);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
this.options.push(option);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Check for command name and alias conflicts with existing commands.
|
|
561
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
562
|
+
*
|
|
563
|
+
* @param {Command} command
|
|
564
|
+
* @api private
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
_registerCommand(command) {
|
|
568
|
+
const knownBy = (cmd) => {
|
|
569
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
573
|
+
if (alreadyUsed) {
|
|
574
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join('|');
|
|
575
|
+
const newCmd = knownBy(command).join('|');
|
|
576
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
this.commands.push(command);
|
|
580
|
+
}
|
|
581
|
+
|
|
537
582
|
/**
|
|
538
583
|
* Add an option.
|
|
539
584
|
*
|
|
@@ -541,6 +586,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
541
586
|
* @return {Command} `this` command for chaining
|
|
542
587
|
*/
|
|
543
588
|
addOption(option) {
|
|
589
|
+
this._registerOption(option);
|
|
590
|
+
|
|
544
591
|
const oname = option.name();
|
|
545
592
|
const name = option.attributeName();
|
|
546
593
|
|
|
@@ -555,9 +602,6 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
555
602
|
this.setOptionValueWithSource(name, option.defaultValue, 'default');
|
|
556
603
|
}
|
|
557
604
|
|
|
558
|
-
// register the option
|
|
559
|
-
this.options.push(option);
|
|
560
|
-
|
|
561
605
|
// handler for cli and env supplied values
|
|
562
606
|
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
563
607
|
// val is null for optional option used without an optional-argument.
|
|
@@ -605,7 +649,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
605
649
|
/**
|
|
606
650
|
* Internal implementation shared by .option() and .requiredOption()
|
|
607
651
|
*
|
|
608
|
-
* @
|
|
652
|
+
* @private
|
|
609
653
|
*/
|
|
610
654
|
_optionEx(config, flags, description, fn, defaultValue) {
|
|
611
655
|
if (typeof flags === 'object' && flags instanceof Option) {
|
|
@@ -733,12 +777,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
733
777
|
*/
|
|
734
778
|
passThroughOptions(passThrough = true) {
|
|
735
779
|
this._passThroughOptions = !!passThrough;
|
|
736
|
-
|
|
737
|
-
throw new Error('passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)');
|
|
738
|
-
}
|
|
780
|
+
this._checkForBrokenPassThrough();
|
|
739
781
|
return this;
|
|
740
782
|
}
|
|
741
783
|
|
|
784
|
+
/**
|
|
785
|
+
* @private
|
|
786
|
+
*/
|
|
787
|
+
|
|
788
|
+
_checkForBrokenPassThrough() {
|
|
789
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
790
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
742
794
|
/**
|
|
743
795
|
* Whether to store option values as properties on command object,
|
|
744
796
|
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
@@ -751,9 +803,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
751
803
|
if (this.options.length) {
|
|
752
804
|
throw new Error('call .storeOptionsAsProperties() before adding options');
|
|
753
805
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
806
|
+
if (Object.keys(this._optionValues).length) {
|
|
807
|
+
throw new Error('call .storeOptionsAsProperties() before setting option values');
|
|
808
|
+
}
|
|
757
809
|
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
758
810
|
return this;
|
|
759
811
|
}
|
|
@@ -838,7 +890,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
838
890
|
* Get user arguments from implied or explicit arguments.
|
|
839
891
|
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
840
892
|
*
|
|
841
|
-
* @
|
|
893
|
+
* @private
|
|
842
894
|
*/
|
|
843
895
|
|
|
844
896
|
_prepareUserArgs(argv, parseOptions) {
|
|
@@ -941,7 +993,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
941
993
|
/**
|
|
942
994
|
* Execute a sub-command executable.
|
|
943
995
|
*
|
|
944
|
-
* @
|
|
996
|
+
* @private
|
|
945
997
|
*/
|
|
946
998
|
|
|
947
999
|
_executeSubCommand(subcommand, args) {
|
|
@@ -1028,15 +1080,15 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1028
1080
|
}
|
|
1029
1081
|
|
|
1030
1082
|
// By default terminate process when spawned process terminates.
|
|
1031
|
-
// Suppressing the exit if exitCallback defined is a bit messy and of limited use, but does allow process to stay running!
|
|
1032
1083
|
const exitCallback = this._exitCallback;
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1084
|
+
proc.on('close', (code, _signal) => {
|
|
1085
|
+
code = code ?? 1; // code is null if spawned process terminated due to a signal
|
|
1086
|
+
if (!exitCallback) {
|
|
1087
|
+
process.exit(code);
|
|
1088
|
+
} else {
|
|
1089
|
+
exitCallback(new CommanderError(code, 'commander.executeSubCommandAsync', '(close)'));
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1040
1092
|
proc.on('error', (err) => {
|
|
1041
1093
|
// @ts-ignore
|
|
1042
1094
|
if (err.code === 'ENOENT') {
|
|
@@ -1066,7 +1118,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1066
1118
|
}
|
|
1067
1119
|
|
|
1068
1120
|
/**
|
|
1069
|
-
* @
|
|
1121
|
+
* @private
|
|
1070
1122
|
*/
|
|
1071
1123
|
|
|
1072
1124
|
_dispatchSubcommand(commandName, operands, unknown) {
|
|
@@ -1089,7 +1141,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1089
1141
|
* Invoke help directly if possible, or dispatch if necessary.
|
|
1090
1142
|
* e.g. help foo
|
|
1091
1143
|
*
|
|
1092
|
-
* @
|
|
1144
|
+
* @private
|
|
1093
1145
|
*/
|
|
1094
1146
|
|
|
1095
1147
|
_dispatchHelpCommand(subcommandName) {
|
|
@@ -1110,7 +1162,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1110
1162
|
/**
|
|
1111
1163
|
* Check this.args against expected this.registeredArguments.
|
|
1112
1164
|
*
|
|
1113
|
-
* @
|
|
1165
|
+
* @private
|
|
1114
1166
|
*/
|
|
1115
1167
|
|
|
1116
1168
|
_checkNumberOfArguments() {
|
|
@@ -1132,7 +1184,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1132
1184
|
/**
|
|
1133
1185
|
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
1134
1186
|
*
|
|
1135
|
-
* @
|
|
1187
|
+
* @private
|
|
1136
1188
|
*/
|
|
1137
1189
|
|
|
1138
1190
|
_processArguments() {
|
|
@@ -1180,7 +1232,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1180
1232
|
* @param {Promise|undefined} promise
|
|
1181
1233
|
* @param {Function} fn
|
|
1182
1234
|
* @return {Promise|undefined}
|
|
1183
|
-
* @
|
|
1235
|
+
* @private
|
|
1184
1236
|
*/
|
|
1185
1237
|
|
|
1186
1238
|
_chainOrCall(promise, fn) {
|
|
@@ -1198,7 +1250,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1198
1250
|
* @param {Promise|undefined} promise
|
|
1199
1251
|
* @param {string} event
|
|
1200
1252
|
* @return {Promise|undefined}
|
|
1201
|
-
* @
|
|
1253
|
+
* @private
|
|
1202
1254
|
*/
|
|
1203
1255
|
|
|
1204
1256
|
_chainOrCallHooks(promise, event) {
|
|
@@ -1230,7 +1282,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1230
1282
|
* @param {Command} subCommand
|
|
1231
1283
|
* @param {string} event
|
|
1232
1284
|
* @return {Promise|undefined}
|
|
1233
|
-
* @
|
|
1285
|
+
* @private
|
|
1234
1286
|
*/
|
|
1235
1287
|
|
|
1236
1288
|
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
@@ -1249,7 +1301,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1249
1301
|
* Process arguments in context of this command.
|
|
1250
1302
|
* Returns action result, in case it is a promise.
|
|
1251
1303
|
*
|
|
1252
|
-
* @
|
|
1304
|
+
* @private
|
|
1253
1305
|
*/
|
|
1254
1306
|
|
|
1255
1307
|
_parseCommand(operands, unknown) {
|
|
@@ -1267,7 +1319,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1267
1319
|
return this._dispatchHelpCommand(operands[1]);
|
|
1268
1320
|
}
|
|
1269
1321
|
if (this._defaultCommandName) {
|
|
1270
|
-
|
|
1322
|
+
this._outputHelpIfRequested(unknown); // Run the help for default command from parent rather than passing to default command
|
|
1271
1323
|
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1272
1324
|
}
|
|
1273
1325
|
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
@@ -1275,7 +1327,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1275
1327
|
this.help({ error: true });
|
|
1276
1328
|
}
|
|
1277
1329
|
|
|
1278
|
-
|
|
1330
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1279
1331
|
this._checkForMissingMandatoryOptions();
|
|
1280
1332
|
this._checkForConflictingOptions();
|
|
1281
1333
|
|
|
@@ -1333,7 +1385,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1333
1385
|
/**
|
|
1334
1386
|
* Find matching command.
|
|
1335
1387
|
*
|
|
1336
|
-
* @
|
|
1388
|
+
* @private
|
|
1337
1389
|
*/
|
|
1338
1390
|
_findCommand(name) {
|
|
1339
1391
|
if (!name) return undefined;
|
|
@@ -1345,7 +1397,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1345
1397
|
*
|
|
1346
1398
|
* @param {string} arg
|
|
1347
1399
|
* @return {Option}
|
|
1348
|
-
* @
|
|
1400
|
+
* @package internal use only
|
|
1349
1401
|
*/
|
|
1350
1402
|
|
|
1351
1403
|
_findOption(arg) {
|
|
@@ -1356,7 +1408,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1356
1408
|
* Display an error message if a mandatory option does not have a value.
|
|
1357
1409
|
* Called after checking for help flags in leaf subcommand.
|
|
1358
1410
|
*
|
|
1359
|
-
* @
|
|
1411
|
+
* @private
|
|
1360
1412
|
*/
|
|
1361
1413
|
|
|
1362
1414
|
_checkForMissingMandatoryOptions() {
|
|
@@ -1373,7 +1425,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1373
1425
|
/**
|
|
1374
1426
|
* Display an error message if conflicting options are used together in this.
|
|
1375
1427
|
*
|
|
1376
|
-
* @
|
|
1428
|
+
* @private
|
|
1377
1429
|
*/
|
|
1378
1430
|
_checkForConflictingLocalOptions() {
|
|
1379
1431
|
const definedNonDefaultOptions = this.options.filter(
|
|
@@ -1404,7 +1456,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1404
1456
|
* Display an error message if conflicting options are used together.
|
|
1405
1457
|
* Called after checking for help flags in leaf subcommand.
|
|
1406
1458
|
*
|
|
1407
|
-
* @
|
|
1459
|
+
* @private
|
|
1408
1460
|
*/
|
|
1409
1461
|
_checkForConflictingOptions() {
|
|
1410
1462
|
// Walk up hierarchy so can call in subcommand after checking for displaying help.
|
|
@@ -1608,7 +1660,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1608
1660
|
* Apply any option related environment variables, if option does
|
|
1609
1661
|
* not have a value from cli or client code.
|
|
1610
1662
|
*
|
|
1611
|
-
* @
|
|
1663
|
+
* @private
|
|
1612
1664
|
*/
|
|
1613
1665
|
_parseOptionsEnv() {
|
|
1614
1666
|
this.options.forEach((option) => {
|
|
@@ -1631,7 +1683,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1631
1683
|
/**
|
|
1632
1684
|
* Apply any implied option values, if option is undefined or default value.
|
|
1633
1685
|
*
|
|
1634
|
-
* @
|
|
1686
|
+
* @private
|
|
1635
1687
|
*/
|
|
1636
1688
|
_parseOptionsImplied() {
|
|
1637
1689
|
const dualHelper = new DualOptions(this.options);
|
|
@@ -1655,7 +1707,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1655
1707
|
* Argument `name` is missing.
|
|
1656
1708
|
*
|
|
1657
1709
|
* @param {string} name
|
|
1658
|
-
* @
|
|
1710
|
+
* @private
|
|
1659
1711
|
*/
|
|
1660
1712
|
|
|
1661
1713
|
missingArgument(name) {
|
|
@@ -1667,7 +1719,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1667
1719
|
* `Option` is missing an argument.
|
|
1668
1720
|
*
|
|
1669
1721
|
* @param {Option} option
|
|
1670
|
-
* @
|
|
1722
|
+
* @private
|
|
1671
1723
|
*/
|
|
1672
1724
|
|
|
1673
1725
|
optionMissingArgument(option) {
|
|
@@ -1679,7 +1731,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1679
1731
|
* `Option` does not have a value, and is a mandatory option.
|
|
1680
1732
|
*
|
|
1681
1733
|
* @param {Option} option
|
|
1682
|
-
* @
|
|
1734
|
+
* @private
|
|
1683
1735
|
*/
|
|
1684
1736
|
|
|
1685
1737
|
missingMandatoryOptionValue(option) {
|
|
@@ -1692,7 +1744,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1692
1744
|
*
|
|
1693
1745
|
* @param {Option} option
|
|
1694
1746
|
* @param {Option} conflictingOption
|
|
1695
|
-
* @
|
|
1747
|
+
* @private
|
|
1696
1748
|
*/
|
|
1697
1749
|
_conflictingOption(option, conflictingOption) {
|
|
1698
1750
|
// The calling code does not know whether a negated option is the source of the
|
|
@@ -1729,7 +1781,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1729
1781
|
* Unknown option `flag`.
|
|
1730
1782
|
*
|
|
1731
1783
|
* @param {string} flag
|
|
1732
|
-
* @
|
|
1784
|
+
* @private
|
|
1733
1785
|
*/
|
|
1734
1786
|
|
|
1735
1787
|
unknownOption(flag) {
|
|
@@ -1758,7 +1810,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1758
1810
|
* Excess arguments, more than expected.
|
|
1759
1811
|
*
|
|
1760
1812
|
* @param {string[]} receivedArgs
|
|
1761
|
-
* @
|
|
1813
|
+
* @private
|
|
1762
1814
|
*/
|
|
1763
1815
|
|
|
1764
1816
|
_excessArguments(receivedArgs) {
|
|
@@ -1774,7 +1826,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1774
1826
|
/**
|
|
1775
1827
|
* Unknown command.
|
|
1776
1828
|
*
|
|
1777
|
-
* @
|
|
1829
|
+
* @private
|
|
1778
1830
|
*/
|
|
1779
1831
|
|
|
1780
1832
|
unknownCommand() {
|
|
@@ -1814,8 +1866,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1814
1866
|
flags = flags || '-V, --version';
|
|
1815
1867
|
description = description || 'output the version number';
|
|
1816
1868
|
const versionOption = this.createOption(flags, description);
|
|
1817
|
-
this._versionOptionName = versionOption.attributeName();
|
|
1818
|
-
this.
|
|
1869
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1870
|
+
this._registerOption(versionOption);
|
|
1871
|
+
|
|
1819
1872
|
this.on('option:' + versionOption.name(), () => {
|
|
1820
1873
|
this._outputConfiguration.writeOut(`${str}\n`);
|
|
1821
1874
|
this._exit(0, 'commander.version', str);
|
|
@@ -1871,6 +1924,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1871
1924
|
}
|
|
1872
1925
|
|
|
1873
1926
|
if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');
|
|
1927
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1928
|
+
if (matchingCommand) {
|
|
1929
|
+
// c.f. _registerCommand
|
|
1930
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join('|');
|
|
1931
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1932
|
+
}
|
|
1874
1933
|
|
|
1875
1934
|
command._aliases.push(alias);
|
|
1876
1935
|
return this;
|
|
@@ -1984,7 +2043,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1984
2043
|
}
|
|
1985
2044
|
|
|
1986
2045
|
/**
|
|
1987
|
-
* @
|
|
2046
|
+
* @private
|
|
1988
2047
|
*/
|
|
1989
2048
|
|
|
1990
2049
|
_getHelpContext(contextOptions) {
|
|
@@ -2110,22 +2169,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2110
2169
|
});
|
|
2111
2170
|
return this;
|
|
2112
2171
|
}
|
|
2113
|
-
}
|
|
2114
2172
|
|
|
2115
|
-
/**
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
*/
|
|
2173
|
+
/**
|
|
2174
|
+
* Output help information if help flags specified
|
|
2175
|
+
*
|
|
2176
|
+
* @param {Array} args - array of options to search for help flags
|
|
2177
|
+
* @private
|
|
2178
|
+
*/
|
|
2122
2179
|
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2180
|
+
_outputHelpIfRequested(args) {
|
|
2181
|
+
const helpOption = this._hasHelpOption && args.find(arg => arg === this._helpLongFlag || arg === this._helpShortFlag);
|
|
2182
|
+
if (helpOption) {
|
|
2183
|
+
this.outputHelp();
|
|
2184
|
+
// (Do not have all displayed text available so only passing placeholder.)
|
|
2185
|
+
this._exit(0, 'commander.helpDisplayed', '(outputHelp)');
|
|
2186
|
+
}
|
|
2129
2187
|
}
|
|
2130
2188
|
}
|
|
2131
2189
|
|
|
@@ -2134,7 +2192,7 @@ function outputHelpIfRequested(cmd, args) {
|
|
|
2134
2192
|
*
|
|
2135
2193
|
* @param {string[]} args - array of arguments from node.execArgv
|
|
2136
2194
|
* @returns {string[]}
|
|
2137
|
-
* @
|
|
2195
|
+
* @private
|
|
2138
2196
|
*/
|
|
2139
2197
|
|
|
2140
2198
|
function incrementNodeInspectorPort(args) {
|
package/lib/option.js
CHANGED
|
@@ -158,7 +158,7 @@ class Option {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
* @
|
|
161
|
+
* @package internal use only
|
|
162
162
|
*/
|
|
163
163
|
|
|
164
164
|
_concatValue(value, previous) {
|
|
@@ -208,7 +208,6 @@ class Option {
|
|
|
208
208
|
* as a object attribute key.
|
|
209
209
|
*
|
|
210
210
|
* @return {string}
|
|
211
|
-
* @api private
|
|
212
211
|
*/
|
|
213
212
|
|
|
214
213
|
attributeName() {
|
|
@@ -220,7 +219,7 @@ class Option {
|
|
|
220
219
|
*
|
|
221
220
|
* @param {string} arg
|
|
222
221
|
* @return {boolean}
|
|
223
|
-
* @
|
|
222
|
+
* @package internal use only
|
|
224
223
|
*/
|
|
225
224
|
|
|
226
225
|
is(arg) {
|
|
@@ -233,7 +232,7 @@ class Option {
|
|
|
233
232
|
* Options are one of boolean, negated, required argument, or optional argument.
|
|
234
233
|
*
|
|
235
234
|
* @return {boolean}
|
|
236
|
-
* @
|
|
235
|
+
* @package internal use only
|
|
237
236
|
*/
|
|
238
237
|
|
|
239
238
|
isBoolean() {
|
|
@@ -293,7 +292,7 @@ class DualOptions {
|
|
|
293
292
|
*
|
|
294
293
|
* @param {string} str
|
|
295
294
|
* @return {string}
|
|
296
|
-
* @
|
|
295
|
+
* @private
|
|
297
296
|
*/
|
|
298
297
|
|
|
299
298
|
function camelcase(str) {
|
|
@@ -305,7 +304,7 @@ function camelcase(str) {
|
|
|
305
304
|
/**
|
|
306
305
|
* Split the short and long flag out of something like '-m,--mixed <value>'
|
|
307
306
|
*
|
|
308
|
-
* @
|
|
307
|
+
* @private
|
|
309
308
|
*/
|
|
310
309
|
|
|
311
310
|
function splitOptionFlags(flags) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -58,23 +58,23 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/jest": "^29.2.4",
|
|
60
60
|
"@types/node": "^20.2.5",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
62
|
-
"@typescript-eslint/parser": "^
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
62
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
63
63
|
"eslint": "^8.30.0",
|
|
64
64
|
"eslint-config-standard": "^17.0.0",
|
|
65
|
-
"eslint-config-standard-with-typescript": "^
|
|
65
|
+
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
66
66
|
"eslint-plugin-import": "^2.26.0",
|
|
67
67
|
"eslint-plugin-jest": "^27.1.7",
|
|
68
|
-
"eslint-plugin-n": "^
|
|
68
|
+
"eslint-plugin-n": "^16.2.0",
|
|
69
69
|
"eslint-plugin-promise": "^6.1.1",
|
|
70
70
|
"jest": "^29.3.1",
|
|
71
71
|
"ts-jest": "^29.0.3",
|
|
72
|
-
"tsd": "^0.
|
|
72
|
+
"tsd": "^0.29.0",
|
|
73
73
|
"typescript": "^5.0.4"
|
|
74
74
|
},
|
|
75
75
|
"types": "typings/index.d.ts",
|
|
76
76
|
"engines": {
|
|
77
|
-
"node": ">=
|
|
77
|
+
"node": ">=18"
|
|
78
78
|
},
|
|
79
79
|
"support": true
|
|
80
80
|
}
|