@bemoje/cli 2.1.3 → 2.1.4

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