@bemoje/cli 2.1.3 → 2.1.5

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/index.mjs CHANGED
@@ -1,47 +1,36 @@
1
+ import C from 'ansi-colors';
2
+ import { isFunction, isString, isPrimitive } from 'es-toolkit/predicate';
3
+ import memoizee from 'memoizee';
4
+ import { ms } from 'enhanced-ms';
5
+ import { inspect, parseArgs } from 'util';
6
+ import { kebabCase } from 'es-toolkit/string';
7
+ import humanizeDuration from 'humanize-duration';
8
+ import { isPromise } from 'util/types';
9
+
1
10
  var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, { get: all[name], enumerable: true });
6
- };
7
- var __decorateClass = (decorators, target, key, kind) => {
8
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
9
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10
- if (decorator = decorators[i])
11
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
12
- if (kind && result) __defProp(target, key, result);
13
- return result;
11
+ var __name = (target, value) => {
12
+ return __defProp(target, 'name', { value, configurable: true });
14
13
  };
15
14
 
16
- // src/lib/Command.ts
17
- var Command_exports = {};
18
- __export(Command_exports, {
19
- Command: () => Command
20
- });
21
-
22
- // src/lib/Help.ts
23
- var Help_exports = {};
24
- __export(Help_exports, {
25
- Help: () => Help
26
- });
27
- import C from "ansi-colors";
28
-
29
15
  // ../decorators/src/assertDescriptorValueIsFunction.ts
30
16
  function assertDescriptorValueIsFunction(key, descriptor) {
31
- if (!(typeof descriptor.value === "function" && descriptor.value !== Function.prototype)) {
17
+ if (!(typeof descriptor.value === 'function' && descriptor.value !== Function.prototype)) {
32
18
  throw new TypeError(`"value" not a function for ${key} with descriptor: ${JSON.stringify(descriptor)}.`);
33
19
  }
34
20
  }
21
+ __name(assertDescriptorValueIsFunction, 'assertDescriptorValueIsFunction');
35
22
 
36
23
  // ../object/src/entriesOf.ts
37
24
  function entriesOf(obj) {
38
25
  return Object.entries(obj);
39
26
  }
27
+ __name(entriesOf, 'entriesOf');
40
28
 
41
29
  // ../object/src/keysOf.ts
42
30
  function keysOf(obj) {
43
31
  return Object.keys(obj);
44
32
  }
33
+ __name(keysOf, 'keysOf');
45
34
 
46
35
  // ../object/src/filterObject.ts
47
36
  function filterObject(obj, predicate) {
@@ -53,6 +42,7 @@ function filterObject(obj, predicate) {
53
42
  }
54
43
  return accum;
55
44
  }
45
+ __name(filterObject, 'filterObject');
56
46
 
57
47
  // ../object/src/objSortKeys.ts
58
48
  function objSortKeys(o, compare) {
@@ -66,11 +56,13 @@ function objSortKeys(o, compare) {
66
56
  }
67
57
  return Object.fromEntries(entries);
68
58
  }
59
+ __name(objSortKeys, 'objSortKeys');
69
60
 
70
61
  // ../object/src/valuesOf.ts
71
62
  function valuesOf(obj) {
72
63
  return Object.values(obj);
73
64
  }
65
+ __name(valuesOf, 'valuesOf');
74
66
 
75
67
  // ../map/src/mapGetOrDefault.ts
76
68
  function mapGetOrDefault(map, key, factory) {
@@ -82,16 +74,21 @@ function mapGetOrDefault(map, key, factory) {
82
74
  map.set(key, value);
83
75
  return value;
84
76
  }
77
+ __name(mapGetOrDefault, 'mapGetOrDefault');
85
78
 
86
79
  // ../map/src/TimeoutWeakMap.ts
87
80
  var TimeoutWeakMap = class {
81
+ static {
82
+ __name(this, 'TimeoutWeakMap');
83
+ }
84
+ timeoutMs;
85
+ wmap = /* @__PURE__ */ new WeakMap();
88
86
  /**
89
87
  * @param timeoutMs Default timeout in milliseconds for entries
90
88
  */
91
89
  constructor(timeoutMs) {
92
90
  this.timeoutMs = timeoutMs;
93
91
  }
94
- wmap = /* @__PURE__ */ new WeakMap();
95
92
  /**
96
93
  * Retrieves the value for the given key and refreshes its timeout.
97
94
  *
@@ -120,7 +117,7 @@ var TimeoutWeakMap = class {
120
117
  value,
121
118
  setTimeout(() => {
122
119
  this.delete(key);
123
- }, timeoutMs ?? this.timeoutMs).unref()
120
+ }, timeoutMs ?? this.timeoutMs).unref(),
124
121
  ]);
125
122
  return this;
126
123
  }
@@ -194,28 +191,29 @@ var TimeoutWeakMap = class {
194
191
  }
195
192
  }
196
193
  };
197
-
198
- // ../decorators/src/lazyProp.ts
199
- import { isFunction } from "es-toolkit/predicate";
200
-
201
- // ../decorators/src/memoizeSync.ts
202
- import memoizee from "memoizee";
203
- import { ms } from "enhanced-ms";
204
194
  function memoizeSync(arg = {}) {
205
- const opts = typeof arg === "object" ? arg : { maxAge: typeof arg === "number" ? arg : ms(arg) };
206
- return function decorator(target, key, descriptor) {
195
+ const opts =
196
+ typeof arg === 'object'
197
+ ? arg
198
+ : {
199
+ maxAge: typeof arg === 'number' ? arg : ms(arg),
200
+ };
201
+ return /* @__PURE__ */ __name(function decorator(target, key, descriptor) {
207
202
  if (!descriptor) {
208
- throw new TypeError("descriptor is undefined");
203
+ throw new TypeError('descriptor is undefined');
209
204
  }
210
205
  const orig = descriptor.value;
211
206
  assertDescriptorValueIsFunction(key, descriptor);
212
- const options = { length: false, ...opts };
207
+ const options = {
208
+ length: false,
209
+ ...opts,
210
+ };
213
211
  if (opts.instancesShareCache) {
214
- Reflect.deleteProperty(options, "instancesShareCache");
212
+ Reflect.deleteProperty(options, 'instancesShareCache');
215
213
  descriptor.value = memoizee(orig, options);
216
214
  } else {
217
215
  const wmap = /* @__PURE__ */ new WeakMap();
218
- descriptor.value = function(...args) {
216
+ descriptor.value = function (...args) {
219
217
  const memoized = mapGetOrDefault(wmap, this, () => {
220
218
  return memoizee(orig, options);
221
219
  });
@@ -223,25 +221,24 @@ function memoizeSync(arg = {}) {
223
221
  };
224
222
  }
225
223
  return descriptor;
226
- };
224
+ }, 'decorator');
227
225
  }
228
-
229
- // ../decorators/src/lazyProp.ts
230
- import { ms as ms2 } from "enhanced-ms";
226
+ __name(memoizeSync, 'memoizeSync');
231
227
  function lazyProp(targetOrTimeout, key, descriptor) {
232
- if (typeof targetOrTimeout === "number" || typeof targetOrTimeout === "string") {
233
- const maxAge = typeof targetOrTimeout === "number" ? targetOrTimeout : ms2(targetOrTimeout);
228
+ if (typeof targetOrTimeout === 'number' || typeof targetOrTimeout === 'string') {
229
+ const maxAge = typeof targetOrTimeout === 'number' ? targetOrTimeout : ms(targetOrTimeout);
234
230
  return createLazyPropDecorator(new TimeoutWeakMap(maxAge));
235
231
  } else {
236
232
  const decorator = createLazyPropDecorator(/* @__PURE__ */ new WeakMap());
237
233
  return decorator(targetOrTimeout, key, descriptor);
238
234
  }
239
235
  }
236
+ __name(lazyProp, 'lazyProp');
240
237
  function createLazyPropDecorator(map) {
241
- return function(target, key, descriptor) {
238
+ return function (target, key, descriptor) {
242
239
  const { get, value } = descriptor;
243
240
  if (isFunction(get)) {
244
- descriptor.get = function() {
241
+ descriptor.get = function () {
245
242
  return mapGetOrDefault(map, this, () => {
246
243
  return get.call(this);
247
244
  });
@@ -254,21 +251,52 @@ function createLazyPropDecorator(map) {
254
251
  throw new TypeError('neither "get" nor "value" are functions');
255
252
  };
256
253
  }
254
+ __name(createLazyPropDecorator, 'createLazyPropDecorator');
257
255
 
258
256
  // src/lib/Help.ts
257
+ function _ts_decorate(decorators, target, key, desc) {
258
+ var c = arguments.length,
259
+ r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
260
+ d;
261
+ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') {
262
+ r = Reflect.decorate(decorators, target, key, desc);
263
+ } else {
264
+ for (var i = decorators.length - 1; i >= 0; i--) {
265
+ if ((d = decorators[i])) {
266
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
267
+ }
268
+ }
269
+ }
270
+ return (c > 3 && r && Object.defineProperty(target, key, r), r);
271
+ }
272
+ __name(_ts_decorate, '_ts_decorate');
273
+ function _ts_metadata(k, v) {
274
+ if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function') {
275
+ return Reflect.metadata(k, v);
276
+ }
277
+ }
278
+ __name(_ts_metadata, '_ts_metadata');
259
279
  var Help = class {
280
+ static {
281
+ __name(this, 'Help');
282
+ }
260
283
  cmd;
261
284
  /** output helpWidth, long lines are wrapped to fit */
262
285
  helpWidth = process.stdout.isTTY ? process.stdout.columns : 80;
263
286
  minWidthToWrap = 40;
264
287
  sortSubcommands = true;
265
288
  sortOptions = true;
266
- usageDisplayOptionsAs = "[opts]";
267
- usageDisplaySubcommandAs = "[cmd]";
289
+ usageDisplayOptionsAs = '[opts]';
290
+ usageDisplaySubcommandAs = '[cmd]';
268
291
  constructor(cmd) {
269
292
  this.cmd = cmd;
270
- Object.defineProperty(this, "cmd", { enumerable: false });
293
+ Object.defineProperty(this, 'cmd', {
294
+ enumerable: false,
295
+ });
271
296
  }
297
+ /**
298
+ * Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
299
+ */
272
300
  visibleCommands() {
273
301
  const res = Object.values(this.cmd.commands).filter((c) => {
274
302
  return !c.hidden;
@@ -284,11 +312,14 @@ var Help = class {
284
312
  * Compare options for sort.
285
313
  */
286
314
  compareOptions(a, b) {
287
- const getSortKey = (option) => {
288
- return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
289
- };
315
+ const getSortKey = /* @__PURE__ */ __name((option) => {
316
+ return option.short ? option.short.replace(/^-/, '') : option.long.replace(/^--/, '');
317
+ }, 'getSortKey');
290
318
  return getSortKey(a).localeCompare(getSortKey(b));
291
319
  }
320
+ /**
321
+ * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
322
+ */
292
323
  visibleOptions() {
293
324
  const res = this.cmd.options.filter((option) => {
294
325
  return !option.hidden;
@@ -298,6 +329,9 @@ var Help = class {
298
329
  }
299
330
  return res;
300
331
  }
332
+ /**
333
+ * Get an array of the arguments if any have a description.
334
+ */
301
335
  visibleArguments() {
302
336
  return this.cmd.arguments.slice();
303
337
  }
@@ -305,11 +339,17 @@ var Help = class {
305
339
  * Get the command term to show in the list of subcommands.
306
340
  */
307
341
  subcommandTerm(sub) {
308
- const args = sub.arguments.map((arg) => {
309
- return arg.usage;
310
- }).join(" ");
311
- return (sub.aliases[0] ? `${sub.aliases[0].padEnd(this.longestSubcommandAliasLength(), " ")} | ` : "") + sub.name + (sub.options.length ? ` ${this.usageDisplayOptionsAs}` : "") + // simplistic check for non-help option
312
- (args ? ` ${args}` : "");
342
+ const args = sub.arguments
343
+ .map((arg) => {
344
+ return arg.usage;
345
+ })
346
+ .join(' ');
347
+ return (
348
+ (sub.aliases[0] ? `${sub.aliases[0].padEnd(this.longestSubcommandAliasLength(), ' ')} | ` : '') +
349
+ sub.name +
350
+ (sub.options.length ? ` ${this.usageDisplayOptionsAs}` : '') + // simplistic check for non-help option
351
+ (args ? ` ${args}` : '')
352
+ );
313
353
  }
314
354
  /**
315
355
  * Get the option term to show in the list of options.
@@ -323,24 +363,36 @@ var Help = class {
323
363
  argumentTerm(argument) {
324
364
  return argument.usage;
325
365
  }
366
+ /**
367
+ * Get the longest subcommand primary alias length.
368
+ */
326
369
  longestSubcommandAliasLength() {
327
370
  return Math.max(
328
371
  0,
329
372
  ...this.visibleCommands().map((c) => {
330
373
  return c.aliases[0]?.length || 0;
331
- })
374
+ }),
332
375
  );
333
376
  }
377
+ /**
378
+ * Get the longest subcommand term length.
379
+ */
334
380
  longestSubcommandTermLength() {
335
381
  return this.visibleCommands().reduce((max, command) => {
336
382
  return Math.max(max, this.displayWidth(this.styleSubcommandTerm(this.subcommandTerm(command))));
337
383
  }, 0);
338
384
  }
385
+ /**
386
+ * Get the longest option term length.
387
+ */
339
388
  longestOptionTermLength() {
340
389
  return this.visibleOptions().reduce((max, option) => {
341
390
  return Math.max(max, this.displayWidth(this.styleOptionTerm(this.optionTerm(option))));
342
391
  }, 0);
343
392
  }
393
+ /**
394
+ * Get the longest argument term length.
395
+ */
344
396
  longestArgumentTermLength() {
345
397
  return this.visibleArguments().reduce((max, argument) => {
346
398
  return Math.max(max, this.displayWidth(this.styleArgumentTerm(this.argumentTerm(argument))));
@@ -350,26 +402,32 @@ var Help = class {
350
402
  * Get the command usage to be displayed at the top of the built-in help.
351
403
  */
352
404
  commandUsage() {
353
- let path = "";
405
+ let path = '';
354
406
  for (let ancestor = this.cmd.parent; ancestor; ancestor = ancestor.parent) {
355
407
  path = `${ancestor.name} ${path}`;
356
408
  }
357
409
  return `${path + this.cmd.name} ${[
358
- ...Object.keys(this.cmd.commands).length ? [this.usageDisplaySubcommandAs] : [],
359
- ...this.cmd.options.length ? [this.usageDisplayOptionsAs] : [],
410
+ ...(Object.keys(this.cmd.commands).length ? [this.usageDisplaySubcommandAs] : []),
411
+ ...(this.cmd.options.length ? [this.usageDisplayOptionsAs] : []),
360
412
  ...this.cmd.arguments.map((arg) => {
361
- return arg.required ? arg.variadic ? `<${arg.name}...>` : `<${arg.name}>` : arg.variadic ? `[${arg.name}...]` : `[${arg.name}]`;
362
- })
363
- ].join(" ")}`.trim();
413
+ return arg.required
414
+ ? arg.variadic
415
+ ? `<${arg.name}...>`
416
+ : `<${arg.name}>`
417
+ : arg.variadic
418
+ ? `[${arg.name}...]`
419
+ : `[${arg.name}]`;
420
+ }),
421
+ ].join(' ')}`.trim();
364
422
  }
365
423
  /**
366
424
  * Get the description for the command.
367
425
  */
368
426
  commandDescription() {
369
- let res = "";
427
+ let res = '';
370
428
  if (this.cmd.aliases.length) {
371
- res += `Aliases: ${this.cmd.aliases.join(", ")}`;
372
- res += "\n\n";
429
+ res += `Aliases: ${this.cmd.aliases.join(', ')}`;
430
+ res += '\n\n';
373
431
  }
374
432
  res += this.cmd.description;
375
433
  return res;
@@ -379,7 +437,10 @@ var Help = class {
379
437
  * (Fallback to description for backwards compatibility.)
380
438
  */
381
439
  subcommandDescription(sub) {
382
- return sub.summary || (sub.description?.includes("\n") ? sub.description.trim().split("\n")[0] : sub.description.trim());
440
+ return (
441
+ sub.summary ||
442
+ (sub.description?.includes('\n') ? sub.description.trim().split('\n')[0] : sub.description.trim())
443
+ );
383
444
  }
384
445
  /**
385
446
  * Get the option description to show in the list of options.
@@ -389,9 +450,11 @@ var Help = class {
389
450
  if (option.choices) {
390
451
  extraInfo.push(
391
452
  // use stringify to match the display of the default value
392
- `choices: ${option.choices.map((choice) => {
393
- return String(choice);
394
- }).join(", ")}`
453
+ `choices: ${option.choices
454
+ .map((choice) => {
455
+ return String(choice);
456
+ })
457
+ .join(', ')}`,
395
458
  );
396
459
  }
397
460
  if (option.defaultValue && !(Array.isArray(option.defaultValue) && option.defaultValue.length === 0)) {
@@ -401,13 +464,13 @@ var Help = class {
401
464
  extraInfo.push(`env: ${option.env}`);
402
465
  }
403
466
  if (extraInfo.length > 0) {
404
- const extraDescription = `(${extraInfo.join(", ")})`;
467
+ const extraDescription = `(${extraInfo.join(', ')})`;
405
468
  if (option.description) {
406
469
  return `${option.description} ${extraDescription}`;
407
470
  }
408
471
  return extraDescription;
409
472
  }
410
- return option.description ?? "";
473
+ return option.description ?? '';
411
474
  }
412
475
  /**
413
476
  * Get the argument description to show in the list of arguments.
@@ -417,22 +480,24 @@ var Help = class {
417
480
  if (argument.choices) {
418
481
  extraInfo.push(
419
482
  // use stringify to match the display of the default value
420
- `choices: ${argument.choices.map((choice) => {
421
- return String(choice);
422
- }).join(", ")}`
483
+ `choices: ${argument.choices
484
+ .map((choice) => {
485
+ return String(choice);
486
+ })
487
+ .join(', ')}`,
423
488
  );
424
489
  }
425
490
  if (argument.defaultValue && !(Array.isArray(argument.defaultValue) && argument.defaultValue.length === 0)) {
426
491
  extraInfo.push(`default: ${argument.defaultValueDescription || String(argument.defaultValue)}`);
427
492
  }
428
493
  if (extraInfo.length > 0) {
429
- const extraDescription = `(${extraInfo.join(", ")})`;
494
+ const extraDescription = `(${extraInfo.join(', ')})`;
430
495
  if (argument.description) {
431
496
  return `${argument.description} ${extraDescription}`;
432
497
  }
433
498
  return extraDescription;
434
499
  }
435
- return argument.description ?? "";
500
+ return argument.description ?? '';
436
501
  }
437
502
  /**
438
503
  * Format a list of items, given a heading and an array of formatted items.
@@ -441,7 +506,7 @@ var Help = class {
441
506
  if (items.length === 0) {
442
507
  return [];
443
508
  }
444
- return [this.styleTitle(heading), ...items, ""];
509
+ return [this.styleTitle(heading), ...items, ''];
445
510
  }
446
511
  /**
447
512
  * Group items by their help group heading.
@@ -468,7 +533,7 @@ var Help = class {
468
533
  */
469
534
  displayWidth(str) {
470
535
  const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
471
- return str.replace(sgrPattern, "").length;
536
+ return str.replace(sgrPattern, '').length;
472
537
  }
473
538
  /**
474
539
  * Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
@@ -480,24 +545,27 @@ var Help = class {
480
545
  * Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
481
546
  */
482
547
  styleUsage(str) {
483
- return str.split(" ").map((word, index, arr) => {
484
- if (word === this.usageDisplaySubcommandAs) {
485
- return C.green(word);
486
- }
487
- if (word === this.usageDisplayOptionsAs) {
488
- return C.blue(word);
489
- }
490
- if (word[0] === "<") {
491
- return C.red(word);
492
- }
493
- if (word[0] === "[") {
494
- return C.cyan(word);
495
- }
496
- if (arr[index + 1]?.startsWith("[")) {
497
- return C.magenta(word);
498
- }
499
- return this.styleCommandText(word);
500
- }).join(" ");
548
+ return str
549
+ .split(' ')
550
+ .map((word, index, arr) => {
551
+ if (word === this.usageDisplaySubcommandAs) {
552
+ return C.green(word);
553
+ }
554
+ if (word === this.usageDisplayOptionsAs) {
555
+ return C.blue(word);
556
+ }
557
+ if (word[0] === '<') {
558
+ return C.red(word);
559
+ }
560
+ if (word[0] === '[') {
561
+ return C.cyan(word);
562
+ }
563
+ if (arr[index + 1]?.startsWith('[')) {
564
+ return C.magenta(word);
565
+ }
566
+ return this.styleCommandText(word);
567
+ })
568
+ .join(' ');
501
569
  }
502
570
  /**
503
571
  * Style command descriptions for display in help output.
@@ -539,21 +607,24 @@ var Help = class {
539
607
  * Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
540
608
  */
541
609
  styleSubcommandTerm(str) {
542
- const res = str.split(" ").map((word) => {
543
- if (word === this.usageDisplayOptionsAs) {
544
- return C.dim(word);
545
- }
546
- if (word[0] === "[" || word[0] === "<") {
547
- return C.dim(word);
548
- }
549
- return this.styleSubcommandText(word);
550
- }).join(" ");
551
- const split = res.split("|");
610
+ const res = str
611
+ .split(' ')
612
+ .map((word) => {
613
+ if (word === this.usageDisplayOptionsAs) {
614
+ return C.dim(word);
615
+ }
616
+ if (word[0] === '[' || word[0] === '<') {
617
+ return C.dim(word);
618
+ }
619
+ return this.styleSubcommandText(word);
620
+ })
621
+ .join(' ');
622
+ const split = res.split('|');
552
623
  if (split.length === 1) {
553
624
  return res;
554
625
  }
555
626
  split[0] = C.green(split[0]);
556
- return split.join("|");
627
+ return split.join('|');
557
628
  }
558
629
  /**
559
630
  * Style argument terms for display in help output.
@@ -585,11 +656,14 @@ var Help = class {
585
656
  styleCommandText(str) {
586
657
  return str;
587
658
  }
659
+ /**
660
+ * Calculate the pad width from the maximum term length.
661
+ */
588
662
  padWidth() {
589
663
  return Math.max(
590
664
  this.longestOptionTermLength(),
591
665
  this.longestSubcommandTermLength(),
592
- this.longestArgumentTermLength()
666
+ this.longestArgumentTermLength(),
593
667
  );
594
668
  }
595
669
  /**
@@ -607,7 +681,7 @@ var Help = class {
607
681
  */
608
682
  formatItem(term, termWidth, description) {
609
683
  const itemIndent = 2;
610
- const itemIndentStr = " ".repeat(itemIndent);
684
+ const itemIndentStr = ' '.repeat(itemIndent);
611
685
  if (!description) {
612
686
  return itemIndentStr + term;
613
687
  }
@@ -620,11 +694,22 @@ var Help = class {
620
694
  formattedDescription = description;
621
695
  } else {
622
696
  const wrappedDescription = this.boxWrap(description, remainingWidth);
623
- formattedDescription = wrappedDescription.replace(/\n/g, `
624
- ${" ".repeat(termWidth + spacerWidth)}`);
697
+ formattedDescription = wrappedDescription.replace(
698
+ /\n/g,
699
+ `
700
+ ${' '.repeat(termWidth + spacerWidth)}`,
701
+ );
625
702
  }
626
- return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
627
- ${itemIndentStr}`);
703
+ return (
704
+ itemIndentStr +
705
+ paddedTerm +
706
+ ' '.repeat(spacerWidth) +
707
+ formattedDescription.replace(
708
+ /\n/g,
709
+ `
710
+ ${itemIndentStr}`,
711
+ )
712
+ );
628
713
  }
629
714
  /**
630
715
  * Wrap a string at whitespace, preserving existing line breaks.
@@ -640,7 +725,7 @@ ${itemIndentStr}`);
640
725
  rawLines.forEach((line) => {
641
726
  const chunks = line.match(chunkPattern);
642
727
  if (chunks === null) {
643
- wrappedLines.push("");
728
+ wrappedLines.push('');
644
729
  return;
645
730
  }
646
731
  let sumChunks = [chunks.shift()];
@@ -652,119 +737,181 @@ ${itemIndentStr}`);
652
737
  sumWidth += visibleWidth;
653
738
  return;
654
739
  }
655
- wrappedLines.push(sumChunks.join(""));
740
+ wrappedLines.push(sumChunks.join(''));
656
741
  const nextChunk = chunk.trimStart();
657
742
  sumChunks = [nextChunk];
658
743
  sumWidth = this.displayWidth(nextChunk);
659
744
  });
660
- wrappedLines.push(sumChunks.join(""));
745
+ wrappedLines.push(sumChunks.join(''));
661
746
  });
662
- return wrappedLines.join("\n");
747
+ return wrappedLines.join('\n');
663
748
  }
664
749
  /**
665
750
  * Generate the built-in help text.
666
751
  */
667
752
  render() {
668
- let output = [`${this.styleTitle("Usage:")} ${this.styleUsage(this.commandUsage())}`, ""];
753
+ let output = [`${this.styleTitle('Usage:')} ${this.styleUsage(this.commandUsage())}`, ''];
669
754
  const des = this.commandDescription();
670
755
  if (des.length > 0) {
671
- output = output.concat([this.boxWrap(this.styleCommandDescription(des), this.helpWidth), ""]);
756
+ output = output.concat([this.boxWrap(this.styleCommandDescription(des), this.helpWidth), '']);
672
757
  }
673
758
  const argumentList = this.visibleArguments().map((argument) => {
674
759
  return this.formatItem(
675
760
  this.styleArgumentTerm(this.argumentTerm(argument)),
676
761
  this.padWidth(),
677
- this.styleArgumentDescription(this.argumentDescription(argument))
762
+ this.styleArgumentDescription(this.argumentDescription(argument)),
678
763
  );
679
764
  });
680
- output = output.concat(this.formatItemList("Arguments:", argumentList));
765
+ output = output.concat(this.formatItemList('Arguments:', argumentList));
681
766
  const optionGroups = this.groupItems(this.cmd.options, this.visibleOptions(), (option) => {
682
- return option.group ?? "Options:";
767
+ return option.group ?? 'Options:';
683
768
  });
684
769
  optionGroups.forEach((options, group) => {
685
770
  const optionList = options.map((option) => {
686
771
  return this.formatItem(
687
772
  this.styleOptionTerm(this.optionTerm(option)),
688
773
  this.padWidth(),
689
- this.styleOptionDescription(this.optionDescription(option))
774
+ this.styleOptionDescription(this.optionDescription(option)),
690
775
  );
691
776
  });
692
777
  output = output.concat(this.formatItemList(group, optionList));
693
778
  });
694
- const commandGroups = this.groupItems(
695
- Object.values(this.cmd.commands),
696
- this.visibleCommands(),
697
- (sub) => {
698
- return sub.group || "Commands:";
699
- }
700
- );
779
+ const commandGroups = this.groupItems(Object.values(this.cmd.commands), this.visibleCommands(), (sub) => {
780
+ return sub.group || 'Commands:';
781
+ });
701
782
  commandGroups.forEach((commands, group) => {
702
783
  const commandList = commands.map((sub) => {
703
784
  return this.formatItem(
704
785
  this.styleSubcommandTerm(this.subcommandTerm(sub)),
705
786
  this.padWidth(),
706
- this.styleSubcommandDescription(this.subcommandDescription(sub))
787
+ this.styleSubcommandDescription(this.subcommandDescription(sub)),
707
788
  );
708
789
  });
709
790
  output = output.concat(this.formatItemList(group, commandList));
710
791
  });
711
- return output.join("\n");
792
+ return output.join('\n');
712
793
  }
713
794
  };
714
- __decorateClass([
715
- lazyProp
716
- ], Help.prototype, "visibleCommands", 1);
717
- __decorateClass([
718
- lazyProp
719
- ], Help.prototype, "visibleOptions", 1);
720
- __decorateClass([
721
- lazyProp
722
- ], Help.prototype, "visibleArguments", 1);
723
- __decorateClass([
724
- lazyProp
725
- ], Help.prototype, "longestSubcommandAliasLength", 1);
726
- __decorateClass([
727
- lazyProp
728
- ], Help.prototype, "longestSubcommandTermLength", 1);
729
- __decorateClass([
730
- lazyProp
731
- ], Help.prototype, "longestOptionTermLength", 1);
732
- __decorateClass([
733
- lazyProp
734
- ], Help.prototype, "longestArgumentTermLength", 1);
735
- __decorateClass([
736
- lazyProp
737
- ], Help.prototype, "padWidth", 1);
795
+ _ts_decorate(
796
+ [
797
+ lazyProp,
798
+ _ts_metadata('design:type', Function),
799
+ _ts_metadata('design:paramtypes', []),
800
+ _ts_metadata('design:returntype', Array),
801
+ ],
802
+ Help.prototype,
803
+ 'visibleCommands',
804
+ null,
805
+ );
806
+ _ts_decorate(
807
+ [
808
+ lazyProp,
809
+ _ts_metadata('design:type', Function),
810
+ _ts_metadata('design:paramtypes', []),
811
+ _ts_metadata('design:returntype', Array),
812
+ ],
813
+ Help.prototype,
814
+ 'visibleOptions',
815
+ null,
816
+ );
817
+ _ts_decorate(
818
+ [
819
+ lazyProp,
820
+ _ts_metadata('design:type', Function),
821
+ _ts_metadata('design:paramtypes', []),
822
+ _ts_metadata('design:returntype', Array),
823
+ ],
824
+ Help.prototype,
825
+ 'visibleArguments',
826
+ null,
827
+ );
828
+ _ts_decorate(
829
+ [
830
+ lazyProp,
831
+ _ts_metadata('design:type', Function),
832
+ _ts_metadata('design:paramtypes', []),
833
+ _ts_metadata('design:returntype', Number),
834
+ ],
835
+ Help.prototype,
836
+ 'longestSubcommandAliasLength',
837
+ null,
838
+ );
839
+ _ts_decorate(
840
+ [
841
+ lazyProp,
842
+ _ts_metadata('design:type', Function),
843
+ _ts_metadata('design:paramtypes', []),
844
+ _ts_metadata('design:returntype', Number),
845
+ ],
846
+ Help.prototype,
847
+ 'longestSubcommandTermLength',
848
+ null,
849
+ );
850
+ _ts_decorate(
851
+ [
852
+ lazyProp,
853
+ _ts_metadata('design:type', Function),
854
+ _ts_metadata('design:paramtypes', []),
855
+ _ts_metadata('design:returntype', Number),
856
+ ],
857
+ Help.prototype,
858
+ 'longestOptionTermLength',
859
+ null,
860
+ );
861
+ _ts_decorate(
862
+ [
863
+ lazyProp,
864
+ _ts_metadata('design:type', Function),
865
+ _ts_metadata('design:paramtypes', []),
866
+ _ts_metadata('design:returntype', Number),
867
+ ],
868
+ Help.prototype,
869
+ 'longestArgumentTermLength',
870
+ null,
871
+ );
872
+ _ts_decorate(
873
+ [
874
+ lazyProp,
875
+ _ts_metadata('design:type', Function),
876
+ _ts_metadata('design:paramtypes', []),
877
+ _ts_metadata('design:returntype', Number),
878
+ ],
879
+ Help.prototype,
880
+ 'padWidth',
881
+ null,
882
+ );
738
883
 
739
- // ../array/src/arrLast.ts
884
+ // ../array/src/lib/arrLast.ts
740
885
  function arrLast(array) {
741
886
  if (!array.length) {
742
- throw new Error("Cannot get last element of empty array.");
887
+ throw new Error('Cannot get last element of empty array.');
743
888
  }
744
889
  return array[array.length - 1];
745
890
  }
891
+ __name(arrLast, 'arrLast');
746
892
 
747
- // ../array/src/arrRemoveDuplicates.ts
893
+ // ../array/src/lib/arrRemoveDuplicates.ts
748
894
  function arrRemoveDuplicates(array) {
749
895
  return Array.from(new Set(array));
750
896
  }
897
+ __name(arrRemoveDuplicates, 'arrRemoveDuplicates');
751
898
 
752
899
  // src/lib/internal/collectVariadicOptionValues.ts
753
900
  function collectVariadicOptionValues(parsed, options) {
754
901
  for (let i = 0; i < parsed.tokens.length; i++) {
755
902
  const token = parsed.tokens[i];
756
- if (token.kind !== "option") {
903
+ if (token.kind !== 'option') {
757
904
  continue;
758
905
  }
759
906
  const def = options.find((o) => {
760
907
  return o.name === token.name;
761
908
  });
762
- if (!def?.variadic || def.type !== "string") {
909
+ if (!def?.variadic || def.type !== 'string') {
763
910
  continue;
764
911
  }
765
912
  const values = [token.value];
766
913
  let j = i + 1;
767
- while (j < parsed.tokens.length && parsed.tokens[j].kind === "positional") {
914
+ while (j < parsed.tokens.length && parsed.tokens[j].kind === 'positional') {
768
915
  const positionalToken = parsed.tokens[j];
769
916
  values.push(positionalToken.value);
770
917
  const posIndex = parsed.positionals.indexOf(positionalToken.value);
@@ -778,51 +925,40 @@ function collectVariadicOptionValues(parsed, options) {
778
925
  token.name,
779
926
  values.filter((v) => {
780
927
  return v !== void 0;
781
- })
928
+ }),
782
929
  );
783
930
  }
784
931
  }
785
-
786
- // src/lib/Command.ts
787
- import colors3 from "ansi-colors";
932
+ __name(collectVariadicOptionValues, 'collectVariadicOptionValues');
788
933
 
789
934
  // src/lib/helpers/findCommand.ts
790
- var findCommand_exports = {};
791
- __export(findCommand_exports, {
792
- findCommand: () => findCommand
793
- });
794
935
  function findCommand(cmd, nameOrAlias) {
795
- return cmd.commands[nameOrAlias] ?? valuesOf(cmd.commands).find((c) => {
796
- return c.aliases.includes(nameOrAlias);
797
- });
936
+ return (
937
+ cmd.commands[nameOrAlias] ??
938
+ valuesOf(cmd.commands).find((c) => {
939
+ return c.aliases.includes(nameOrAlias);
940
+ })
941
+ );
798
942
  }
943
+ __name(findCommand, 'findCommand');
799
944
 
800
945
  // src/lib/helpers/findOption.ts
801
- var findOption_exports = {};
802
- __export(findOption_exports, {
803
- findOption: () => findOption
804
- });
805
946
  function findOption(cmd, nameOrShortOrLong) {
806
- return nameOrShortOrLong.startsWith("--") ? cmd.options.find((o) => {
807
- return o.long === nameOrShortOrLong.slice(2);
808
- }) : nameOrShortOrLong.startsWith("-") ? cmd.options.find((o) => {
809
- return o.short === nameOrShortOrLong.slice(1);
810
- }) : cmd.options.find((o) => {
811
- return o.name === nameOrShortOrLong;
812
- });
947
+ return nameOrShortOrLong.startsWith('--')
948
+ ? cmd.options.find((o) => {
949
+ return o.long === nameOrShortOrLong.slice(2);
950
+ })
951
+ : nameOrShortOrLong.startsWith('-')
952
+ ? cmd.options.find((o) => {
953
+ return o.short === nameOrShortOrLong.slice(1);
954
+ })
955
+ : cmd.options.find((o) => {
956
+ return o.name === nameOrShortOrLong;
957
+ });
813
958
  }
814
-
815
- // src/lib/helpers/getCommandAncestors.ts
816
- var getCommandAncestors_exports = {};
817
- __export(getCommandAncestors_exports, {
818
- getCommandAncestors: () => getCommandAncestors
819
- });
959
+ __name(findOption, 'findOption');
820
960
 
821
961
  // src/lib/helpers/getCommandAndAncestors.ts
822
- var getCommandAndAncestors_exports = {};
823
- __export(getCommandAndAncestors_exports, {
824
- getCommandAndAncestors: () => getCommandAndAncestors
825
- });
826
962
  function getCommandAndAncestors(cmd) {
827
963
  const result = [];
828
964
  let command = cmd;
@@ -831,15 +967,13 @@ function getCommandAndAncestors(cmd) {
831
967
  }
832
968
  return result;
833
969
  }
970
+ __name(getCommandAndAncestors, 'getCommandAndAncestors');
834
971
 
835
972
  // src/lib/helpers/getCommandAncestors.ts
836
973
  function getCommandAncestors(cmd) {
837
974
  return getCommandAndAncestors(cmd).slice(1);
838
975
  }
839
-
840
- // src/lib/Command.ts
841
- import { inspect } from "node:util";
842
- import { kebabCase } from "es-toolkit/string";
976
+ __name(getCommandAncestors, 'getCommandAncestors');
843
977
 
844
978
  // src/lib/internal/mergeOptionDefaults.ts
845
979
  function mergeOptionDefaults(values, options) {
@@ -849,6 +983,7 @@ function mergeOptionDefaults(values, options) {
849
983
  }
850
984
  }
851
985
  }
986
+ __name(mergeOptionDefaults, 'mergeOptionDefaults');
852
987
 
853
988
  // src/lib/internal/normalizeArgv.ts
854
989
  function normalizeArgv(argv, options) {
@@ -868,15 +1003,9 @@ function normalizeArgv(argv, options) {
868
1003
  }
869
1004
  return argv;
870
1005
  }
871
-
872
- // src/lib/Command.ts
873
- import { parseArgs } from "node:util";
1006
+ __name(normalizeArgv, 'normalizeArgv');
874
1007
 
875
1008
  // src/lib/helpers/parseOptionFlags.ts
876
- var parseOptionFlags_exports = {};
877
- __export(parseOptionFlags_exports, {
878
- parseOptionFlags: () => parseOptionFlags
879
- });
880
1009
  function parseOptionFlags(flags) {
881
1010
  const match = flags.match(/^-(.+?), --([a-zA-Z][\w-]*)(?:\s*(<(.+?)>|\[(.+?)\]))?$/);
882
1011
  if (!match) {
@@ -887,12 +1016,18 @@ function parseOptionFlags(flags) {
887
1016
  throw new Error(`Expected short name to be a single character. Got: -${short}`);
888
1017
  }
889
1018
  const long = match[2];
890
- const argName = (match[4] || match[5])?.replace(/\.\.\.$/, "") || void 0;
891
- const name = long.split("-").reduce((str, word) => {
1019
+ const argName = (match[4] || match[5])?.replace(/\.\.\.$/, '') || void 0;
1020
+ const name = long.split('-').reduce((str, word) => {
892
1021
  return str + word[0].toUpperCase() + word.slice(1);
893
1022
  });
894
- return { short, long, name, argName };
1023
+ return {
1024
+ short,
1025
+ long,
1026
+ name,
1027
+ argName,
1028
+ };
895
1029
  }
1030
+ __name(parseOptionFlags, 'parseOptionFlags');
896
1031
 
897
1032
  // src/lib/internal/resolveArguments.ts
898
1033
  function resolveArguments(positionals, args) {
@@ -908,67 +1043,66 @@ function resolveArguments(positionals, args) {
908
1043
  }
909
1044
  return result;
910
1045
  }
1046
+ __name(resolveArguments, 'resolveArguments');
911
1047
 
912
1048
  // ../fn/src/setName.ts
913
1049
  function setName(name, target) {
914
- return Object.defineProperty(target, "name", {
915
- value: typeof name === "string" ? name : name.name,
1050
+ return Object.defineProperty(target, 'name', {
1051
+ value: typeof name === 'string' ? name : name.name,
916
1052
  configurable: true,
917
- enumerable: false
1053
+ enumerable: false,
918
1054
  });
919
1055
  }
1056
+ __name(setName, 'setName');
920
1057
 
921
1058
  // ../string/src/lib/strFirstCharToUpperCase.ts
922
1059
  function strFirstCharToUpperCase(string) {
923
1060
  return string.charAt(0).toUpperCase() + string.substring(1);
924
1061
  }
925
-
926
- // ../node/src/createLogger.ts
927
- import colors from "ansi-colors";
928
- import { isPrimitive } from "es-toolkit/predicate";
929
- import { isString } from "es-toolkit/predicate";
1062
+ __name(strFirstCharToUpperCase, 'strFirstCharToUpperCase');
930
1063
  function createLogger(name) {
931
- const NAME = name ? colors.dim.cyan(name) : name;
932
- const START = [NAME, colors.dim.gray("[START]")].filter(Boolean);
933
- const DEBUG = [NAME, colors.dim.magenta("[DEBUG]")].filter(Boolean);
934
- const INFO = [NAME, colors.dim.gray("[INFO]")].filter(Boolean);
935
- const DONE = [NAME, colors.dim.green("[DONE] ")].filter(Boolean);
936
- const WARN = [NAME, colors.dim.yellow("[WARN] ")].filter(Boolean);
937
- const ERROR = [NAME, colors.dim.red("[ERROR]")].filter(Boolean);
938
- const grayArgs = createColoredArgs(colors.gray);
939
- const cyanArgs = createColoredArgs(colors.cyan);
940
- const yellowArgs = createColoredArgs(colors.yellow);
1064
+ const NAME = name ? C.dim.cyan(name) : name;
1065
+ const START = [NAME, C.dim.gray('[START]')].filter(Boolean);
1066
+ const DEBUG = [NAME, C.dim.magenta('[DEBUG]')].filter(Boolean);
1067
+ const INFO = [NAME, C.dim.gray('[INFO]')].filter(Boolean);
1068
+ const DONE = [NAME, C.dim.green('[DONE] ')].filter(Boolean);
1069
+ const WARN = [NAME, C.dim.yellow('[WARN] ')].filter(Boolean);
1070
+ const ERROR = [NAME, C.dim.red('[ERROR]')].filter(Boolean);
1071
+ const grayArgs = createColoredArgs(C.gray);
1072
+ const cyanArgs = createColoredArgs(C.cyan);
1073
+ const yellowArgs = createColoredArgs(C.yellow);
941
1074
  return {
942
- start: (...args) => {
1075
+ start: /* @__PURE__ */ __name((...args) => {
943
1076
  return console.info(...START, ...args);
944
- },
945
- done: (...args) => {
1077
+ }, 'start'),
1078
+ done: /* @__PURE__ */ __name((...args) => {
946
1079
  return console.info(...DONE, ...args);
947
- },
948
- info: (...args) => {
1080
+ }, 'done'),
1081
+ info: /* @__PURE__ */ __name((...args) => {
949
1082
  return console.info(...INFO, ...grayArgs(args));
950
- },
951
- log: (...args) => {
952
- return console.log(...NAME ? [NAME, ...args] : args);
953
- },
954
- warn: (...args) => {
1083
+ }, 'info'),
1084
+ log: /* @__PURE__ */ __name((...args) => {
1085
+ return console.log(...(NAME ? [NAME, ...args] : args));
1086
+ }, 'log'),
1087
+ warn: /* @__PURE__ */ __name((...args) => {
955
1088
  return console.warn(...WARN, ...yellowArgs(args));
956
- },
957
- debug: (...args) => {
1089
+ }, 'warn'),
1090
+ debug: /* @__PURE__ */ __name((...args) => {
958
1091
  return console.debug(...DEBUG, ...cyanArgs(args));
959
- },
960
- error: (...args) => {
1092
+ }, 'debug'),
1093
+ error: /* @__PURE__ */ __name((...args) => {
961
1094
  return args.forEach((arg) => {
962
1095
  return console.error(...ERROR, arg);
963
1096
  });
964
- }
1097
+ }, 'error'),
965
1098
  };
966
1099
  }
1100
+ __name(createLogger, 'createLogger');
967
1101
  function createColoredArgs(colorFn) {
968
1102
  return (args) => {
969
1103
  return args.map((arg) => {
970
1104
  if (isString(arg)) {
971
- if (arg === colors.stripColor(arg)) {
1105
+ if (arg === C.stripColor(arg)) {
972
1106
  return colorFn(arg);
973
1107
  } else {
974
1108
  return arg;
@@ -981,14 +1115,10 @@ function createColoredArgs(colorFn) {
981
1115
  });
982
1116
  };
983
1117
  }
984
-
985
- // ../node/src/timer.ts
986
- import colors2 from "ansi-colors";
987
- import humanizeDuration from "humanize-duration";
988
- import { isPromise } from "node:util/types";
1118
+ __name(createColoredArgs, 'createColoredArgs');
989
1119
  function timer(arg, task) {
990
1120
  const t0 = process.hrtime.bigint();
991
- const [name, description] = Array.isArray(arg) ? arg : [arg, ""];
1121
+ const [name, description] = Array.isArray(arg) ? arg : [arg, ''];
992
1122
  const log = createLogger(name);
993
1123
  if (name && description) {
994
1124
  log.start(description);
@@ -1006,59 +1136,98 @@ function timer(arg, task) {
1006
1136
  }
1007
1137
  const ns = process.hrtime.bigint() - t0;
1008
1138
  const ms3 = Math.floor(Number(ns) / 1e6);
1009
- log.done(colors2.dim(humanizeDuration(ms3)));
1139
+ log.done(C.dim(humanizeDuration(ms3)));
1010
1140
  return retval2;
1011
1141
  }
1012
1142
  }
1143
+ __name(timer, 'timer');
1013
1144
 
1014
1145
  // src/lib/internal/validateParsed.ts
1015
1146
  function validateParsed(args, optionValues, argDefs, optionDefs) {
1016
- return argDefs.map((def, index) => {
1017
- const value = args[index];
1018
- if (def.required) {
1019
- if (def.variadic ? Array.isArray(value) && value.length === 0 : value === void 0) {
1020
- return `Missing argument [${index}] ${def.usage}`;
1021
- }
1022
- }
1023
- if (def.choices && value !== void 0) {
1024
- if (![value].flat().every((v) => {
1025
- return def.choices.includes(v);
1026
- })) {
1027
- return `Invalid argument [${index}] ${def.usage}: Got \`${value}\`. Accepted values: [${def.choices.map((c) => {
1028
- return `\`${c}\``;
1029
- }).join(",")}]`;
1030
- }
1031
- }
1032
- }).concat(
1033
- entriesOf(optionValues).map(([key, value]) => {
1034
- const def = optionDefs.find((o) => {
1035
- return o.name === key;
1036
- });
1037
- if (!def) {
1038
- return `Unknown option --${key}`;
1147
+ return argDefs
1148
+ .map((def, index) => {
1149
+ const value = args[index];
1150
+ if (def.required) {
1151
+ if (def.variadic ? Array.isArray(value) && value.length === 0 : value === void 0) {
1152
+ return `Missing argument [${index}] ${def.usage}`;
1153
+ }
1039
1154
  }
1040
1155
  if (def.choices && value !== void 0) {
1041
- if (!(def.variadic ? value : [value]).every((v) => {
1042
- return def.choices.includes(v);
1043
- })) {
1044
- return `Invalid option value ${def.flags}: Got \`${value}\`. Accepted values: [${def.choices.map((c) => {
1045
- return `\`${c}\``;
1046
- }).join(",")}]`;
1156
+ if (
1157
+ ![value].flat().every((v) => {
1158
+ return def.choices.includes(v);
1159
+ })
1160
+ ) {
1161
+ return `Invalid argument [${index}] ${def.usage}: Got \`${value}\`. Accepted values: [${def.choices
1162
+ .map((c) => {
1163
+ return `\`${c}\``;
1164
+ })
1165
+ .join(',')}]`;
1047
1166
  }
1048
1167
  }
1049
1168
  })
1050
- ).filter((s) => {
1051
- return s !== void 0;
1052
- }).reduce(
1053
- (acc, curr) => {
1054
- return (acc ?? []).concat(curr);
1055
- },
1056
- void 0
1057
- );
1169
+ .concat(
1170
+ entriesOf(optionValues).map(([key, value]) => {
1171
+ const def = optionDefs.find((o) => {
1172
+ return o.name === key;
1173
+ });
1174
+ if (!def) {
1175
+ return `Unknown option --${key}`;
1176
+ }
1177
+ if (def.choices && value !== void 0) {
1178
+ if (
1179
+ !(def.variadic ? value : [value]).every((v) => {
1180
+ return def.choices.includes(v);
1181
+ })
1182
+ ) {
1183
+ return `Invalid option value ${def.flags}: Got \`${value}\`. Accepted values: [${def.choices
1184
+ .map((c) => {
1185
+ return `\`${c}\``;
1186
+ })
1187
+ .join(',')}]`;
1188
+ }
1189
+ }
1190
+ }),
1191
+ )
1192
+ .filter((s) => {
1193
+ return s !== void 0;
1194
+ })
1195
+ .reduce(
1196
+ (acc, curr) => {
1197
+ return (acc ?? []).concat(curr);
1198
+ },
1199
+ void 0,
1200
+ );
1058
1201
  }
1202
+ __name(validateParsed, 'validateParsed');
1059
1203
 
1060
1204
  // src/lib/Command.ts
1061
- var _Command = class _Command {
1205
+ function _ts_decorate2(decorators, target, key, desc) {
1206
+ var c = arguments.length,
1207
+ r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
1208
+ d;
1209
+ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') {
1210
+ r = Reflect.decorate(decorators, target, key, desc);
1211
+ } else {
1212
+ for (var i = decorators.length - 1; i >= 0; i--) {
1213
+ if ((d = decorators[i])) {
1214
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1215
+ }
1216
+ }
1217
+ }
1218
+ return (c > 3 && r && Object.defineProperty(target, key, r), r);
1219
+ }
1220
+ __name(_ts_decorate2, '_ts_decorate');
1221
+ function _ts_metadata2(k, v) {
1222
+ if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function') {
1223
+ return Reflect.metadata(k, v);
1224
+ }
1225
+ }
1226
+ __name(_ts_metadata2, '_ts_metadata');
1227
+ var Command = class _Command {
1228
+ static {
1229
+ __name(this, 'Command');
1230
+ }
1062
1231
  /** parent command in the hierarchy, undefined for root command */
1063
1232
  parent;
1064
1233
  /** the command name used to invoke it */
@@ -1088,18 +1257,35 @@ var _Command = class _Command {
1088
1257
  constructor(name, parent) {
1089
1258
  this.name = name;
1090
1259
  this.aliases = [];
1091
- this.description = "";
1260
+ this.description = '';
1092
1261
  this.arguments = [];
1093
1262
  this.options = [];
1094
1263
  this.commands = {};
1095
1264
  this.hooks = [];
1096
- Object.defineProperty(this, "parent", { value: parent, enumerable: false });
1265
+ Object.defineProperty(this, 'parent', {
1266
+ value: parent,
1267
+ enumerable: false,
1268
+ });
1097
1269
  if (!parent) {
1098
- this.addOption("-D, --debug", { description: "Display debug information" }).addOptionHook("debug", ({ cmd, ...data }) => {
1099
- console.debug(inspect(cmd, { depth: 1, colors: true }));
1100
- console.debug(inspect(data, { depth: 3, colors: true }));
1270
+ this.addOption('-D, --debug', {
1271
+ description: 'Display debug information',
1272
+ }).addOptionHook('debug', ({ cmd, ...data }) => {
1273
+ console.debug(
1274
+ inspect(cmd, {
1275
+ depth: 1,
1276
+ colors: true,
1277
+ }),
1278
+ );
1279
+ console.debug(
1280
+ inspect(data, {
1281
+ depth: 3,
1282
+ colors: true,
1283
+ }),
1284
+ );
1101
1285
  });
1102
- this.addOption("-h, --help", { description: "Display help information" }).addOptionHook("help", ({ cmd }) => {
1286
+ this.addOption('-h, --help', {
1287
+ description: 'Display help information',
1288
+ }).addOptionHook('help', ({ cmd }) => {
1103
1289
  console.log(cmd.renderHelp());
1104
1290
  process.exitCode = 0;
1105
1291
  });
@@ -1117,7 +1303,7 @@ var _Command = class _Command {
1117
1303
  /** renders formatted help text using provided help definition */
1118
1304
  renderHelp(config = {}) {
1119
1305
  const result = this.help.render();
1120
- return config.noColor ? colors3.stripColor(result) : result;
1306
+ return config.noColor ? C.stripColor(result) : result;
1121
1307
  }
1122
1308
  /** sets the command name */
1123
1309
  setName(name) {
@@ -1131,19 +1317,23 @@ var _Command = class _Command {
1131
1317
  }
1132
1318
  /** adds aliases to existing ones */
1133
1319
  addAliases(...aliases) {
1134
- const taken = this.parent ? valuesOf(this.parent.commands).flatMap((c) => {
1135
- return [c.name, ...c.aliases];
1136
- }) : [];
1137
- arrRemoveDuplicates(aliases.flat()).filter((a) => {
1138
- return !this.aliases.includes(a) && a !== this.name;
1139
- }).forEach((a) => {
1140
- if (taken.includes(a)) {
1141
- throw new Error(
1142
- `Alias "${a}" is already used by a sibling command: ${findCommand(this.parent, a)?.name}`
1143
- );
1144
- }
1145
- this.aliases.push(a);
1146
- });
1320
+ const taken = this.parent
1321
+ ? valuesOf(this.parent.commands).flatMap((c) => {
1322
+ return [c.name, ...c.aliases];
1323
+ })
1324
+ : [];
1325
+ arrRemoveDuplicates(aliases.flat())
1326
+ .filter((a) => {
1327
+ return !this.aliases.includes(a) && a !== this.name;
1328
+ })
1329
+ .forEach((a) => {
1330
+ if (taken.includes(a)) {
1331
+ throw new Error(
1332
+ `Alias "${a}" is already used by a sibling command: ${findCommand(this.parent, a)?.name}`,
1333
+ );
1334
+ }
1335
+ this.aliases.push(a);
1336
+ });
1147
1337
  this.aliases.sort((a, b) => {
1148
1338
  return a.length - b.length;
1149
1339
  });
@@ -1152,14 +1342,16 @@ var _Command = class _Command {
1152
1342
  /** sets the command version */
1153
1343
  setVersion(version) {
1154
1344
  this.version = version;
1155
- if (findOption(this, "version")) {
1345
+ if (findOption(this, 'version')) {
1156
1346
  return this;
1157
1347
  }
1158
- return this.addOption("-V, --version", { description: "Display semver version" }).addOptionHook("version", ({ cmd }) => {
1348
+ return this.addOption('-V, --version', {
1349
+ description: 'Display semver version',
1350
+ }).addOptionHook('version', ({ cmd }) => {
1159
1351
  console.log(
1160
1352
  getCommandAndAncestors(cmd).find((c) => {
1161
1353
  return c.version;
1162
- })?.version
1354
+ })?.version,
1163
1355
  );
1164
1356
  process.exitCode = 0;
1165
1357
  });
@@ -1171,7 +1363,7 @@ var _Command = class _Command {
1171
1363
  }
1172
1364
  /** sets command description, joining variadic lines */
1173
1365
  setDescription(...lines) {
1174
- this.description = lines.join("\n");
1366
+ this.description = lines.join('\n');
1175
1367
  return this;
1176
1368
  }
1177
1369
  /** sets whether command is hidden from help */
@@ -1185,11 +1377,11 @@ var _Command = class _Command {
1185
1377
  return this;
1186
1378
  }
1187
1379
  /** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
1188
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1380
+
1189
1381
  command(name, cb) {
1190
1382
  if (this.arguments.length) {
1191
1383
  throw new Error(
1192
- `Cannot add subcommand "${name}" to "${this.name}" because it already has arguments defined.`
1384
+ `Cannot add subcommand "${name}" to "${this.name}" because it already has arguments defined.`,
1193
1385
  );
1194
1386
  }
1195
1387
  const sub = this.createSubcommand(name);
@@ -1208,20 +1400,24 @@ var _Command = class _Command {
1208
1400
  throw new Error(
1209
1401
  `Command name "${getCommandAndAncestors(sub).map((c) => {
1210
1402
  return c.name;
1211
- })}" is already used by this command or its aliases: ${taken.join(", ")}`
1403
+ })}" is already used by this command or its aliases: ${taken.join(', ')}`,
1212
1404
  );
1213
1405
  }
1214
1406
  const kebab = kebabCase(name);
1215
- const words = kebab.split("-");
1216
- const initials = words.map((s) => {
1217
- return s[0];
1218
- }).join("");
1407
+ const words = kebab.split('-');
1408
+ const initials = words
1409
+ .map((s) => {
1410
+ return s[0];
1411
+ })
1412
+ .join('');
1219
1413
  if (!taken.includes(initials)) {
1220
1414
  sub.addAliases(initials);
1221
1415
  } else {
1222
- const initials2 = words.map((s) => {
1223
- return s[0] + s[1];
1224
- }).join("");
1416
+ const initials2 = words
1417
+ .map((s) => {
1418
+ return s[0] + s[1];
1419
+ })
1420
+ .join('');
1225
1421
  if (!taken.includes(initials2)) {
1226
1422
  sub.addAliases(initials2);
1227
1423
  }
@@ -1230,7 +1426,7 @@ var _Command = class _Command {
1230
1426
  return cb ? cb(sub, this) : sub;
1231
1427
  }
1232
1428
  /** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
1233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1429
+
1234
1430
  addCommand(name, cb) {
1235
1431
  this.command(name, cb);
1236
1432
  return this;
@@ -1240,9 +1436,9 @@ var _Command = class _Command {
1240
1436
  if (!/^<(.*?)>$|^\[(.*?)\]$/.test(usage)) {
1241
1437
  throw new Error(`Invalid argument format: ${usage}`);
1242
1438
  }
1243
- const name = usage.slice(1, -1).replace(/\.\.\.$/, "");
1244
- const required = usage.startsWith("<");
1245
- const variadic = usage.slice(0, -1).endsWith("...");
1439
+ const name = usage.slice(1, -1).replace(/\.\.\.$/, '');
1440
+ const required = usage.startsWith('<');
1441
+ const variadic = usage.slice(0, -1).endsWith('...');
1246
1442
  const prevArg = this.arguments[this.arguments.length - 1];
1247
1443
  if (prevArg?.variadic) {
1248
1444
  throw new Error(`Cannot add argument ${usage} after variadic argument ${prevArg.usage}`);
@@ -1252,7 +1448,7 @@ var _Command = class _Command {
1252
1448
  }
1253
1449
  if (required && prevArg?.defaultValue) {
1254
1450
  throw new Error(
1255
- `Cannot add required argument ${usage} after optional argument with default value ${prevArg.usage}`
1451
+ `Cannot add required argument ${usage} after optional argument with default value ${prevArg.usage}`,
1256
1452
  );
1257
1453
  }
1258
1454
  const arg = {
@@ -1260,7 +1456,7 @@ var _Command = class _Command {
1260
1456
  name,
1261
1457
  required,
1262
1458
  variadic,
1263
- ...options
1459
+ ...options,
1264
1460
  };
1265
1461
  if (variadic && !arg.defaultValue) {
1266
1462
  arg.defaultValue = [];
@@ -1286,21 +1482,21 @@ var _Command = class _Command {
1286
1482
  ins.short = short;
1287
1483
  ins.long = long;
1288
1484
  ins.name = name;
1289
- ins.description = "";
1485
+ ins.description = '';
1290
1486
  if (!argName) {
1291
- ins.type = "boolean";
1487
+ ins.type = 'boolean';
1292
1488
  } else {
1293
- ins.type = "string";
1489
+ ins.type = 'string';
1294
1490
  ins.argName = argName;
1295
- if (flags.endsWith(">")) {
1296
- if (flags.endsWith("...>")) {
1491
+ if (flags.endsWith('>')) {
1492
+ if (flags.endsWith('...>')) {
1297
1493
  ins.required = true;
1298
1494
  ins.variadic = true;
1299
1495
  } else {
1300
1496
  ins.required = true;
1301
1497
  }
1302
- } else if (flags.endsWith("]")) {
1303
- if (flags.endsWith("...]")) {
1498
+ } else if (flags.endsWith(']')) {
1499
+ if (flags.endsWith('...]')) {
1304
1500
  ins.variadic = true;
1305
1501
  ins.defaultValue = opts.defaultValue ?? [];
1306
1502
  }
@@ -1311,15 +1507,18 @@ var _Command = class _Command {
1311
1507
  Reflect.set(ins, key, value);
1312
1508
  }
1313
1509
  }
1314
- if (ins.env && ins.defaultValue === void 0 && typeof process.env[ins.env] === "string") {
1510
+ if (ins.env && ins.defaultValue === void 0 && typeof process.env[ins.env] === 'string') {
1315
1511
  ins.required = false;
1316
- ins.flags = ins.flags.replace("<", "[").replace(">", "]");
1317
- if (ins.type === "boolean") {
1512
+ ins.flags = ins.flags.replace('<', '[').replace('>', ']');
1513
+ if (ins.type === 'boolean') {
1318
1514
  ins.defaultValue = /^(t(rue)?|y(es)?|1)$/i.test(process.env[ins.env]);
1319
1515
  } else if (ins.variadic) {
1320
- ins.defaultValue = process.env[ins.env].replace(/\]|\[/, "").split(",").map((v) => {
1321
- return v.trim();
1322
- });
1516
+ ins.defaultValue = process.env[ins.env]
1517
+ .replace(/\]|\[/, '')
1518
+ .split(',')
1519
+ .map((v) => {
1520
+ return v.trim();
1521
+ });
1323
1522
  } else {
1324
1523
  ins.defaultValue = process.env[ins.env];
1325
1524
  }
@@ -1337,14 +1536,18 @@ var _Command = class _Command {
1337
1536
  addOptionHook(optionName, action) {
1338
1537
  const def = findOption(this, optionName);
1339
1538
  if (!def.group && /process\.exitCode ?= ?.+;?\s*\}$/.test(action.toString())) {
1340
- def.group = "Command Options";
1539
+ def.group = 'Command Options';
1341
1540
  }
1342
1541
  this.hooks.push({
1343
1542
  name: optionName,
1344
1543
  predicate: setName(`has${strFirstCharToUpperCase(optionName)}`, ({ opts }) => {
1345
- return opts[optionName] !== void 0 && opts[optionName] !== false && !(Array.isArray(opts[optionName]) && opts[optionName].length === 0);
1544
+ return (
1545
+ opts[optionName] !== void 0 &&
1546
+ opts[optionName] !== false &&
1547
+ !(Array.isArray(opts[optionName]) && opts[optionName].length === 0)
1548
+ );
1346
1549
  }),
1347
- action: setName(optionName, action)
1550
+ action: setName(optionName, action),
1348
1551
  });
1349
1552
  return this;
1350
1553
  }
@@ -1359,13 +1562,21 @@ var _Command = class _Command {
1359
1562
  args: argv,
1360
1563
  options: Object.fromEntries(
1361
1564
  this.options.map((o) => {
1362
- return [o.name, { type: o.type, short: o.short, default: o.defaultValue, multiple: !!o.variadic }];
1363
- })
1565
+ return [
1566
+ o.name,
1567
+ {
1568
+ type: o.type,
1569
+ short: o.short,
1570
+ default: o.defaultValue,
1571
+ multiple: !!o.variadic,
1572
+ },
1573
+ ];
1574
+ }),
1364
1575
  ),
1365
1576
  allowPositionals: true,
1366
1577
  tokens: true,
1367
1578
  strict: false,
1368
- allowNegative: true
1579
+ allowNegative: true,
1369
1580
  });
1370
1581
  collectVariadicOptionValues(parsed, this.options);
1371
1582
  mergeOptionDefaults(parsed.values, this.options);
@@ -1387,22 +1598,22 @@ var _Command = class _Command {
1387
1598
  args,
1388
1599
  opts,
1389
1600
  errors,
1390
- cmd: this
1601
+ cmd: this,
1391
1602
  };
1392
1603
  const hooks = this.hooks.filter((t) => {
1393
1604
  return t.predicate(data);
1394
1605
  });
1395
- const execute = async () => {
1606
+ const execute = /* @__PURE__ */ __name(async () => {
1396
1607
  for (const hook of hooks) {
1397
1608
  await hook.action(data);
1398
1609
  if (process.exitCode !== void 0) {
1399
1610
  return;
1400
1611
  }
1401
1612
  }
1402
- await timer([[...path, this.name].join(" "), this.description], async (logger) => {
1613
+ await timer([[...path, this.name].join(' '), this.description], async (logger) => {
1403
1614
  if (errors) {
1404
1615
  errors.forEach((msg) => {
1405
- return logger.error(colors3.red(msg));
1616
+ return logger.error(C.red(msg));
1406
1617
  });
1407
1618
  process.exitCode = 1;
1408
1619
  return;
@@ -1413,13 +1624,17 @@ var _Command = class _Command {
1413
1624
  args,
1414
1625
  opts,
1415
1626
  cmd: this,
1416
- logger
1627
+ logger,
1417
1628
  });
1418
1629
  }
1419
1630
  console.log(this.renderHelp());
1420
1631
  });
1632
+ }, 'execute');
1633
+ return {
1634
+ ...data,
1635
+ hooks,
1636
+ execute,
1421
1637
  };
1422
- return { ...data, hooks, execute };
1423
1638
  }
1424
1639
  /**
1425
1640
  * sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
@@ -1434,33 +1649,15 @@ var _Command = class _Command {
1434
1649
  return new _Command(name, this);
1435
1650
  }
1436
1651
  };
1437
- __decorateClass([
1438
- lazyProp
1439
- ], _Command.prototype, "help", 1);
1440
- var Command = _Command;
1441
-
1442
- // src/lib/types.ts
1443
- var types_exports = {};
1652
+ _ts_decorate2(
1653
+ [
1654
+ lazyProp,
1655
+ _ts_metadata2('design:type', typeof Help === 'undefined' ? Object : Help),
1656
+ _ts_metadata2('design:paramtypes', []),
1657
+ ],
1658
+ Command.prototype,
1659
+ 'help',
1660
+ null,
1661
+ );
1444
1662
 
1445
- // src/index.ts
1446
- var src_default = {
1447
- ...Command_exports,
1448
- //
1449
- ...Help_exports,
1450
- ...findCommand_exports,
1451
- ...findOption_exports,
1452
- ...getCommandAncestors_exports,
1453
- ...getCommandAndAncestors_exports,
1454
- ...parseOptionFlags_exports,
1455
- ...types_exports
1456
- };
1457
- export {
1458
- Command,
1459
- Help,
1460
- src_default as default,
1461
- findCommand,
1462
- findOption,
1463
- getCommandAncestors,
1464
- getCommandAndAncestors,
1465
- parseOptionFlags
1466
- };
1663
+ export { Command, Help, findCommand, findOption, getCommandAncestors, getCommandAndAncestors, parseOptionFlags };