js-style-kit 0.5.0 → 0.5.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.
@@ -97,7 +97,7 @@ var require_argument = __commonJS({
97
97
  this._name = name;
98
98
  break;
99
99
  }
100
- if (this._name.length > 3 && this._name.slice(-3) === "...") {
100
+ if (this._name.endsWith("...")) {
101
101
  this.variadic = true;
102
102
  this._name = this._name.slice(0, -3);
103
103
  }
@@ -113,11 +113,12 @@ var require_argument = __commonJS({
113
113
  /**
114
114
  * @package
115
115
  */
116
- _concatValue(value, previous) {
116
+ _collectValue(value, previous) {
117
117
  if (previous === this.defaultValue || !Array.isArray(previous)) {
118
118
  return [value];
119
119
  }
120
- return previous.concat(value);
120
+ previous.push(value);
121
+ return previous;
121
122
  }
122
123
  /**
123
124
  * Set the default value, and optionally supply the description to be displayed in the help.
@@ -156,7 +157,7 @@ var require_argument = __commonJS({
156
157
  );
157
158
  }
158
159
  if (this.variadic) {
159
- return this._concatValue(arg, previous);
160
+ return this._collectValue(arg, previous);
160
161
  }
161
162
  return arg;
162
163
  };
@@ -939,11 +940,12 @@ var require_option = __commonJS({
939
940
  /**
940
941
  * @package
941
942
  */
942
- _concatValue(value, previous) {
943
+ _collectValue(value, previous) {
943
944
  if (previous === this.defaultValue || !Array.isArray(previous)) {
944
945
  return [value];
945
946
  }
946
- return previous.concat(value);
947
+ previous.push(value);
948
+ return previous;
947
949
  }
948
950
  /**
949
951
  * Only allow option value to be one of choices.
@@ -960,7 +962,7 @@ var require_option = __commonJS({
960
962
  );
961
963
  }
962
964
  if (this.variadic) {
963
- return this._concatValue(arg, previous);
965
+ return this._collectValue(arg, previous);
964
966
  }
965
967
  return arg;
966
968
  };
@@ -1398,11 +1400,10 @@ var require_command = __commonJS({
1398
1400
  */
1399
1401
  configureOutput(configuration) {
1400
1402
  if (configuration === void 0) return this._outputConfiguration;
1401
- this._outputConfiguration = Object.assign(
1402
- {},
1403
- this._outputConfiguration,
1404
- configuration
1405
- );
1403
+ this._outputConfiguration = {
1404
+ ...this._outputConfiguration,
1405
+ ...configuration
1406
+ };
1406
1407
  return this;
1407
1408
  }
1408
1409
  /**
@@ -1512,7 +1513,7 @@ var require_command = __commonJS({
1512
1513
  */
1513
1514
  addArgument(argument) {
1514
1515
  const previousArgument = this.registeredArguments.slice(-1)[0];
1515
- if (previousArgument && previousArgument.variadic) {
1516
+ if (previousArgument?.variadic) {
1516
1517
  throw new Error(
1517
1518
  `only the last argument can be variadic '${previousArgument.name()}'`
1518
1519
  );
@@ -1778,7 +1779,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1778
1779
  if (val !== null && option.parseArg) {
1779
1780
  val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1780
1781
  } else if (val !== null && option.variadic) {
1781
- val = option._concatValue(val, oldValue);
1782
+ val = option._collectValue(val, oldValue);
1782
1783
  }
1783
1784
  if (val == null) {
1784
1785
  if (option.negate) {
@@ -2430,7 +2431,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2430
2431
  * @private
2431
2432
  */
2432
2433
  _chainOrCall(promise, fn) {
2433
- if (promise && promise.then && typeof promise.then === "function") {
2434
+ if (promise?.then && typeof promise.then === "function") {
2434
2435
  return promise.then(() => fn());
2435
2436
  }
2436
2437
  return fn();
@@ -2535,7 +2536,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2535
2536
  promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
2536
2537
  return promiseChain;
2537
2538
  }
2538
- if (this.parent && this.parent.listenerCount(commandEvent)) {
2539
+ if (this.parent?.listenerCount(commandEvent)) {
2539
2540
  checkForUnknownOptions();
2540
2541
  this._processArguments();
2541
2542
  this.parent.emit(commandEvent, operands, unknown);
@@ -2646,14 +2647,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2646
2647
  * sub --unknown uuu op => [sub], [--unknown uuu op]
2647
2648
  * sub -- --unknown uuu op => [sub --unknown uuu op], []
2648
2649
  *
2649
- * @param {string[]} argv
2650
+ * @param {string[]} args
2650
2651
  * @return {{operands: string[], unknown: string[]}}
2651
2652
  */
2652
- parseOptions(argv) {
2653
+ parseOptions(args) {
2653
2654
  const operands = [];
2654
2655
  const unknown = [];
2655
2656
  let dest = operands;
2656
- const args = argv.slice();
2657
2657
  function maybeOption(arg) {
2658
2658
  return arg.length > 1 && arg[0] === "-";
2659
2659
  }
@@ -2664,11 +2664,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
2664
2664
  );
2665
2665
  };
2666
2666
  let activeVariadicOption = null;
2667
- while (args.length) {
2668
- const arg = args.shift();
2667
+ let activeGroup = null;
2668
+ let i = 0;
2669
+ while (i < args.length || activeGroup) {
2670
+ const arg = activeGroup ?? args[i++];
2671
+ activeGroup = null;
2669
2672
  if (arg === "--") {
2670
2673
  if (dest === unknown) dest.push(arg);
2671
- dest.push(...args);
2674
+ dest.push(...args.slice(i));
2672
2675
  break;
2673
2676
  }
2674
2677
  if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
@@ -2680,13 +2683,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2680
2683
  const option = this._findOption(arg);
2681
2684
  if (option) {
2682
2685
  if (option.required) {
2683
- const value = args.shift();
2686
+ const value = args[i++];
2684
2687
  if (value === void 0) this.optionMissingArgument(option);
2685
2688
  this.emit(`option:${option.name()}`, value);
2686
2689
  } else if (option.optional) {
2687
2690
  let value = null;
2688
- if (args.length > 0 && (!maybeOption(args[0]) || negativeNumberArg(args[0]))) {
2689
- value = args.shift();
2691
+ if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
2692
+ value = args[i++];
2690
2693
  }
2691
2694
  this.emit(`option:${option.name()}`, value);
2692
2695
  } else {
@@ -2703,7 +2706,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2703
2706
  this.emit(`option:${option.name()}`, arg.slice(2));
2704
2707
  } else {
2705
2708
  this.emit(`option:${option.name()}`);
2706
- args.unshift(`-${arg.slice(2)}`);
2709
+ activeGroup = `-${arg.slice(2)}`;
2707
2710
  }
2708
2711
  continue;
2709
2712
  }
@@ -2722,21 +2725,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
2722
2725
  if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
2723
2726
  if (this._findCommand(arg)) {
2724
2727
  operands.push(arg);
2725
- if (args.length > 0) unknown.push(...args);
2728
+ unknown.push(...args.slice(i));
2726
2729
  break;
2727
2730
  } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
2728
- operands.push(arg);
2729
- if (args.length > 0) operands.push(...args);
2731
+ operands.push(arg, ...args.slice(i));
2730
2732
  break;
2731
2733
  } else if (this._defaultCommandName) {
2732
- unknown.push(arg);
2733
- if (args.length > 0) unknown.push(...args);
2734
+ unknown.push(arg, ...args.slice(i));
2734
2735
  break;
2735
2736
  }
2736
2737
  }
2737
2738
  if (this._passThroughOptions) {
2738
- dest.push(arg);
2739
- if (args.length > 0) dest.push(...args);
2739
+ dest.push(arg, ...args.slice(i));
2740
2740
  break;
2741
2741
  }
2742
2742
  dest.push(arg);