bililive-cli 1.6.2 → 1.7.2

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/lib/index.cjs CHANGED
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var require$$0 = require('events');
5
- var require$$0$1 = require('child_process');
6
- var require$$1 = require('path');
7
- var require$$0$2 = require('fs');
8
- var require$$4 = require('process');
4
+ var EventEmitter$1 = require('node:events');
5
+ var require$$1 = require('node:child_process');
6
+ var path$1 = require('node:path');
9
7
  var fs$1 = require('node:fs');
8
+ var process$2 = require('node:process');
10
9
  var os = require('node:os');
11
- var path$1 = require('node:path');
12
10
 
13
11
  var commander = {};
14
12
 
@@ -18,7 +16,6 @@ var error = {};
18
16
 
19
17
  /**
20
18
  * CommanderError class
21
- * @class
22
19
  */
23
20
 
24
21
  let CommanderError$3 = class CommanderError extends Error {
@@ -27,7 +24,6 @@ let CommanderError$3 = class CommanderError extends Error {
27
24
  * @param {number} exitCode suggested exit code which could be used with process.exit
28
25
  * @param {string} code an id string representing the error
29
26
  * @param {string} message human-readable description of the error
30
- * @constructor
31
27
  */
32
28
  constructor(exitCode, code, message) {
33
29
  super(message);
@@ -42,13 +38,11 @@ let CommanderError$3 = class CommanderError extends Error {
42
38
 
43
39
  /**
44
40
  * InvalidArgumentError class
45
- * @class
46
41
  */
47
42
  let InvalidArgumentError$4 = class InvalidArgumentError extends CommanderError$3 {
48
43
  /**
49
44
  * Constructs the InvalidArgumentError class
50
45
  * @param {string} [message] explanation of why argument is invalid
51
- * @constructor
52
46
  */
53
47
  constructor(message) {
54
48
  super(1, 'commander.invalidArgument', message);
@@ -113,7 +107,7 @@ let Argument$3 = class Argument {
113
107
  }
114
108
 
115
109
  /**
116
- * @package internal use only
110
+ * @package
117
111
  */
118
112
 
119
113
  _concatValue(value, previous) {
@@ -161,7 +155,9 @@ let Argument$3 = class Argument {
161
155
  this.argChoices = values.slice();
162
156
  this.parseArg = (arg, previous) => {
163
157
  if (!this.argChoices.includes(arg)) {
164
- throw new InvalidArgumentError$3(`Allowed choices are ${this.argChoices.join(', ')}.`);
158
+ throw new InvalidArgumentError$3(
159
+ `Allowed choices are ${this.argChoices.join(', ')}.`,
160
+ );
165
161
  }
166
162
  if (this.variadic) {
167
163
  return this._concatValue(arg, previous);
@@ -173,6 +169,8 @@ let Argument$3 = class Argument {
173
169
 
174
170
  /**
175
171
  * Make argument required.
172
+ *
173
+ * @returns {Argument}
176
174
  */
177
175
  argRequired() {
178
176
  this.required = true;
@@ -181,6 +179,8 @@ let Argument$3 = class Argument {
181
179
 
182
180
  /**
183
181
  * Make argument optional.
182
+ *
183
+ * @returns {Argument}
184
184
  */
185
185
  argOptional() {
186
186
  this.required = false;
@@ -199,9 +199,7 @@ let Argument$3 = class Argument {
199
199
  function humanReadableArgName$2(arg) {
200
200
  const nameOutput = arg.name() + (arg.variadic === true ? '...' : '');
201
201
 
202
- return arg.required
203
- ? '<' + nameOutput + '>'
204
- : '[' + nameOutput + ']';
202
+ return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';
205
203
  }
206
204
 
207
205
  argument.Argument = Argument$3;
@@ -238,14 +236,14 @@ let Help$3 = class Help {
238
236
  */
239
237
 
240
238
  visibleCommands(cmd) {
241
- const visibleCommands = cmd.commands.filter(cmd => !cmd._hidden);
239
+ const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);
242
240
  const helpCommand = cmd._getHelpCommand();
243
241
  if (helpCommand && !helpCommand._hidden) {
244
242
  visibleCommands.push(helpCommand);
245
243
  }
246
244
  if (this.sortSubcommands) {
247
245
  visibleCommands.sort((a, b) => {
248
- // @ts-ignore: overloaded return type
246
+ // @ts-ignore: because overloaded return type
249
247
  return a.name().localeCompare(b.name());
250
248
  });
251
249
  }
@@ -257,12 +255,14 @@ let Help$3 = class Help {
257
255
  *
258
256
  * @param {Option} a
259
257
  * @param {Option} b
260
- * @returns number
258
+ * @returns {number}
261
259
  */
262
260
  compareOptions(a, b) {
263
261
  const getSortKey = (option) => {
264
262
  // WYSIWYG for order displayed in help. Short used for comparison if present. No special handling for negated.
265
- return option.short ? option.short.replace(/^-/, '') : option.long.replace(/^--/, '');
263
+ return option.short
264
+ ? option.short.replace(/^-/, '')
265
+ : option.long.replace(/^--/, '');
266
266
  };
267
267
  return getSortKey(a).localeCompare(getSortKey(b));
268
268
  }
@@ -285,9 +285,13 @@ let Help$3 = class Help {
285
285
  if (!removeShort && !removeLong) {
286
286
  visibleOptions.push(helpOption); // no changes needed
287
287
  } else if (helpOption.long && !removeLong) {
288
- visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
288
+ visibleOptions.push(
289
+ cmd.createOption(helpOption.long, helpOption.description),
290
+ );
289
291
  } else if (helpOption.short && !removeShort) {
290
- visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
292
+ visibleOptions.push(
293
+ cmd.createOption(helpOption.short, helpOption.description),
294
+ );
291
295
  }
292
296
  }
293
297
  if (this.sortOptions) {
@@ -307,8 +311,14 @@ let Help$3 = class Help {
307
311
  if (!this.showGlobalOptions) return [];
308
312
 
309
313
  const globalOptions = [];
310
- for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
311
- const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
314
+ for (
315
+ let ancestorCmd = cmd.parent;
316
+ ancestorCmd;
317
+ ancestorCmd = ancestorCmd.parent
318
+ ) {
319
+ const visibleOptions = ancestorCmd.options.filter(
320
+ (option) => !option.hidden,
321
+ );
312
322
  globalOptions.push(...visibleOptions);
313
323
  }
314
324
  if (this.sortOptions) {
@@ -327,13 +337,14 @@ let Help$3 = class Help {
327
337
  visibleArguments(cmd) {
328
338
  // Side effect! Apply the legacy descriptions before the arguments are displayed.
329
339
  if (cmd._argsDescription) {
330
- cmd.registeredArguments.forEach(argument => {
331
- argument.description = argument.description || cmd._argsDescription[argument.name()] || '';
340
+ cmd.registeredArguments.forEach((argument) => {
341
+ argument.description =
342
+ argument.description || cmd._argsDescription[argument.name()] || '';
332
343
  });
333
344
  }
334
345
 
335
346
  // If there are any arguments with a description then return all the arguments.
336
- if (cmd.registeredArguments.find(argument => argument.description)) {
347
+ if (cmd.registeredArguments.find((argument) => argument.description)) {
337
348
  return cmd.registeredArguments;
338
349
  }
339
350
  return [];
@@ -348,11 +359,15 @@ let Help$3 = class Help {
348
359
 
349
360
  subcommandTerm(cmd) {
350
361
  // Legacy. Ignores custom usage string, and nested commands.
351
- const args = cmd.registeredArguments.map(arg => humanReadableArgName$1(arg)).join(' ');
352
- return cmd._name +
362
+ const args = cmd.registeredArguments
363
+ .map((arg) => humanReadableArgName$1(arg))
364
+ .join(' ');
365
+ return (
366
+ cmd._name +
353
367
  (cmd._aliases[0] ? '|' + cmd._aliases[0] : '') +
354
368
  (cmd.options.length ? ' [options]' : '') + // simplistic check for non-help option
355
- (args ? ' ' + args : '');
369
+ (args ? ' ' + args : '')
370
+ );
356
371
  }
357
372
 
358
373
  /**
@@ -447,7 +462,11 @@ let Help$3 = class Help {
447
462
  cmdName = cmdName + '|' + cmd._aliases[0];
448
463
  }
449
464
  let ancestorCmdNames = '';
450
- for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
465
+ for (
466
+ let ancestorCmd = cmd.parent;
467
+ ancestorCmd;
468
+ ancestorCmd = ancestorCmd.parent
469
+ ) {
451
470
  ancestorCmdNames = ancestorCmd.name() + ' ' + ancestorCmdNames;
452
471
  }
453
472
  return ancestorCmdNames + cmdName + ' ' + cmd.usage();
@@ -461,7 +480,7 @@ let Help$3 = class Help {
461
480
  */
462
481
 
463
482
  commandDescription(cmd) {
464
- // @ts-ignore: overloaded return type
483
+ // @ts-ignore: because overloaded return type
465
484
  return cmd.description();
466
485
  }
467
486
 
@@ -474,7 +493,7 @@ let Help$3 = class Help {
474
493
  */
475
494
 
476
495
  subcommandDescription(cmd) {
477
- // @ts-ignore: overloaded return type
496
+ // @ts-ignore: because overloaded return type
478
497
  return cmd.summary() || cmd.description();
479
498
  }
480
499
 
@@ -491,15 +510,20 @@ let Help$3 = class Help {
491
510
  if (option.argChoices) {
492
511
  extraInfo.push(
493
512
  // use stringify to match the display of the default value
494
- `choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`);
513
+ `choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`,
514
+ );
495
515
  }
496
516
  if (option.defaultValue !== undefined) {
497
517
  // default for boolean and negated more for programmer than end user,
498
518
  // but show true/false for boolean option as may be for hand-rolled env or config processing.
499
- const showDefault = option.required || option.optional ||
519
+ const showDefault =
520
+ option.required ||
521
+ option.optional ||
500
522
  (option.isBoolean() && typeof option.defaultValue === 'boolean');
501
523
  if (showDefault) {
502
- extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
524
+ extraInfo.push(
525
+ `default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`,
526
+ );
503
527
  }
504
528
  }
505
529
  // preset for boolean and negated are more for programmer than end user
@@ -528,10 +552,13 @@ let Help$3 = class Help {
528
552
  if (argument.argChoices) {
529
553
  extraInfo.push(
530
554
  // use stringify to match the display of the default value
531
- `choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`);
555
+ `choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`,
556
+ );
532
557
  }
533
558
  if (argument.defaultValue !== undefined) {
534
- extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
559
+ extraInfo.push(
560
+ `default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`,
561
+ );
535
562
  }
536
563
  if (extraInfo.length > 0) {
537
564
  const extraDescripton = `(${extraInfo.join(', ')})`;
@@ -559,7 +586,11 @@ let Help$3 = class Help {
559
586
  function formatItem(term, description) {
560
587
  if (description) {
561
588
  const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
562
- return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
589
+ return helper.wrap(
590
+ fullText,
591
+ helpWidth - itemIndentWidth,
592
+ termWidth + itemSeparatorWidth,
593
+ );
563
594
  }
564
595
  return term;
565
596
  }
@@ -573,12 +604,18 @@ let Help$3 = class Help {
573
604
  // Description
574
605
  const commandDescription = helper.commandDescription(cmd);
575
606
  if (commandDescription.length > 0) {
576
- output = output.concat([helper.wrap(commandDescription, helpWidth, 0), '']);
607
+ output = output.concat([
608
+ helper.wrap(commandDescription, helpWidth, 0),
609
+ '',
610
+ ]);
577
611
  }
578
612
 
579
613
  // Arguments
580
614
  const argumentList = helper.visibleArguments(cmd).map((argument) => {
581
- return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
615
+ return formatItem(
616
+ helper.argumentTerm(argument),
617
+ helper.argumentDescription(argument),
618
+ );
582
619
  });
583
620
  if (argumentList.length > 0) {
584
621
  output = output.concat(['Arguments:', formatList(argumentList), '']);
@@ -586,24 +623,39 @@ let Help$3 = class Help {
586
623
 
587
624
  // Options
588
625
  const optionList = helper.visibleOptions(cmd).map((option) => {
589
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
626
+ return formatItem(
627
+ helper.optionTerm(option),
628
+ helper.optionDescription(option),
629
+ );
590
630
  });
591
631
  if (optionList.length > 0) {
592
632
  output = output.concat(['Options:', formatList(optionList), '']);
593
633
  }
594
634
 
595
635
  if (this.showGlobalOptions) {
596
- const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
597
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
598
- });
636
+ const globalOptionList = helper
637
+ .visibleGlobalOptions(cmd)
638
+ .map((option) => {
639
+ return formatItem(
640
+ helper.optionTerm(option),
641
+ helper.optionDescription(option),
642
+ );
643
+ });
599
644
  if (globalOptionList.length > 0) {
600
- output = output.concat(['Global Options:', formatList(globalOptionList), '']);
645
+ output = output.concat([
646
+ 'Global Options:',
647
+ formatList(globalOptionList),
648
+ '',
649
+ ]);
601
650
  }
602
651
  }
603
652
 
604
653
  // Commands
605
654
  const commandList = helper.visibleCommands(cmd).map((cmd) => {
606
- return formatItem(helper.subcommandTerm(cmd), helper.subcommandDescription(cmd));
655
+ return formatItem(
656
+ helper.subcommandTerm(cmd),
657
+ helper.subcommandDescription(cmd),
658
+ );
607
659
  });
608
660
  if (commandList.length > 0) {
609
661
  output = output.concat(['Commands:', formatList(commandList), '']);
@@ -625,7 +677,7 @@ let Help$3 = class Help {
625
677
  helper.longestOptionTermLength(cmd, helper),
626
678
  helper.longestGlobalOptionTermLength(cmd, helper),
627
679
  helper.longestSubcommandTermLength(cmd, helper),
628
- helper.longestArgumentTermLength(cmd, helper)
680
+ helper.longestArgumentTermLength(cmd, helper),
629
681
  );
630
682
  }
631
683
 
@@ -643,7 +695,8 @@ let Help$3 = class Help {
643
695
 
644
696
  wrap(str, width, indent, minColumnWidth = 40) {
645
697
  // Full \s characters, minus the linefeeds.
646
- const indents = ' \\f\\t\\v\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff';
698
+ const indents =
699
+ ' \\f\\t\\v\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff';
647
700
  // Detect manually wrapped and indented strings by searching for line break followed by spaces.
648
701
  const manualIndent = new RegExp(`[\\n][${indents}]+`);
649
702
  if (str.match(manualIndent)) return str;
@@ -658,12 +711,20 @@ let Help$3 = class Help {
658
711
  const breaks = `\\s${zeroWidthSpace}`;
659
712
  // Match line end (so empty lines don't collapse),
660
713
  // or as much text as will fit in column, or excess text up to first break.
661
- const regex = new RegExp(`\n|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, 'g');
714
+ const regex = new RegExp(
715
+ `\n|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
716
+ 'g',
717
+ );
662
718
  const lines = columnText.match(regex) || [];
663
- return leadingStr + lines.map((line, i) => {
664
- if (line === '\n') return ''; // preserve empty lines
665
- return ((i > 0) ? indentString : '') + line.trimEnd();
666
- }).join('\n');
719
+ return (
720
+ leadingStr +
721
+ lines
722
+ .map((line, i) => {
723
+ if (line === '\n') return ''; // preserve empty lines
724
+ return (i > 0 ? indentString : '') + line.trimEnd();
725
+ })
726
+ .join('\n')
727
+ );
667
728
  }
668
729
  };
669
730
 
@@ -766,7 +827,7 @@ let Option$3 = class Option {
766
827
  * .addOption(new Option('--log', 'write logging information to file'))
767
828
  * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
768
829
  *
769
- * @param {Object} impliedOptionValues
830
+ * @param {object} impliedOptionValues
770
831
  * @return {Option}
771
832
  */
772
833
  implies(impliedOptionValues) {
@@ -831,7 +892,7 @@ let Option$3 = class Option {
831
892
  }
832
893
 
833
894
  /**
834
- * @package internal use only
895
+ * @package
835
896
  */
836
897
 
837
898
  _concatValue(value, previous) {
@@ -853,7 +914,9 @@ let Option$3 = class Option {
853
914
  this.argChoices = values.slice();
854
915
  this.parseArg = (arg, previous) => {
855
916
  if (!this.argChoices.includes(arg)) {
856
- throw new InvalidArgumentError$2(`Allowed choices are ${this.argChoices.join(', ')}.`);
917
+ throw new InvalidArgumentError$2(
918
+ `Allowed choices are ${this.argChoices.join(', ')}.`,
919
+ );
857
920
  }
858
921
  if (this.variadic) {
859
922
  return this._concatValue(arg, previous);
@@ -892,7 +955,7 @@ let Option$3 = class Option {
892
955
  *
893
956
  * @param {string} arg
894
957
  * @return {boolean}
895
- * @package internal use only
958
+ * @package
896
959
  */
897
960
 
898
961
  is(arg) {
@@ -905,7 +968,7 @@ let Option$3 = class Option {
905
968
  * Options are one of boolean, negated, required argument, or optional argument.
906
969
  *
907
970
  * @return {boolean}
908
- * @package internal use only
971
+ * @package
909
972
  */
910
973
 
911
974
  isBoolean() {
@@ -928,7 +991,7 @@ let DualOptions$1 = class DualOptions {
928
991
  this.positiveOptions = new Map();
929
992
  this.negativeOptions = new Map();
930
993
  this.dualOptions = new Set();
931
- options.forEach(option => {
994
+ options.forEach((option) => {
932
995
  if (option.negate) {
933
996
  this.negativeOptions.set(option.attributeName(), option);
934
997
  } else {
@@ -955,7 +1018,7 @@ let DualOptions$1 = class DualOptions {
955
1018
 
956
1019
  // Use the value to deduce if (probably) came from the option.
957
1020
  const preset = this.negativeOptions.get(optionKey).presetArg;
958
- const negativeValue = (preset !== undefined) ? preset : false;
1021
+ const negativeValue = preset !== undefined ? preset : false;
959
1022
  return option.negate === (negativeValue === value);
960
1023
  }
961
1024
  };
@@ -986,7 +1049,8 @@ function splitOptionFlags(flags) {
986
1049
  // Use original very loose parsing to maintain backwards compatibility for now,
987
1050
  // which allowed for example unintended `-sw, --short-word` [sic].
988
1051
  const flagParts = flags.split(/[ |,]+/);
989
- if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) shortFlag = flagParts.shift();
1052
+ if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
1053
+ shortFlag = flagParts.shift();
990
1054
  longFlag = flagParts.shift();
991
1055
  // Add support for lone short flag without significantly changing parsing!
992
1056
  if (!shortFlag && /^-[^-]$/.test(longFlag)) {
@@ -1009,7 +1073,8 @@ function editDistance(a, b) {
1009
1073
  // (Simple implementation.)
1010
1074
 
1011
1075
  // Quick early exit, return worst case.
1012
- if (Math.abs(a.length - b.length) > maxDistance) return Math.max(a.length, b.length);
1076
+ if (Math.abs(a.length - b.length) > maxDistance)
1077
+ return Math.max(a.length, b.length);
1013
1078
 
1014
1079
  // distance between prefix substrings of a and b
1015
1080
  const d = [];
@@ -1035,7 +1100,7 @@ function editDistance(a, b) {
1035
1100
  d[i][j] = Math.min(
1036
1101
  d[i - 1][j] + 1, // deletion
1037
1102
  d[i][j - 1] + 1, // insertion
1038
- d[i - 1][j - 1] + cost // substitution
1103
+ d[i - 1][j - 1] + cost, // substitution
1039
1104
  );
1040
1105
  // transposition
1041
1106
  if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
@@ -1063,7 +1128,7 @@ function suggestSimilar$1(word, candidates) {
1063
1128
  const searchingOptions = word.startsWith('--');
1064
1129
  if (searchingOptions) {
1065
1130
  word = word.slice(2);
1066
- candidates = candidates.map(candidate => candidate.slice(2));
1131
+ candidates = candidates.map((candidate) => candidate.slice(2));
1067
1132
  }
1068
1133
 
1069
1134
  let similar = [];
@@ -1088,7 +1153,7 @@ function suggestSimilar$1(word, candidates) {
1088
1153
 
1089
1154
  similar.sort((a, b) => a.localeCompare(b));
1090
1155
  if (searchingOptions) {
1091
- similar = similar.map(candidate => `--${candidate}`);
1156
+ similar = similar.map((candidate) => `--${candidate}`);
1092
1157
  }
1093
1158
 
1094
1159
  if (similar.length > 1) {
@@ -1102,11 +1167,11 @@ function suggestSimilar$1(word, candidates) {
1102
1167
 
1103
1168
  suggestSimilar$2.suggestSimilar = suggestSimilar$1;
1104
1169
 
1105
- const EventEmitter = require$$0.EventEmitter;
1106
- const childProcess = require$$0$1;
1107
- const path = require$$1;
1108
- const fs = require$$0$2;
1109
- const process$1 = require$$4;
1170
+ const EventEmitter = EventEmitter$1.EventEmitter;
1171
+ const childProcess = require$$1;
1172
+ const path = path$1;
1173
+ const fs = fs$1;
1174
+ const process$1 = process$2;
1110
1175
 
1111
1176
  const { Argument: Argument$2, humanReadableArgName } = argument;
1112
1177
  const { CommanderError: CommanderError$2 } = error;
@@ -1164,9 +1229,11 @@ let Command$2 = class Command extends EventEmitter {
1164
1229
  this._outputConfiguration = {
1165
1230
  writeOut: (str) => process$1.stdout.write(str),
1166
1231
  writeErr: (str) => process$1.stderr.write(str),
1167
- getOutHelpWidth: () => process$1.stdout.isTTY ? process$1.stdout.columns : undefined,
1168
- getErrHelpWidth: () => process$1.stderr.isTTY ? process$1.stderr.columns : undefined,
1169
- outputError: (str, write) => write(str)
1232
+ getOutHelpWidth: () =>
1233
+ process$1.stdout.isTTY ? process$1.stdout.columns : undefined,
1234
+ getErrHelpWidth: () =>
1235
+ process$1.stderr.isTTY ? process$1.stderr.columns : undefined,
1236
+ outputError: (str, write) => write(str),
1170
1237
  };
1171
1238
 
1172
1239
  this._hidden = false;
@@ -1193,7 +1260,8 @@ let Command$2 = class Command extends EventEmitter {
1193
1260
  this._helpConfiguration = sourceCommand._helpConfiguration;
1194
1261
  this._exitCallback = sourceCommand._exitCallback;
1195
1262
  this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
1196
- this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
1263
+ this._combineFlagAndOptionalValue =
1264
+ sourceCommand._combineFlagAndOptionalValue;
1197
1265
  this._allowExcessArguments = sourceCommand._allowExcessArguments;
1198
1266
  this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
1199
1267
  this._showHelpAfterError = sourceCommand._showHelpAfterError;
@@ -1209,6 +1277,7 @@ let Command$2 = class Command extends EventEmitter {
1209
1277
 
1210
1278
  _getCommandAndAncestors() {
1211
1279
  const result = [];
1280
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1212
1281
  for (let command = this; command; command = command.parent) {
1213
1282
  result.push(command);
1214
1283
  }
@@ -1235,8 +1304,8 @@ let Command$2 = class Command extends EventEmitter {
1235
1304
  * .command('stop [service]', 'stop named service, or all if no name supplied');
1236
1305
  *
1237
1306
  * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
1238
- * @param {(Object|string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
1239
- * @param {Object} [execOpts] - configuration options (for executable)
1307
+ * @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
1308
+ * @param {object} [execOpts] - configuration options (for executable)
1240
1309
  * @return {Command} returns new command for action handler, or `this` for executable command
1241
1310
  */
1242
1311
 
@@ -1296,8 +1365,8 @@ let Command$2 = class Command extends EventEmitter {
1296
1365
  * You can customise the help by overriding Help properties using configureHelp(),
1297
1366
  * or with a subclass of Help by overriding createHelp().
1298
1367
  *
1299
- * @param {Object} [configuration] - configuration options
1300
- * @return {(Command|Object)} `this` command for chaining, or stored configuration
1368
+ * @param {object} [configuration] - configuration options
1369
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
1301
1370
  */
1302
1371
 
1303
1372
  configureHelp(configuration) {
@@ -1322,8 +1391,8 @@ let Command$2 = class Command extends EventEmitter {
1322
1391
  * // functions based on what is being written out
1323
1392
  * outputError(str, write) // used for displaying errors, and not used for displaying help
1324
1393
  *
1325
- * @param {Object} [configuration] - configuration options
1326
- * @return {(Command|Object)} `this` command for chaining, or stored configuration
1394
+ * @param {object} [configuration] - configuration options
1395
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
1327
1396
  */
1328
1397
 
1329
1398
  configureOutput(configuration) {
@@ -1362,7 +1431,7 @@ let Command$2 = class Command extends EventEmitter {
1362
1431
  * See .command() for creating an attached subcommand which inherits settings from its parent.
1363
1432
  *
1364
1433
  * @param {Command} cmd - new subcommand
1365
- * @param {Object} [opts] - configuration options
1434
+ * @param {object} [opts] - configuration options
1366
1435
  * @return {Command} `this` command for chaining
1367
1436
  */
1368
1437
 
@@ -1438,9 +1507,12 @@ let Command$2 = class Command extends EventEmitter {
1438
1507
  */
1439
1508
 
1440
1509
  arguments(names) {
1441
- names.trim().split(/ +/).forEach((detail) => {
1442
- this.argument(detail);
1443
- });
1510
+ names
1511
+ .trim()
1512
+ .split(/ +/)
1513
+ .forEach((detail) => {
1514
+ this.argument(detail);
1515
+ });
1444
1516
  return this;
1445
1517
  }
1446
1518
 
@@ -1453,10 +1525,18 @@ let Command$2 = class Command extends EventEmitter {
1453
1525
  addArgument(argument) {
1454
1526
  const previousArgument = this.registeredArguments.slice(-1)[0];
1455
1527
  if (previousArgument && previousArgument.variadic) {
1456
- throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
1528
+ throw new Error(
1529
+ `only the last argument can be variadic '${previousArgument.name()}'`,
1530
+ );
1457
1531
  }
1458
- if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
1459
- throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
1532
+ if (
1533
+ argument.required &&
1534
+ argument.defaultValue !== undefined &&
1535
+ argument.parseArg === undefined
1536
+ ) {
1537
+ throw new Error(
1538
+ `a default value for a required argument is never used: '${argument.name()}'`,
1539
+ );
1460
1540
  }
1461
1541
  this.registeredArguments.push(argument);
1462
1542
  return this;
@@ -1465,6 +1545,7 @@ let Command$2 = class Command extends EventEmitter {
1465
1545
  /**
1466
1546
  * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
1467
1547
  *
1548
+ * @example
1468
1549
  * program.helpCommand('help [cmd]');
1469
1550
  * program.helpCommand('help [cmd]', 'show help');
1470
1551
  * program.helpCommand(false); // suppress default help command
@@ -1523,8 +1604,11 @@ let Command$2 = class Command extends EventEmitter {
1523
1604
  * @package
1524
1605
  */
1525
1606
  _getHelpCommand() {
1526
- const hasImplicitHelpCommand = this._addImplicitHelpCommand ??
1527
- (this.commands.length && !this._actionHandler && !this._findCommand('help'));
1607
+ const hasImplicitHelpCommand =
1608
+ this._addImplicitHelpCommand ??
1609
+ (this.commands.length &&
1610
+ !this._actionHandler &&
1611
+ !this._findCommand('help'));
1528
1612
 
1529
1613
  if (hasImplicitHelpCommand) {
1530
1614
  if (this._helpCommand === undefined) {
@@ -1670,14 +1754,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
1670
1754
  * Register option if no conflicts found, or throw on conflict.
1671
1755
  *
1672
1756
  * @param {Option} option
1673
- * @api private
1757
+ * @private
1674
1758
  */
1675
1759
 
1676
1760
  _registerOption(option) {
1677
- const matchingOption = (option.short && this._findOption(option.short)) ||
1761
+ const matchingOption =
1762
+ (option.short && this._findOption(option.short)) ||
1678
1763
  (option.long && this._findOption(option.long));
1679
1764
  if (matchingOption) {
1680
- const matchingFlag = (option.long && this._findOption(option.long)) ? option.long : option.short;
1765
+ const matchingFlag =
1766
+ option.long && this._findOption(option.long)
1767
+ ? option.long
1768
+ : option.short;
1681
1769
  throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1682
1770
  - already used by option '${matchingOption.flags}'`);
1683
1771
  }
@@ -1690,7 +1778,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1690
1778
  * Register command if no conflicts found, or throw on conflict.
1691
1779
  *
1692
1780
  * @param {Command} command
1693
- * @api private
1781
+ * @private
1694
1782
  */
1695
1783
 
1696
1784
  _registerCommand(command) {
@@ -1698,11 +1786,15 @@ Expecting one of '${allowedValues.join("', '")}'`);
1698
1786
  return [cmd.name()].concat(cmd.aliases());
1699
1787
  };
1700
1788
 
1701
- const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
1789
+ const alreadyUsed = knownBy(command).find((name) =>
1790
+ this._findCommand(name),
1791
+ );
1702
1792
  if (alreadyUsed) {
1703
1793
  const existingCmd = knownBy(this._findCommand(alreadyUsed)).join('|');
1704
1794
  const newCmd = knownBy(command).join('|');
1705
- throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
1795
+ throw new Error(
1796
+ `cannot add command '${newCmd}' as already have command '${existingCmd}'`,
1797
+ );
1706
1798
  }
1707
1799
 
1708
1800
  this.commands.push(command);
@@ -1725,7 +1817,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
1725
1817
  // --no-foo is special and defaults foo to true, unless a --foo option is already defined
1726
1818
  const positiveLongFlag = option.long.replace(/^--no-/, '--');
1727
1819
  if (!this._findOption(positiveLongFlag)) {
1728
- this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, 'default');
1820
+ this.setOptionValueWithSource(
1821
+ name,
1822
+ option.defaultValue === undefined ? true : option.defaultValue,
1823
+ 'default',
1824
+ );
1729
1825
  }
1730
1826
  } else if (option.defaultValue !== undefined) {
1731
1827
  this.setOptionValueWithSource(name, option.defaultValue, 'default');
@@ -1778,11 +1874,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
1778
1874
  /**
1779
1875
  * Internal implementation shared by .option() and .requiredOption()
1780
1876
  *
1877
+ * @return {Command} `this` command for chaining
1781
1878
  * @private
1782
1879
  */
1783
1880
  _optionEx(config, flags, description, fn, defaultValue) {
1784
1881
  if (typeof flags === 'object' && flags instanceof Option$2) {
1785
- throw new Error('To add an Option object use addOption() instead of option() or requiredOption()');
1882
+ throw new Error(
1883
+ 'To add an Option object use addOption() instead of option() or requiredOption()',
1884
+ );
1786
1885
  }
1787
1886
  const option = this.createOption(flags, description);
1788
1887
  option.makeOptionMandatory(!!config.mandatory);
@@ -1830,20 +1929,26 @@ Expecting one of '${allowedValues.join("', '")}'`);
1830
1929
  }
1831
1930
 
1832
1931
  /**
1833
- * Add a required option which must have a value after parsing. This usually means
1834
- * the option must be specified on the command line. (Otherwise the same as .option().)
1835
- *
1836
- * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1837
- *
1838
- * @param {string} flags
1839
- * @param {string} [description]
1840
- * @param {(Function|*)} [parseArg] - custom option processing function or default value
1841
- * @param {*} [defaultValue]
1842
- * @return {Command} `this` command for chaining
1843
- */
1932
+ * Add a required option which must have a value after parsing. This usually means
1933
+ * the option must be specified on the command line. (Otherwise the same as .option().)
1934
+ *
1935
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1936
+ *
1937
+ * @param {string} flags
1938
+ * @param {string} [description]
1939
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1940
+ * @param {*} [defaultValue]
1941
+ * @return {Command} `this` command for chaining
1942
+ */
1844
1943
 
1845
1944
  requiredOption(flags, description, parseArg, defaultValue) {
1846
- return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
1945
+ return this._optionEx(
1946
+ { mandatory: true },
1947
+ flags,
1948
+ description,
1949
+ parseArg,
1950
+ defaultValue,
1951
+ );
1847
1952
  }
1848
1953
 
1849
1954
  /**
@@ -1854,7 +1959,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
1854
1959
  * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
1855
1960
  * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
1856
1961
  *
1857
- * @param {boolean} [combine=true] - if `true` or omitted, an optional value can be specified directly after the flag.
1962
+ * @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
1963
+ * @return {Command} `this` command for chaining
1858
1964
  */
1859
1965
  combineFlagAndOptionalValue(combine = true) {
1860
1966
  this._combineFlagAndOptionalValue = !!combine;
@@ -1864,8 +1970,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
1864
1970
  /**
1865
1971
  * Allow unknown options on the command line.
1866
1972
  *
1867
- * @param {boolean} [allowUnknown=true] - if `true` or omitted, no error will be thrown
1868
- * for unknown options.
1973
+ * @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
1974
+ * @return {Command} `this` command for chaining
1869
1975
  */
1870
1976
  allowUnknownOption(allowUnknown = true) {
1871
1977
  this._allowUnknownOption = !!allowUnknown;
@@ -1875,8 +1981,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
1875
1981
  /**
1876
1982
  * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1877
1983
  *
1878
- * @param {boolean} [allowExcess=true] - if `true` or omitted, no error will be thrown
1879
- * for excess arguments.
1984
+ * @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
1985
+ * @return {Command} `this` command for chaining
1880
1986
  */
1881
1987
  allowExcessArguments(allowExcess = true) {
1882
1988
  this._allowExcessArguments = !!allowExcess;
@@ -1888,7 +1994,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
1888
1994
  * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1889
1995
  * The default behaviour is non-positional and global options may appear anywhere on the command line.
1890
1996
  *
1891
- * @param {boolean} [positional=true]
1997
+ * @param {boolean} [positional]
1998
+ * @return {Command} `this` command for chaining
1892
1999
  */
1893
2000
  enablePositionalOptions(positional = true) {
1894
2001
  this._enablePositionalOptions = !!positional;
@@ -1901,8 +2008,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
1901
2008
  * positional options to have been enabled on the program (parent commands).
1902
2009
  * The default behaviour is non-positional and options may appear before or after command-arguments.
1903
2010
  *
1904
- * @param {boolean} [passThrough=true]
1905
- * for unknown options.
2011
+ * @param {boolean} [passThrough] for unknown options.
2012
+ * @return {Command} `this` command for chaining
1906
2013
  */
1907
2014
  passThroughOptions(passThrough = true) {
1908
2015
  this._passThroughOptions = !!passThrough;
@@ -1915,25 +2022,33 @@ Expecting one of '${allowedValues.join("', '")}'`);
1915
2022
  */
1916
2023
 
1917
2024
  _checkForBrokenPassThrough() {
1918
- if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1919
- throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
2025
+ if (
2026
+ this.parent &&
2027
+ this._passThroughOptions &&
2028
+ !this.parent._enablePositionalOptions
2029
+ ) {
2030
+ throw new Error(
2031
+ `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`,
2032
+ );
1920
2033
  }
1921
2034
  }
1922
2035
 
1923
2036
  /**
1924
- * Whether to store option values as properties on command object,
1925
- * or store separately (specify false). In both cases the option values can be accessed using .opts().
1926
- *
1927
- * @param {boolean} [storeAsProperties=true]
1928
- * @return {Command} `this` command for chaining
1929
- */
2037
+ * Whether to store option values as properties on command object,
2038
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
2039
+ *
2040
+ * @param {boolean} [storeAsProperties=true]
2041
+ * @return {Command} `this` command for chaining
2042
+ */
1930
2043
 
1931
2044
  storeOptionsAsProperties(storeAsProperties = true) {
1932
2045
  if (this.options.length) {
1933
2046
  throw new Error('call .storeOptionsAsProperties() before adding options');
1934
2047
  }
1935
2048
  if (Object.keys(this._optionValues).length) {
1936
- throw new Error('call .storeOptionsAsProperties() before setting option values');
2049
+ throw new Error(
2050
+ 'call .storeOptionsAsProperties() before setting option values',
2051
+ );
1937
2052
  }
1938
2053
  this._storeOptionsAsProperties = !!storeAsProperties;
1939
2054
  return this;
@@ -1943,7 +2058,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1943
2058
  * Retrieve option value.
1944
2059
  *
1945
2060
  * @param {string} key
1946
- * @return {Object} value
2061
+ * @return {object} value
1947
2062
  */
1948
2063
 
1949
2064
  getOptionValue(key) {
@@ -1957,7 +2072,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1957
2072
  * Store option value.
1958
2073
  *
1959
2074
  * @param {string} key
1960
- * @param {Object} value
2075
+ * @param {object} value
1961
2076
  * @return {Command} `this` command for chaining
1962
2077
  */
1963
2078
 
@@ -1966,13 +2081,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
1966
2081
  }
1967
2082
 
1968
2083
  /**
1969
- * Store option value and where the value came from.
1970
- *
1971
- * @param {string} key
1972
- * @param {Object} value
1973
- * @param {string} source - expected values are default/config/env/cli/implied
1974
- * @return {Command} `this` command for chaining
1975
- */
2084
+ * Store option value and where the value came from.
2085
+ *
2086
+ * @param {string} key
2087
+ * @param {object} value
2088
+ * @param {string} source - expected values are default/config/env/cli/implied
2089
+ * @return {Command} `this` command for chaining
2090
+ */
1976
2091
 
1977
2092
  setOptionValueWithSource(key, value, source) {
1978
2093
  if (this._storeOptionsAsProperties) {
@@ -1985,24 +2100,24 @@ Expecting one of '${allowedValues.join("', '")}'`);
1985
2100
  }
1986
2101
 
1987
2102
  /**
1988
- * Get source of option value.
1989
- * Expected values are default | config | env | cli | implied
1990
- *
1991
- * @param {string} key
1992
- * @return {string}
1993
- */
2103
+ * Get source of option value.
2104
+ * Expected values are default | config | env | cli | implied
2105
+ *
2106
+ * @param {string} key
2107
+ * @return {string}
2108
+ */
1994
2109
 
1995
2110
  getOptionValueSource(key) {
1996
2111
  return this._optionValueSources[key];
1997
2112
  }
1998
2113
 
1999
2114
  /**
2000
- * Get source of option value. See also .optsWithGlobals().
2001
- * Expected values are default | config | env | cli | implied
2002
- *
2003
- * @param {string} key
2004
- * @return {string}
2005
- */
2115
+ * Get source of option value. See also .optsWithGlobals().
2116
+ * Expected values are default | config | env | cli | implied
2117
+ *
2118
+ * @param {string} key
2119
+ * @return {string}
2120
+ */
2006
2121
 
2007
2122
  getOptionValueSourceWithGlobals(key) {
2008
2123
  // global overwrites local, like optsWithGlobals
@@ -2028,17 +2143,30 @@ Expecting one of '${allowedValues.join("', '")}'`);
2028
2143
  }
2029
2144
  parseOptions = parseOptions || {};
2030
2145
 
2031
- // Default to using process.argv
2032
- if (argv === undefined) {
2033
- argv = process$1.argv;
2034
- // @ts-ignore: unknown property
2035
- if (process$1.versions && process$1.versions.electron) {
2146
+ // auto-detect argument conventions if nothing supplied
2147
+ if (argv === undefined && parseOptions.from === undefined) {
2148
+ if (process$1.versions?.electron) {
2036
2149
  parseOptions.from = 'electron';
2037
2150
  }
2151
+ // check node specific options for scenarios where user CLI args follow executable without scriptname
2152
+ const execArgv = process$1.execArgv ?? [];
2153
+ if (
2154
+ execArgv.includes('-e') ||
2155
+ execArgv.includes('--eval') ||
2156
+ execArgv.includes('-p') ||
2157
+ execArgv.includes('--print')
2158
+ ) {
2159
+ parseOptions.from = 'eval'; // internal usage, not documented
2160
+ }
2161
+ }
2162
+
2163
+ // default to using process.argv
2164
+ if (argv === undefined) {
2165
+ argv = process$1.argv;
2038
2166
  }
2039
2167
  this.rawArgs = argv.slice();
2040
2168
 
2041
- // make it a little easier for callers by supporting various argv conventions
2169
+ // extract the user args and scriptPath
2042
2170
  let userArgs;
2043
2171
  switch (parseOptions.from) {
2044
2172
  case undefined:
@@ -2047,7 +2175,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2047
2175
  userArgs = argv.slice(2);
2048
2176
  break;
2049
2177
  case 'electron':
2050
- // @ts-ignore: unknown property
2178
+ // @ts-ignore: because defaultApp is an unknown property
2051
2179
  if (process$1.defaultApp) {
2052
2180
  this._scriptPath = argv[1];
2053
2181
  userArgs = argv.slice(2);
@@ -2058,12 +2186,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
2058
2186
  case 'user':
2059
2187
  userArgs = argv.slice(0);
2060
2188
  break;
2189
+ case 'eval':
2190
+ userArgs = argv.slice(1);
2191
+ break;
2061
2192
  default:
2062
- throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
2193
+ throw new Error(
2194
+ `unexpected parse option { from: '${parseOptions.from}' }`,
2195
+ );
2063
2196
  }
2064
2197
 
2065
2198
  // Find default name for program from arguments.
2066
- if (!this._name && this._scriptPath) this.nameFromFilename(this._scriptPath);
2199
+ if (!this._name && this._scriptPath)
2200
+ this.nameFromFilename(this._scriptPath);
2067
2201
  this._name = this._name || 'program';
2068
2202
 
2069
2203
  return userArgs;
@@ -2072,16 +2206,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
2072
2206
  /**
2073
2207
  * Parse `argv`, setting options and invoking commands when defined.
2074
2208
  *
2075
- * The default expectation is that the arguments are from node and have the application as argv[0]
2076
- * and the script being run in argv[1], with user parameters after that.
2209
+ * Use parseAsync instead of parse if any of your action handlers are async.
2210
+ *
2211
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
2212
+ *
2213
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
2214
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
2215
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
2216
+ * - `'user'`: just user arguments
2077
2217
  *
2078
2218
  * @example
2079
- * program.parse(process.argv);
2080
- * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
2219
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
2220
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
2081
2221
  * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
2082
2222
  *
2083
2223
  * @param {string[]} [argv] - optional, defaults to process.argv
2084
- * @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
2224
+ * @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
2085
2225
  * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
2086
2226
  * @return {Command} `this` command for chaining
2087
2227
  */
@@ -2096,18 +2236,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
2096
2236
  /**
2097
2237
  * Parse `argv`, setting options and invoking commands when defined.
2098
2238
  *
2099
- * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
2239
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
2100
2240
  *
2101
- * The default expectation is that the arguments are from node and have the application as argv[0]
2102
- * and the script being run in argv[1], with user parameters after that.
2241
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
2242
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
2243
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
2244
+ * - `'user'`: just user arguments
2103
2245
  *
2104
2246
  * @example
2105
- * await program.parseAsync(process.argv);
2106
- * await program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
2247
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
2248
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
2107
2249
  * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
2108
2250
  *
2109
2251
  * @param {string[]} [argv]
2110
- * @param {Object} [parseOptions]
2252
+ * @param {object} [parseOptions]
2111
2253
  * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
2112
2254
  * @return {Promise}
2113
2255
  */
@@ -2139,7 +2281,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
2139
2281
  if (sourceExt.includes(path.extname(baseName))) return undefined;
2140
2282
 
2141
2283
  // Try all the extensions.
2142
- const foundExt = sourceExt.find(ext => fs.existsSync(`${localBin}${ext}`));
2284
+ const foundExt = sourceExt.find((ext) =>
2285
+ fs.existsSync(`${localBin}${ext}`),
2286
+ );
2143
2287
  if (foundExt) return `${localBin}${foundExt}`;
2144
2288
 
2145
2289
  return undefined;
@@ -2150,7 +2294,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
2150
2294
  this._checkForConflictingOptions();
2151
2295
 
2152
2296
  // executableFile and executableDir might be full path, or just a name
2153
- let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
2297
+ let executableFile =
2298
+ subcommand._executableFile || `${this._name}-${subcommand._name}`;
2154
2299
  let executableDir = this._executableDir || '';
2155
2300
  if (this._scriptPath) {
2156
2301
  let resolvedScriptPath; // resolve possible symlink for installed npm binary
@@ -2159,7 +2304,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
2159
2304
  } catch (err) {
2160
2305
  resolvedScriptPath = this._scriptPath;
2161
2306
  }
2162
- executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
2307
+ executableDir = path.resolve(
2308
+ path.dirname(resolvedScriptPath),
2309
+ executableDir,
2310
+ );
2163
2311
  }
2164
2312
 
2165
2313
  // Look for a local file in preference to a command in PATH.
@@ -2168,9 +2316,15 @@ Expecting one of '${allowedValues.join("', '")}'`);
2168
2316
 
2169
2317
  // Legacy search using prefix of script name instead of command name
2170
2318
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
2171
- const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
2319
+ const legacyName = path.basename(
2320
+ this._scriptPath,
2321
+ path.extname(this._scriptPath),
2322
+ );
2172
2323
  if (legacyName !== this._name) {
2173
- localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
2324
+ localFile = findFile(
2325
+ executableDir,
2326
+ `${legacyName}-${subcommand._name}`,
2327
+ );
2174
2328
  }
2175
2329
  }
2176
2330
  executableFile = localFile || executableFile;
@@ -2196,12 +2350,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2196
2350
  proc = childProcess.spawn(process$1.execPath, args, { stdio: 'inherit' });
2197
2351
  }
2198
2352
 
2199
- if (!proc.killed) { // testing mainly to avoid leak warnings during unit tests with mocked spawn
2353
+ if (!proc.killed) {
2354
+ // testing mainly to avoid leak warnings during unit tests with mocked spawn
2200
2355
  const signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
2201
2356
  signals.forEach((signal) => {
2202
- // @ts-ignore
2203
2357
  process$1.on(signal, () => {
2204
2358
  if (proc.killed === false && proc.exitCode === null) {
2359
+ // @ts-ignore because signals not typed to known strings
2205
2360
  proc.kill(signal);
2206
2361
  }
2207
2362
  });
@@ -2210,16 +2365,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
2210
2365
 
2211
2366
  // By default terminate process when spawned process terminates.
2212
2367
  const exitCallback = this._exitCallback;
2213
- proc.on('close', (code, _signal) => {
2368
+ proc.on('close', (code) => {
2214
2369
  code = code ?? 1; // code is null if spawned process terminated due to a signal
2215
2370
  if (!exitCallback) {
2216
2371
  process$1.exit(code);
2217
2372
  } else {
2218
- exitCallback(new CommanderError$2(code, 'commander.executeSubCommandAsync', '(close)'));
2373
+ exitCallback(
2374
+ new CommanderError$2(
2375
+ code,
2376
+ 'commander.executeSubCommandAsync',
2377
+ '(close)',
2378
+ ),
2379
+ );
2219
2380
  }
2220
2381
  });
2221
2382
  proc.on('error', (err) => {
2222
- // @ts-ignore
2383
+ // @ts-ignore: because err.code is an unknown property
2223
2384
  if (err.code === 'ENOENT') {
2224
2385
  const executableDirMessage = executableDir
2225
2386
  ? `searched for local subcommand relative to directory '${executableDir}'`
@@ -2229,14 +2390,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
2229
2390
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
2230
2391
  - ${executableDirMessage}`;
2231
2392
  throw new Error(executableMissing);
2232
- // @ts-ignore
2393
+ // @ts-ignore: because err.code is an unknown property
2233
2394
  } else if (err.code === 'EACCES') {
2234
2395
  throw new Error(`'${executableFile}' not executable`);
2235
2396
  }
2236
2397
  if (!exitCallback) {
2237
2398
  process$1.exit(1);
2238
2399
  } else {
2239
- const wrappedError = new CommanderError$2(1, 'commander.executeSubCommandAsync', '(error)');
2400
+ const wrappedError = new CommanderError$2(
2401
+ 1,
2402
+ 'commander.executeSubCommandAsync',
2403
+ '(error)',
2404
+ );
2240
2405
  wrappedError.nestedError = err;
2241
2406
  exitCallback(wrappedError);
2242
2407
  }
@@ -2255,7 +2420,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2255
2420
  if (!subCommand) this.help({ error: true });
2256
2421
 
2257
2422
  let promiseChain;
2258
- promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, 'preSubcommand');
2423
+ promiseChain = this._chainOrCallSubCommandHook(
2424
+ promiseChain,
2425
+ subCommand,
2426
+ 'preSubcommand',
2427
+ );
2259
2428
  promiseChain = this._chainOrCall(promiseChain, () => {
2260
2429
  if (subCommand._executableHandler) {
2261
2430
  this._executeSubCommand(subCommand, operands.concat(unknown));
@@ -2283,9 +2452,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2283
2452
  }
2284
2453
 
2285
2454
  // Fallback to parsing the help flag to invoke the help.
2286
- return this._dispatchSubcommand(subcommandName, [], [
2287
- this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? '--help'
2288
- ]);
2455
+ return this._dispatchSubcommand(
2456
+ subcommandName,
2457
+ [],
2458
+ [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? '--help'],
2459
+ );
2289
2460
  }
2290
2461
 
2291
2462
  /**
@@ -2302,7 +2473,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
2302
2473
  }
2303
2474
  });
2304
2475
  // too many
2305
- if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
2476
+ if (
2477
+ this.registeredArguments.length > 0 &&
2478
+ this.registeredArguments[this.registeredArguments.length - 1].variadic
2479
+ ) {
2306
2480
  return;
2307
2481
  }
2308
2482
  if (this.args.length > this.registeredArguments.length) {
@@ -2322,7 +2496,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
2322
2496
  let parsedValue = value;
2323
2497
  if (value !== null && argument.parseArg) {
2324
2498
  const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
2325
- parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
2499
+ parsedValue = this._callParseArg(
2500
+ argument,
2501
+ value,
2502
+ previous,
2503
+ invalidValueMessage,
2504
+ );
2326
2505
  }
2327
2506
  return parsedValue;
2328
2507
  };
@@ -2387,8 +2566,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
2387
2566
  const hooks = [];
2388
2567
  this._getCommandAndAncestors()
2389
2568
  .reverse()
2390
- .filter(cmd => cmd._lifeCycleHooks[event] !== undefined)
2391
- .forEach(hookedCommand => {
2569
+ .filter((cmd) => cmd._lifeCycleHooks[event] !== undefined)
2570
+ .forEach((hookedCommand) => {
2392
2571
  hookedCommand._lifeCycleHooks[event].forEach((callback) => {
2393
2572
  hooks.push({ hookedCommand, callback });
2394
2573
  });
@@ -2444,14 +2623,26 @@ Expecting one of '${allowedValues.join("', '")}'`);
2444
2623
  if (operands && this._findCommand(operands[0])) {
2445
2624
  return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
2446
2625
  }
2447
- if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
2626
+ if (
2627
+ this._getHelpCommand() &&
2628
+ operands[0] === this._getHelpCommand().name()
2629
+ ) {
2448
2630
  return this._dispatchHelpCommand(operands[1]);
2449
2631
  }
2450
2632
  if (this._defaultCommandName) {
2451
2633
  this._outputHelpIfRequested(unknown); // Run the help for default command from parent rather than passing to default command
2452
- return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
2634
+ return this._dispatchSubcommand(
2635
+ this._defaultCommandName,
2636
+ operands,
2637
+ unknown,
2638
+ );
2453
2639
  }
2454
- if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
2640
+ if (
2641
+ this.commands.length &&
2642
+ this.args.length === 0 &&
2643
+ !this._actionHandler &&
2644
+ !this._defaultCommandName
2645
+ ) {
2455
2646
  // probably missing subcommand and no handler, user needs help (and exit)
2456
2647
  this.help({ error: true });
2457
2648
  }
@@ -2474,7 +2665,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
2474
2665
 
2475
2666
  let promiseChain;
2476
2667
  promiseChain = this._chainOrCallHooks(promiseChain, 'preAction');
2477
- promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
2668
+ promiseChain = this._chainOrCall(promiseChain, () =>
2669
+ this._actionHandler(this.processedArgs),
2670
+ );
2478
2671
  if (this.parent) {
2479
2672
  promiseChain = this._chainOrCall(promiseChain, () => {
2480
2673
  this.parent.emit(commandEvent, operands, unknown); // legacy
@@ -2488,7 +2681,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
2488
2681
  this._processArguments();
2489
2682
  this.parent.emit(commandEvent, operands, unknown); // legacy
2490
2683
  } else if (operands.length) {
2491
- if (this._findCommand('*')) { // legacy default command
2684
+ if (this._findCommand('*')) {
2685
+ // legacy default command
2492
2686
  return this._dispatchSubcommand('*', operands, unknown);
2493
2687
  }
2494
2688
  if (this.listenerCount('command:*')) {
@@ -2515,10 +2709,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2515
2709
  * Find matching command.
2516
2710
  *
2517
2711
  * @private
2712
+ * @return {Command | undefined}
2518
2713
  */
2519
2714
  _findCommand(name) {
2520
2715
  if (!name) return undefined;
2521
- return this.commands.find(cmd => cmd._name === name || cmd._aliases.includes(name));
2716
+ return this.commands.find(
2717
+ (cmd) => cmd._name === name || cmd._aliases.includes(name),
2718
+ );
2522
2719
  }
2523
2720
 
2524
2721
  /**
@@ -2526,11 +2723,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2526
2723
  *
2527
2724
  * @param {string} arg
2528
2725
  * @return {Option}
2529
- * @package internal use only
2726
+ * @package
2530
2727
  */
2531
2728
 
2532
2729
  _findOption(arg) {
2533
- return this.options.find(option => option.is(arg));
2730
+ return this.options.find((option) => option.is(arg));
2534
2731
  }
2535
2732
 
2536
2733
  /**
@@ -2544,7 +2741,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
2544
2741
  // Walk up hierarchy so can call in subcommand after checking for displaying help.
2545
2742
  this._getCommandAndAncestors().forEach((cmd) => {
2546
2743
  cmd.options.forEach((anOption) => {
2547
- if (anOption.mandatory && (cmd.getOptionValue(anOption.attributeName()) === undefined)) {
2744
+ if (
2745
+ anOption.mandatory &&
2746
+ cmd.getOptionValue(anOption.attributeName()) === undefined
2747
+ ) {
2548
2748
  cmd.missingMandatoryOptionValue(anOption);
2549
2749
  }
2550
2750
  });
@@ -2557,23 +2757,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
2557
2757
  * @private
2558
2758
  */
2559
2759
  _checkForConflictingLocalOptions() {
2560
- const definedNonDefaultOptions = this.options.filter(
2561
- (option) => {
2562
- const optionKey = option.attributeName();
2563
- if (this.getOptionValue(optionKey) === undefined) {
2564
- return false;
2565
- }
2566
- return this.getOptionValueSource(optionKey) !== 'default';
2760
+ const definedNonDefaultOptions = this.options.filter((option) => {
2761
+ const optionKey = option.attributeName();
2762
+ if (this.getOptionValue(optionKey) === undefined) {
2763
+ return false;
2567
2764
  }
2568
- );
2765
+ return this.getOptionValueSource(optionKey) !== 'default';
2766
+ });
2569
2767
 
2570
2768
  const optionsWithConflicting = definedNonDefaultOptions.filter(
2571
- (option) => option.conflictsWith.length > 0
2769
+ (option) => option.conflictsWith.length > 0,
2572
2770
  );
2573
2771
 
2574
2772
  optionsWithConflicting.forEach((option) => {
2575
2773
  const conflictingAndDefined = definedNonDefaultOptions.find((defined) =>
2576
- option.conflictsWith.includes(defined.attributeName())
2774
+ option.conflictsWith.includes(defined.attributeName()),
2577
2775
  );
2578
2776
  if (conflictingAndDefined) {
2579
2777
  this._conflictingOption(option, conflictingAndDefined);
@@ -2653,7 +2851,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
2653
2851
  value = args.shift();
2654
2852
  }
2655
2853
  this.emit(`option:${option.name()}`, value);
2656
- } else { // boolean flag
2854
+ } else {
2855
+ // boolean flag
2657
2856
  this.emit(`option:${option.name()}`);
2658
2857
  }
2659
2858
  activeVariadicOption = option.variadic ? option : null;
@@ -2665,7 +2864,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
2665
2864
  if (arg.length > 2 && arg[0] === '-' && arg[1] !== '-') {
2666
2865
  const option = this._findOption(`-${arg[1]}`);
2667
2866
  if (option) {
2668
- if (option.required || (option.optional && this._combineFlagAndOptionalValue)) {
2867
+ if (
2868
+ option.required ||
2869
+ (option.optional && this._combineFlagAndOptionalValue)
2870
+ ) {
2669
2871
  // option with value following in same argument
2670
2872
  this.emit(`option:${option.name()}`, arg.slice(2));
2671
2873
  } else {
@@ -2696,12 +2898,19 @@ Expecting one of '${allowedValues.join("', '")}'`);
2696
2898
  }
2697
2899
 
2698
2900
  // If using positionalOptions, stop processing our options at subcommand.
2699
- if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
2901
+ if (
2902
+ (this._enablePositionalOptions || this._passThroughOptions) &&
2903
+ operands.length === 0 &&
2904
+ unknown.length === 0
2905
+ ) {
2700
2906
  if (this._findCommand(arg)) {
2701
2907
  operands.push(arg);
2702
2908
  if (args.length > 0) unknown.push(...args);
2703
2909
  break;
2704
- } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
2910
+ } else if (
2911
+ this._getHelpCommand() &&
2912
+ arg === this._getHelpCommand().name()
2913
+ ) {
2705
2914
  operands.push(arg);
2706
2915
  if (args.length > 0) operands.push(...args);
2707
2916
  break;
@@ -2729,7 +2938,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2729
2938
  /**
2730
2939
  * Return an object containing local option values as key-value pairs.
2731
2940
  *
2732
- * @return {Object}
2941
+ * @return {object}
2733
2942
  */
2734
2943
  opts() {
2735
2944
  if (this._storeOptionsAsProperties) {
@@ -2739,7 +2948,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
2739
2948
 
2740
2949
  for (let i = 0; i < len; i++) {
2741
2950
  const key = this.options[i].attributeName();
2742
- result[key] = key === this._versionOptionName ? this._version : this[key];
2951
+ result[key] =
2952
+ key === this._versionOptionName ? this._version : this[key];
2743
2953
  }
2744
2954
  return result;
2745
2955
  }
@@ -2750,13 +2960,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2750
2960
  /**
2751
2961
  * Return an object containing merged local and global option values as key-value pairs.
2752
2962
  *
2753
- * @return {Object}
2963
+ * @return {object}
2754
2964
  */
2755
2965
  optsWithGlobals() {
2756
2966
  // globals overwrite locals
2757
2967
  return this._getCommandAndAncestors().reduce(
2758
2968
  (combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
2759
- {}
2969
+ {},
2760
2970
  );
2761
2971
  }
2762
2972
 
@@ -2764,13 +2974,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
2764
2974
  * Display error message and exit (or call exitOverride).
2765
2975
  *
2766
2976
  * @param {string} message
2767
- * @param {Object} [errorOptions]
2977
+ * @param {object} [errorOptions]
2768
2978
  * @param {string} [errorOptions.code] - an id string representing the error
2769
2979
  * @param {number} [errorOptions.exitCode] - used with process.exit
2770
2980
  */
2771
2981
  error(message, errorOptions) {
2772
2982
  // output handling
2773
- this._outputConfiguration.outputError(`${message}\n`, this._outputConfiguration.writeErr);
2983
+ this._outputConfiguration.outputError(
2984
+ `${message}\n`,
2985
+ this._outputConfiguration.writeErr,
2986
+ );
2774
2987
  if (typeof this._showHelpAfterError === 'string') {
2775
2988
  this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
2776
2989
  } else if (this._showHelpAfterError) {
@@ -2796,11 +3009,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
2796
3009
  if (option.envVar && option.envVar in process$1.env) {
2797
3010
  const optionKey = option.attributeName();
2798
3011
  // Priority check. Do not overwrite cli or options from unknown source (client-code).
2799
- if (this.getOptionValue(optionKey) === undefined || ['default', 'config', 'env'].includes(this.getOptionValueSource(optionKey))) {
2800
- if (option.required || option.optional) { // option can take a value
3012
+ if (
3013
+ this.getOptionValue(optionKey) === undefined ||
3014
+ ['default', 'config', 'env'].includes(
3015
+ this.getOptionValueSource(optionKey),
3016
+ )
3017
+ ) {
3018
+ if (option.required || option.optional) {
3019
+ // option can take a value
2801
3020
  // keep very simple, optional always takes value
2802
3021
  this.emit(`optionEnv:${option.name()}`, process$1.env[option.envVar]);
2803
- } else { // boolean
3022
+ } else {
3023
+ // boolean
2804
3024
  // keep very simple, only care that envVar defined and not the value
2805
3025
  this.emit(`optionEnv:${option.name()}`);
2806
3026
  }
@@ -2817,17 +3037,30 @@ Expecting one of '${allowedValues.join("', '")}'`);
2817
3037
  _parseOptionsImplied() {
2818
3038
  const dualHelper = new DualOptions(this.options);
2819
3039
  const hasCustomOptionValue = (optionKey) => {
2820
- return this.getOptionValue(optionKey) !== undefined && !['default', 'implied'].includes(this.getOptionValueSource(optionKey));
3040
+ return (
3041
+ this.getOptionValue(optionKey) !== undefined &&
3042
+ !['default', 'implied'].includes(this.getOptionValueSource(optionKey))
3043
+ );
2821
3044
  };
2822
3045
  this.options
2823
- .filter(option => (option.implied !== undefined) &&
2824
- hasCustomOptionValue(option.attributeName()) &&
2825
- dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option))
3046
+ .filter(
3047
+ (option) =>
3048
+ option.implied !== undefined &&
3049
+ hasCustomOptionValue(option.attributeName()) &&
3050
+ dualHelper.valueFromOption(
3051
+ this.getOptionValue(option.attributeName()),
3052
+ option,
3053
+ ),
3054
+ )
2826
3055
  .forEach((option) => {
2827
3056
  Object.keys(option.implied)
2828
- .filter(impliedKey => !hasCustomOptionValue(impliedKey))
2829
- .forEach(impliedKey => {
2830
- this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], 'implied');
3057
+ .filter((impliedKey) => !hasCustomOptionValue(impliedKey))
3058
+ .forEach((impliedKey) => {
3059
+ this.setOptionValueWithSource(
3060
+ impliedKey,
3061
+ option.implied[impliedKey],
3062
+ 'implied',
3063
+ );
2831
3064
  });
2832
3065
  });
2833
3066
  }
@@ -2881,12 +3114,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
2881
3114
  const findBestOptionFromValue = (option) => {
2882
3115
  const optionKey = option.attributeName();
2883
3116
  const optionValue = this.getOptionValue(optionKey);
2884
- const negativeOption = this.options.find(target => target.negate && optionKey === target.attributeName());
2885
- const positiveOption = this.options.find(target => !target.negate && optionKey === target.attributeName());
2886
- if (negativeOption && (
2887
- (negativeOption.presetArg === undefined && optionValue === false) ||
2888
- (negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)
2889
- )) {
3117
+ const negativeOption = this.options.find(
3118
+ (target) => target.negate && optionKey === target.attributeName(),
3119
+ );
3120
+ const positiveOption = this.options.find(
3121
+ (target) => !target.negate && optionKey === target.attributeName(),
3122
+ );
3123
+ if (
3124
+ negativeOption &&
3125
+ ((negativeOption.presetArg === undefined && optionValue === false) ||
3126
+ (negativeOption.presetArg !== undefined &&
3127
+ optionValue === negativeOption.presetArg))
3128
+ ) {
2890
3129
  return negativeOption;
2891
3130
  }
2892
3131
  return positiveOption || option;
@@ -2920,11 +3159,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
2920
3159
  if (flag.startsWith('--') && this._showSuggestionAfterError) {
2921
3160
  // Looping to pick up the global options too
2922
3161
  let candidateFlags = [];
3162
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
2923
3163
  let command = this;
2924
3164
  do {
2925
- const moreFlags = command.createHelp().visibleOptions(command)
2926
- .filter(option => option.long)
2927
- .map(option => option.long);
3165
+ const moreFlags = command
3166
+ .createHelp()
3167
+ .visibleOptions(command)
3168
+ .filter((option) => option.long)
3169
+ .map((option) => option.long);
2928
3170
  candidateFlags = candidateFlags.concat(moreFlags);
2929
3171
  command = command.parent;
2930
3172
  } while (command && !command._enablePositionalOptions);
@@ -2946,7 +3188,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2946
3188
  if (this._allowExcessArguments) return;
2947
3189
 
2948
3190
  const expected = this.registeredArguments.length;
2949
- const s = (expected === 1) ? '' : 's';
3191
+ const s = expected === 1 ? '' : 's';
2950
3192
  const forSubcommand = this.parent ? ` for '${this.name()}'` : '';
2951
3193
  const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
2952
3194
  this.error(message, { code: 'commander.excessArguments' });
@@ -2964,11 +3206,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2964
3206
 
2965
3207
  if (this._showSuggestionAfterError) {
2966
3208
  const candidateNames = [];
2967
- this.createHelp().visibleCommands(this).forEach((command) => {
2968
- candidateNames.push(command.name());
2969
- // just visible alias
2970
- if (command.alias()) candidateNames.push(command.alias());
2971
- });
3209
+ this.createHelp()
3210
+ .visibleCommands(this)
3211
+ .forEach((command) => {
3212
+ candidateNames.push(command.name());
3213
+ // just visible alias
3214
+ if (command.alias()) candidateNames.push(command.alias());
3215
+ });
2972
3216
  suggestion = suggestSimilar(unknownName, candidateNames);
2973
3217
  }
2974
3218
 
@@ -3009,11 +3253,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
3009
3253
  * Set the description.
3010
3254
  *
3011
3255
  * @param {string} [str]
3012
- * @param {Object} [argsDescription]
3256
+ * @param {object} [argsDescription]
3013
3257
  * @return {(string|Command)}
3014
3258
  */
3015
3259
  description(str, argsDescription) {
3016
- if (str === undefined && argsDescription === undefined) return this._description;
3260
+ if (str === undefined && argsDescription === undefined)
3261
+ return this._description;
3017
3262
  this._description = str;
3018
3263
  if (argsDescription) {
3019
3264
  this._argsDescription = argsDescription;
@@ -3046,18 +3291,27 @@ Expecting one of '${allowedValues.join("', '")}'`);
3046
3291
  if (alias === undefined) return this._aliases[0]; // just return first, for backwards compatibility
3047
3292
 
3048
3293
  /** @type {Command} */
3294
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3049
3295
  let command = this;
3050
- if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
3296
+ if (
3297
+ this.commands.length !== 0 &&
3298
+ this.commands[this.commands.length - 1]._executableHandler
3299
+ ) {
3051
3300
  // assume adding alias for last added executable subcommand, rather than this
3052
3301
  command = this.commands[this.commands.length - 1];
3053
3302
  }
3054
3303
 
3055
- if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');
3304
+ if (alias === command._name)
3305
+ throw new Error("Command alias can't be the same as its name");
3056
3306
  const matchingCommand = this.parent?._findCommand(alias);
3057
3307
  if (matchingCommand) {
3058
3308
  // c.f. _registerCommand
3059
- const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join('|');
3060
- throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
3309
+ const existingCmd = [matchingCommand.name()]
3310
+ .concat(matchingCommand.aliases())
3311
+ .join('|');
3312
+ throw new Error(
3313
+ `cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`,
3314
+ );
3061
3315
  }
3062
3316
 
3063
3317
  command._aliases.push(alias);
@@ -3095,11 +3349,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
3095
3349
  const args = this.registeredArguments.map((arg) => {
3096
3350
  return humanReadableArgName(arg);
3097
3351
  });
3098
- return [].concat(
3099
- (this.options.length || (this._helpOption !== null) ? '[options]' : []),
3100
- (this.commands.length ? '[command]' : []),
3101
- (this.registeredArguments.length ? args : [])
3102
- ).join(' ');
3352
+ return []
3353
+ .concat(
3354
+ this.options.length || this._helpOption !== null ? '[options]' : [],
3355
+ this.commands.length ? '[command]' : [],
3356
+ this.registeredArguments.length ? args : [],
3357
+ )
3358
+ .join(' ');
3103
3359
  }
3104
3360
 
3105
3361
  this._usage = str;
@@ -3166,7 +3422,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
3166
3422
  helpInformation(contextOptions) {
3167
3423
  const helper = this.createHelp();
3168
3424
  if (helper.helpWidth === undefined) {
3169
- helper.helpWidth = (contextOptions && contextOptions.error) ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
3425
+ helper.helpWidth =
3426
+ contextOptions && contextOptions.error
3427
+ ? this._outputConfiguration.getErrHelpWidth()
3428
+ : this._outputConfiguration.getOutHelpWidth();
3170
3429
  }
3171
3430
  return helper.formatHelp(this, helper);
3172
3431
  }
@@ -3205,13 +3464,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
3205
3464
  }
3206
3465
  const context = this._getHelpContext(contextOptions);
3207
3466
 
3208
- this._getCommandAndAncestors().reverse().forEach(command => command.emit('beforeAllHelp', context));
3467
+ this._getCommandAndAncestors()
3468
+ .reverse()
3469
+ .forEach((command) => command.emit('beforeAllHelp', context));
3209
3470
  this.emit('beforeHelp', context);
3210
3471
 
3211
3472
  let helpInformation = this.helpInformation(context);
3212
3473
  if (deprecatedCallback) {
3213
3474
  helpInformation = deprecatedCallback(helpInformation);
3214
- if (typeof helpInformation !== 'string' && !Buffer.isBuffer(helpInformation)) {
3475
+ if (
3476
+ typeof helpInformation !== 'string' &&
3477
+ !Buffer.isBuffer(helpInformation)
3478
+ ) {
3215
3479
  throw new Error('outputHelp callback must return a string or a Buffer');
3216
3480
  }
3217
3481
  }
@@ -3221,7 +3485,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3221
3485
  this.emit(this._getHelpOption().long); // deprecated
3222
3486
  }
3223
3487
  this.emit('afterHelp', context);
3224
- this._getCommandAndAncestors().forEach(command => command.emit('afterAllHelp', context));
3488
+ this._getCommandAndAncestors().forEach((command) =>
3489
+ command.emit('afterAllHelp', context),
3490
+ );
3225
3491
  }
3226
3492
 
3227
3493
  /**
@@ -3261,7 +3527,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3261
3527
  * Returns null if has been disabled with .helpOption(false).
3262
3528
  *
3263
3529
  * @returns {(Option | null)} the help option
3264
- * @package internal use only
3530
+ * @package
3265
3531
  */
3266
3532
  _getHelpOption() {
3267
3533
  // Lazy create help option on demand.
@@ -3294,7 +3560,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
3294
3560
  help(contextOptions) {
3295
3561
  this.outputHelp(contextOptions);
3296
3562
  let exitCode = process$1.exitCode || 0;
3297
- if (exitCode === 0 && contextOptions && typeof contextOptions !== 'function' && contextOptions.error) {
3563
+ if (
3564
+ exitCode === 0 &&
3565
+ contextOptions &&
3566
+ typeof contextOptions !== 'function' &&
3567
+ contextOptions.error
3568
+ ) {
3298
3569
  exitCode = 1;
3299
3570
  }
3300
3571
  // message: do not have all displayed text available so only passing placeholder.
@@ -3342,7 +3613,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3342
3613
 
3343
3614
  _outputHelpIfRequested(args) {
3344
3615
  const helpOption = this._getHelpOption();
3345
- const helpRequested = helpOption && args.find(arg => helpOption.is(arg));
3616
+ const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
3346
3617
  if (helpRequested) {
3347
3618
  this.outputHelp();
3348
3619
  // (Do not have all displayed text available so only passing placeholder.)
@@ -3375,7 +3646,9 @@ function incrementNodeInspectorPort(args) {
3375
3646
  if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
3376
3647
  // e.g. --inspect
3377
3648
  debugOption = match[1];
3378
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
3649
+ } else if (
3650
+ (match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null
3651
+ ) {
3379
3652
  debugOption = match[1];
3380
3653
  if (/^\d+$/.test(match[3])) {
3381
3654
  // e.g. --inspect=1234
@@ -3384,7 +3657,9 @@ function incrementNodeInspectorPort(args) {
3384
3657
  // e.g. --inspect=localhost
3385
3658
  debugHost = match[3];
3386
3659
  }
3387
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
3660
+ } else if (
3661
+ (match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null
3662
+ ) {
3388
3663
  // e.g. --inspect=localhost:1234
3389
3664
  debugOption = match[1];
3390
3665
  debugHost = match[3];
@@ -3437,11 +3712,17 @@ const {
3437
3712
  Command,
3438
3713
  Argument,
3439
3714
  Option,
3440
- Help
3715
+ Help,
3441
3716
  } = commander;
3442
3717
 
3443
- var version = "1.6.2";
3718
+ var version = "1.7.2";
3444
3719
 
3720
+ process.on("uncaughtException", function (error) {
3721
+ console.error(`${new Date().toISOString()} uncaughtException`, error);
3722
+ });
3723
+ process.on("unhandledRejection", function (error) {
3724
+ console.error(`${new Date().toISOString()} unhandledRejection`, error);
3725
+ });
3445
3726
  const program = new Command();
3446
3727
  program.name("biliLive").description("biliLive-tools命令行").version(version);
3447
3728
  program
@@ -3460,8 +3741,8 @@ program
3460
3741
  throw new Error(`${c.configFolder}参数不存在,请先重新运行 config gen 命令`);
3461
3742
  }
3462
3743
  // 下面两行顺序不能换(
3463
- const { init } = await Promise.resolve().then(function () { return require('./index-CSU11uxG.cjs'); }).then(function (n) { return n.index; });
3464
- const { serverStart } = await Promise.resolve().then(function () { return require('./index-BvslFWVg.cjs'); });
3744
+ const { init } = await Promise.resolve().then(function () { return require('./index-YWKX2VuK.cjs'); }).then(function (n) { return n.index; });
3745
+ const { serverStart } = await Promise.resolve().then(function () { return require('./index-D0TIaB9a.cjs'); });
3465
3746
  const globalConfig = {
3466
3747
  ffmpegPresetPath: path$1.join(c.configFolder, "ffmpeg_presets.json"),
3467
3748
  videoPresetPath: path$1.join(c.configFolder, "presets.json"),
@@ -3472,6 +3753,7 @@ program
3472
3753
  defaultFfprobePath: c.ffprobePath,
3473
3754
  defaultDanmakuFactoryPath: c.danmakuFactoryPath,
3474
3755
  version: version,
3756
+ userDataPath: c.configFolder,
3475
3757
  };
3476
3758
  const container = await init(globalConfig);
3477
3759
  const appConfig = container.resolve("appConfig");