create-storybook 10.0.0-beta.0 → 10.0.0-beta.10
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/dist/_node-chunks/{chunk-WMCE423I.js → chunk-I24RQKHC.js} +689 -706
- package/dist/_node-chunks/{chunk-YS3LR2WA.js → chunk-U2ROAS4E.js} +11 -6
- package/dist/_node-chunks/{run-UEEEVPHK.js → run-MI4MI4HS.js} +618 -184
- package/dist/bin/index.js +8 -8
- package/dist/index.js +8 -8
- package/package.json +6 -5
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_icv75y2zad from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_icv75y2zad from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_icv75y2zad from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_icv75y2zad.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_icv75y2zad.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_icv75y2zad.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
} from "./chunk-
|
|
13
|
+
initiate
|
|
14
|
+
} from "./chunk-I24RQKHC.js";
|
|
15
15
|
import {
|
|
16
16
|
__commonJS,
|
|
17
17
|
__name,
|
|
18
18
|
__require,
|
|
19
19
|
__toESM
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-U2ROAS4E.js";
|
|
21
21
|
|
|
22
22
|
// ../../node_modules/commander/lib/error.js
|
|
23
23
|
var require_error = __commonJS({
|
|
@@ -97,7 +97,7 @@ var require_argument = __commonJS({
|
|
|
97
97
|
this._name = name;
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
|
-
if (this._name.
|
|
100
|
+
if (this._name.endsWith("...")) {
|
|
101
101
|
this.variadic = true;
|
|
102
102
|
this._name = this._name.slice(0, -3);
|
|
103
103
|
}
|
|
@@ -113,11 +113,12 @@ var require_argument = __commonJS({
|
|
|
113
113
|
/**
|
|
114
114
|
* @package
|
|
115
115
|
*/
|
|
116
|
-
|
|
116
|
+
_collectValue(value, previous) {
|
|
117
117
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
118
118
|
return [value];
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
previous.push(value);
|
|
121
|
+
return previous;
|
|
121
122
|
}
|
|
122
123
|
/**
|
|
123
124
|
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
@@ -156,7 +157,7 @@ var require_argument = __commonJS({
|
|
|
156
157
|
);
|
|
157
158
|
}
|
|
158
159
|
if (this.variadic) {
|
|
159
|
-
return this.
|
|
160
|
+
return this._collectValue(arg, previous);
|
|
160
161
|
}
|
|
161
162
|
return arg;
|
|
162
163
|
};
|
|
@@ -201,10 +202,22 @@ var require_help = __commonJS({
|
|
|
201
202
|
}
|
|
202
203
|
constructor() {
|
|
203
204
|
this.helpWidth = void 0;
|
|
205
|
+
this.minWidthToWrap = 40;
|
|
204
206
|
this.sortSubcommands = false;
|
|
205
207
|
this.sortOptions = false;
|
|
206
208
|
this.showGlobalOptions = false;
|
|
207
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
212
|
+
* and just before calling `formatHelp()`.
|
|
213
|
+
*
|
|
214
|
+
* Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.
|
|
215
|
+
*
|
|
216
|
+
* @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions
|
|
217
|
+
*/
|
|
218
|
+
prepareContext(contextOptions) {
|
|
219
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
220
|
+
}
|
|
208
221
|
/**
|
|
209
222
|
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
210
223
|
*
|
|
@@ -341,7 +354,12 @@ var require_help = __commonJS({
|
|
|
341
354
|
*/
|
|
342
355
|
longestSubcommandTermLength(cmd, helper) {
|
|
343
356
|
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
344
|
-
return Math.max(
|
|
357
|
+
return Math.max(
|
|
358
|
+
max,
|
|
359
|
+
this.displayWidth(
|
|
360
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(command))
|
|
361
|
+
)
|
|
362
|
+
);
|
|
345
363
|
}, 0);
|
|
346
364
|
}
|
|
347
365
|
/**
|
|
@@ -353,7 +371,10 @@ var require_help = __commonJS({
|
|
|
353
371
|
*/
|
|
354
372
|
longestOptionTermLength(cmd, helper) {
|
|
355
373
|
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
356
|
-
return Math.max(
|
|
374
|
+
return Math.max(
|
|
375
|
+
max,
|
|
376
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
377
|
+
);
|
|
357
378
|
}, 0);
|
|
358
379
|
}
|
|
359
380
|
/**
|
|
@@ -365,7 +386,10 @@ var require_help = __commonJS({
|
|
|
365
386
|
*/
|
|
366
387
|
longestGlobalOptionTermLength(cmd, helper) {
|
|
367
388
|
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
368
|
-
return Math.max(
|
|
389
|
+
return Math.max(
|
|
390
|
+
max,
|
|
391
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
392
|
+
);
|
|
369
393
|
}, 0);
|
|
370
394
|
}
|
|
371
395
|
/**
|
|
@@ -377,7 +401,12 @@ var require_help = __commonJS({
|
|
|
377
401
|
*/
|
|
378
402
|
longestArgumentTermLength(cmd, helper) {
|
|
379
403
|
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
380
|
-
return Math.max(
|
|
404
|
+
return Math.max(
|
|
405
|
+
max,
|
|
406
|
+
this.displayWidth(
|
|
407
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument))
|
|
408
|
+
)
|
|
409
|
+
);
|
|
381
410
|
}, 0);
|
|
382
411
|
}
|
|
383
412
|
/**
|
|
@@ -445,7 +474,11 @@ var require_help = __commonJS({
|
|
|
445
474
|
extraInfo.push(`env: ${option.envVar}`);
|
|
446
475
|
}
|
|
447
476
|
if (extraInfo.length > 0) {
|
|
448
|
-
|
|
477
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
478
|
+
if (option.description) {
|
|
479
|
+
return `${option.description} ${extraDescription}`;
|
|
480
|
+
}
|
|
481
|
+
return extraDescription;
|
|
449
482
|
}
|
|
450
483
|
return option.description;
|
|
451
484
|
}
|
|
@@ -469,14 +502,49 @@ var require_help = __commonJS({
|
|
|
469
502
|
);
|
|
470
503
|
}
|
|
471
504
|
if (extraInfo.length > 0) {
|
|
472
|
-
const
|
|
505
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
473
506
|
if (argument.description) {
|
|
474
|
-
return `${argument.description} ${
|
|
507
|
+
return `${argument.description} ${extraDescription}`;
|
|
475
508
|
}
|
|
476
|
-
return
|
|
509
|
+
return extraDescription;
|
|
477
510
|
}
|
|
478
511
|
return argument.description;
|
|
479
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
515
|
+
*
|
|
516
|
+
* @param {string} heading
|
|
517
|
+
* @param {string[]} items
|
|
518
|
+
* @param {Help} helper
|
|
519
|
+
* @returns string[]
|
|
520
|
+
*/
|
|
521
|
+
formatItemList(heading, items, helper) {
|
|
522
|
+
if (items.length === 0) return [];
|
|
523
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Group items by their help group heading.
|
|
527
|
+
*
|
|
528
|
+
* @param {Command[] | Option[]} unsortedItems
|
|
529
|
+
* @param {Command[] | Option[]} visibleItems
|
|
530
|
+
* @param {Function} getGroup
|
|
531
|
+
* @returns {Map<string, Command[] | Option[]>}
|
|
532
|
+
*/
|
|
533
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
534
|
+
const result = /* @__PURE__ */ new Map();
|
|
535
|
+
unsortedItems.forEach((item) => {
|
|
536
|
+
const group = getGroup(item);
|
|
537
|
+
if (!result.has(group)) result.set(group, []);
|
|
538
|
+
});
|
|
539
|
+
visibleItems.forEach((item) => {
|
|
540
|
+
const group = getGroup(item);
|
|
541
|
+
if (!result.has(group)) {
|
|
542
|
+
result.set(group, []);
|
|
543
|
+
}
|
|
544
|
+
result.get(group).push(item);
|
|
545
|
+
});
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
480
548
|
/**
|
|
481
549
|
* Generate the built-in help text.
|
|
482
550
|
*
|
|
@@ -486,77 +554,143 @@ var require_help = __commonJS({
|
|
|
486
554
|
*/
|
|
487
555
|
formatHelp(cmd, helper) {
|
|
488
556
|
const termWidth = helper.padWidth(cmd, helper);
|
|
489
|
-
const helpWidth = helper.helpWidth
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
termWidth + itemSeparatorWidth
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
return term;
|
|
502
|
-
}
|
|
503
|
-
__name(formatItem, "formatItem");
|
|
504
|
-
function formatList(textArray) {
|
|
505
|
-
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
506
|
-
}
|
|
507
|
-
__name(formatList, "formatList");
|
|
508
|
-
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
557
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
558
|
+
function callFormatItem(term, description) {
|
|
559
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
560
|
+
}
|
|
561
|
+
__name(callFormatItem, "callFormatItem");
|
|
562
|
+
let output = [
|
|
563
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
564
|
+
""
|
|
565
|
+
];
|
|
509
566
|
const commandDescription = helper.commandDescription(cmd);
|
|
510
567
|
if (commandDescription.length > 0) {
|
|
511
568
|
output = output.concat([
|
|
512
|
-
helper.
|
|
569
|
+
helper.boxWrap(
|
|
570
|
+
helper.styleCommandDescription(commandDescription),
|
|
571
|
+
helpWidth
|
|
572
|
+
),
|
|
513
573
|
""
|
|
514
574
|
]);
|
|
515
575
|
}
|
|
516
576
|
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
517
|
-
return
|
|
518
|
-
helper.argumentTerm(argument),
|
|
519
|
-
helper.argumentDescription(argument)
|
|
577
|
+
return callFormatItem(
|
|
578
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
579
|
+
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
520
580
|
);
|
|
521
581
|
});
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
582
|
+
output = output.concat(
|
|
583
|
+
this.formatItemList("Arguments:", argumentList, helper)
|
|
584
|
+
);
|
|
585
|
+
const optionGroups = this.groupItems(
|
|
586
|
+
cmd.options,
|
|
587
|
+
helper.visibleOptions(cmd),
|
|
588
|
+
(option) => option.helpGroupHeading ?? "Options:"
|
|
589
|
+
);
|
|
590
|
+
optionGroups.forEach((options, group) => {
|
|
591
|
+
const optionList = options.map((option) => {
|
|
592
|
+
return callFormatItem(
|
|
593
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
594
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
530
598
|
});
|
|
531
|
-
if (
|
|
532
|
-
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
533
|
-
}
|
|
534
|
-
if (this.showGlobalOptions) {
|
|
599
|
+
if (helper.showGlobalOptions) {
|
|
535
600
|
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
536
|
-
return
|
|
537
|
-
helper.optionTerm(option),
|
|
538
|
-
helper.optionDescription(option)
|
|
601
|
+
return callFormatItem(
|
|
602
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
603
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
539
604
|
);
|
|
540
605
|
});
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
"Global Options:",
|
|
544
|
-
formatList(globalOptionList),
|
|
545
|
-
""
|
|
546
|
-
]);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
550
|
-
return formatItem(
|
|
551
|
-
helper.subcommandTerm(cmd2),
|
|
552
|
-
helper.subcommandDescription(cmd2)
|
|
606
|
+
output = output.concat(
|
|
607
|
+
this.formatItemList("Global Options:", globalOptionList, helper)
|
|
553
608
|
);
|
|
554
|
-
});
|
|
555
|
-
if (commandList.length > 0) {
|
|
556
|
-
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
557
609
|
}
|
|
610
|
+
const commandGroups = this.groupItems(
|
|
611
|
+
cmd.commands,
|
|
612
|
+
helper.visibleCommands(cmd),
|
|
613
|
+
(sub) => sub.helpGroup() || "Commands:"
|
|
614
|
+
);
|
|
615
|
+
commandGroups.forEach((commands, group) => {
|
|
616
|
+
const commandList = commands.map((sub) => {
|
|
617
|
+
return callFormatItem(
|
|
618
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
619
|
+
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
620
|
+
);
|
|
621
|
+
});
|
|
622
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
623
|
+
});
|
|
558
624
|
return output.join("\n");
|
|
559
625
|
}
|
|
626
|
+
/**
|
|
627
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
628
|
+
*
|
|
629
|
+
* @param {string} str
|
|
630
|
+
* @returns {number}
|
|
631
|
+
*/
|
|
632
|
+
displayWidth(str) {
|
|
633
|
+
return stripColor(str).length;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
637
|
+
*
|
|
638
|
+
* @param {string} str
|
|
639
|
+
* @returns {string}
|
|
640
|
+
*/
|
|
641
|
+
styleTitle(str) {
|
|
642
|
+
return str;
|
|
643
|
+
}
|
|
644
|
+
styleUsage(str) {
|
|
645
|
+
return str.split(" ").map((word) => {
|
|
646
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
647
|
+
if (word === "[command]") return this.styleSubcommandText(word);
|
|
648
|
+
if (word[0] === "[" || word[0] === "<")
|
|
649
|
+
return this.styleArgumentText(word);
|
|
650
|
+
return this.styleCommandText(word);
|
|
651
|
+
}).join(" ");
|
|
652
|
+
}
|
|
653
|
+
styleCommandDescription(str) {
|
|
654
|
+
return this.styleDescriptionText(str);
|
|
655
|
+
}
|
|
656
|
+
styleOptionDescription(str) {
|
|
657
|
+
return this.styleDescriptionText(str);
|
|
658
|
+
}
|
|
659
|
+
styleSubcommandDescription(str) {
|
|
660
|
+
return this.styleDescriptionText(str);
|
|
661
|
+
}
|
|
662
|
+
styleArgumentDescription(str) {
|
|
663
|
+
return this.styleDescriptionText(str);
|
|
664
|
+
}
|
|
665
|
+
styleDescriptionText(str) {
|
|
666
|
+
return str;
|
|
667
|
+
}
|
|
668
|
+
styleOptionTerm(str) {
|
|
669
|
+
return this.styleOptionText(str);
|
|
670
|
+
}
|
|
671
|
+
styleSubcommandTerm(str) {
|
|
672
|
+
return str.split(" ").map((word) => {
|
|
673
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
674
|
+
if (word[0] === "[" || word[0] === "<")
|
|
675
|
+
return this.styleArgumentText(word);
|
|
676
|
+
return this.styleSubcommandText(word);
|
|
677
|
+
}).join(" ");
|
|
678
|
+
}
|
|
679
|
+
styleArgumentTerm(str) {
|
|
680
|
+
return this.styleArgumentText(str);
|
|
681
|
+
}
|
|
682
|
+
styleOptionText(str) {
|
|
683
|
+
return str;
|
|
684
|
+
}
|
|
685
|
+
styleArgumentText(str) {
|
|
686
|
+
return str;
|
|
687
|
+
}
|
|
688
|
+
styleSubcommandText(str) {
|
|
689
|
+
return str;
|
|
690
|
+
}
|
|
691
|
+
styleCommandText(str) {
|
|
692
|
+
return str;
|
|
693
|
+
}
|
|
560
694
|
/**
|
|
561
695
|
* Calculate the pad width from the maximum term length.
|
|
562
696
|
*
|
|
@@ -573,40 +707,95 @@ var require_help = __commonJS({
|
|
|
573
707
|
);
|
|
574
708
|
}
|
|
575
709
|
/**
|
|
576
|
-
*
|
|
577
|
-
* Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
|
|
710
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
578
711
|
*
|
|
579
712
|
* @param {string} str
|
|
580
|
-
* @
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
713
|
+
* @returns {boolean}
|
|
714
|
+
*/
|
|
715
|
+
preformatted(str) {
|
|
716
|
+
return /\n[^\S\r\n]/.test(str);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
584
720
|
*
|
|
721
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
722
|
+
* TTT DDD DDDD
|
|
723
|
+
* DD DDD
|
|
724
|
+
*
|
|
725
|
+
* @param {string} term
|
|
726
|
+
* @param {number} termWidth
|
|
727
|
+
* @param {string} description
|
|
728
|
+
* @param {Help} helper
|
|
729
|
+
* @returns {string}
|
|
585
730
|
*/
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
const leadingStr = str.slice(0, indent);
|
|
593
|
-
const columnText = str.slice(indent).replace("\r\n", "\n");
|
|
594
|
-
const indentString = " ".repeat(indent);
|
|
595
|
-
const zeroWidthSpace = "\u200B";
|
|
596
|
-
const breaks = `\\s${zeroWidthSpace}`;
|
|
597
|
-
const regex = new RegExp(
|
|
598
|
-
`
|
|
599
|
-
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
|
|
600
|
-
"g"
|
|
731
|
+
formatItem(term, termWidth, description, helper) {
|
|
732
|
+
const itemIndent = 2;
|
|
733
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
734
|
+
if (!description) return itemIndentStr + term;
|
|
735
|
+
const paddedTerm = term.padEnd(
|
|
736
|
+
termWidth + term.length - helper.displayWidth(term)
|
|
601
737
|
);
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
738
|
+
const spacerWidth = 2;
|
|
739
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
740
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
741
|
+
let formattedDescription;
|
|
742
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
743
|
+
formattedDescription = description;
|
|
744
|
+
} else {
|
|
745
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
746
|
+
formattedDescription = wrappedDescription.replace(
|
|
747
|
+
/\n/g,
|
|
748
|
+
"\n" + " ".repeat(termWidth + spacerWidth)
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
752
|
+
${itemIndentStr}`);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
756
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
757
|
+
*
|
|
758
|
+
* @param {string} str
|
|
759
|
+
* @param {number} width
|
|
760
|
+
* @returns {string}
|
|
761
|
+
*/
|
|
762
|
+
boxWrap(str, width) {
|
|
763
|
+
if (width < this.minWidthToWrap) return str;
|
|
764
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
765
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
766
|
+
const wrappedLines = [];
|
|
767
|
+
rawLines.forEach((line) => {
|
|
768
|
+
const chunks = line.match(chunkPattern);
|
|
769
|
+
if (chunks === null) {
|
|
770
|
+
wrappedLines.push("");
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
let sumChunks = [chunks.shift()];
|
|
774
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
775
|
+
chunks.forEach((chunk) => {
|
|
776
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
777
|
+
if (sumWidth + visibleWidth <= width) {
|
|
778
|
+
sumChunks.push(chunk);
|
|
779
|
+
sumWidth += visibleWidth;
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
wrappedLines.push(sumChunks.join(""));
|
|
783
|
+
const nextChunk = chunk.trimStart();
|
|
784
|
+
sumChunks = [nextChunk];
|
|
785
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
786
|
+
});
|
|
787
|
+
wrappedLines.push(sumChunks.join(""));
|
|
788
|
+
});
|
|
789
|
+
return wrappedLines.join("\n");
|
|
607
790
|
}
|
|
608
791
|
};
|
|
792
|
+
function stripColor(str) {
|
|
793
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
794
|
+
return str.replace(sgrPattern, "");
|
|
795
|
+
}
|
|
796
|
+
__name(stripColor, "stripColor");
|
|
609
797
|
exports.Help = Help2;
|
|
798
|
+
exports.stripColor = stripColor;
|
|
610
799
|
}
|
|
611
800
|
});
|
|
612
801
|
|
|
@@ -647,6 +836,7 @@ var require_option = __commonJS({
|
|
|
647
836
|
this.argChoices = void 0;
|
|
648
837
|
this.conflictsWith = [];
|
|
649
838
|
this.implied = void 0;
|
|
839
|
+
this.helpGroupHeading = void 0;
|
|
650
840
|
}
|
|
651
841
|
/**
|
|
652
842
|
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
@@ -757,11 +947,12 @@ var require_option = __commonJS({
|
|
|
757
947
|
/**
|
|
758
948
|
* @package
|
|
759
949
|
*/
|
|
760
|
-
|
|
950
|
+
_collectValue(value, previous) {
|
|
761
951
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
762
952
|
return [value];
|
|
763
953
|
}
|
|
764
|
-
|
|
954
|
+
previous.push(value);
|
|
955
|
+
return previous;
|
|
765
956
|
}
|
|
766
957
|
/**
|
|
767
958
|
* Only allow option value to be one of choices.
|
|
@@ -778,7 +969,7 @@ var require_option = __commonJS({
|
|
|
778
969
|
);
|
|
779
970
|
}
|
|
780
971
|
if (this.variadic) {
|
|
781
|
-
return this.
|
|
972
|
+
return this._collectValue(arg, previous);
|
|
782
973
|
}
|
|
783
974
|
return arg;
|
|
784
975
|
};
|
|
@@ -797,12 +988,25 @@ var require_option = __commonJS({
|
|
|
797
988
|
}
|
|
798
989
|
/**
|
|
799
990
|
* Return option name, in a camelcase format that can be used
|
|
800
|
-
* as
|
|
991
|
+
* as an object attribute key.
|
|
801
992
|
*
|
|
802
993
|
* @return {string}
|
|
803
994
|
*/
|
|
804
995
|
attributeName() {
|
|
805
|
-
|
|
996
|
+
if (this.negate) {
|
|
997
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
998
|
+
}
|
|
999
|
+
return camelcase(this.name());
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Set the help group heading.
|
|
1003
|
+
*
|
|
1004
|
+
* @param {string} heading
|
|
1005
|
+
* @return {Option}
|
|
1006
|
+
*/
|
|
1007
|
+
helpGroup(heading) {
|
|
1008
|
+
this.helpGroupHeading = heading;
|
|
1009
|
+
return this;
|
|
806
1010
|
}
|
|
807
1011
|
/**
|
|
808
1012
|
* Check if `arg` matches the short or long flag.
|
|
@@ -874,14 +1078,40 @@ var require_option = __commonJS({
|
|
|
874
1078
|
function splitOptionFlags(flags) {
|
|
875
1079
|
let shortFlag;
|
|
876
1080
|
let longFlag;
|
|
877
|
-
const
|
|
878
|
-
|
|
1081
|
+
const shortFlagExp = /^-[^-]$/;
|
|
1082
|
+
const longFlagExp = /^--[^-]/;
|
|
1083
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
1084
|
+
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
1085
|
+
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
1086
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
879
1087
|
shortFlag = flagParts.shift();
|
|
880
|
-
|
|
881
|
-
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
1088
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
882
1089
|
shortFlag = longFlag;
|
|
883
|
-
longFlag =
|
|
1090
|
+
longFlag = flagParts.shift();
|
|
884
1091
|
}
|
|
1092
|
+
if (flagParts[0].startsWith("-")) {
|
|
1093
|
+
const unsupportedFlag = flagParts[0];
|
|
1094
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
1095
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
1096
|
+
throw new Error(
|
|
1097
|
+
`${baseError}
|
|
1098
|
+
- a short flag is a single dash and a single character
|
|
1099
|
+
- either use a single dash and a single character (for a short flag)
|
|
1100
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`
|
|
1101
|
+
);
|
|
1102
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
1103
|
+
throw new Error(`${baseError}
|
|
1104
|
+
- too many short flags`);
|
|
1105
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
1106
|
+
throw new Error(`${baseError}
|
|
1107
|
+
- too many long flags`);
|
|
1108
|
+
throw new Error(`${baseError}
|
|
1109
|
+
- unrecognised flag format`);
|
|
1110
|
+
}
|
|
1111
|
+
if (shortFlag === void 0 && longFlag === void 0)
|
|
1112
|
+
throw new Error(
|
|
1113
|
+
`option creation failed due to no flags found in '${flags}'.`
|
|
1114
|
+
);
|
|
885
1115
|
return { shortFlag, longFlag };
|
|
886
1116
|
}
|
|
887
1117
|
__name(splitOptionFlags, "splitOptionFlags");
|
|
@@ -982,7 +1212,7 @@ var require_command = __commonJS({
|
|
|
982
1212
|
var process2 = __require("node:process");
|
|
983
1213
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
984
1214
|
var { CommanderError: CommanderError2 } = require_error();
|
|
985
|
-
var { Help: Help2 } = require_help();
|
|
1215
|
+
var { Help: Help2, stripColor } = require_help();
|
|
986
1216
|
var { Option: Option2, DualOptions } = require_option();
|
|
987
1217
|
var { suggestSimilar } = require_suggestSimilar();
|
|
988
1218
|
var Command2 = class _Command extends EventEmitter {
|
|
@@ -1000,7 +1230,7 @@ var require_command = __commonJS({
|
|
|
1000
1230
|
this.options = [];
|
|
1001
1231
|
this.parent = null;
|
|
1002
1232
|
this._allowUnknownOption = false;
|
|
1003
|
-
this._allowExcessArguments =
|
|
1233
|
+
this._allowExcessArguments = false;
|
|
1004
1234
|
this.registeredArguments = [];
|
|
1005
1235
|
this._args = this.registeredArguments;
|
|
1006
1236
|
this.args = [];
|
|
@@ -1027,18 +1257,25 @@ var require_command = __commonJS({
|
|
|
1027
1257
|
this._lifeCycleHooks = {};
|
|
1028
1258
|
this._showHelpAfterError = false;
|
|
1029
1259
|
this._showSuggestionAfterError = true;
|
|
1260
|
+
this._savedState = null;
|
|
1030
1261
|
this._outputConfiguration = {
|
|
1031
1262
|
writeOut: /* @__PURE__ */ __name((str) => process2.stdout.write(str), "writeOut"),
|
|
1032
1263
|
writeErr: /* @__PURE__ */ __name((str) => process2.stderr.write(str), "writeErr"),
|
|
1264
|
+
outputError: /* @__PURE__ */ __name((str, write) => write(str), "outputError"),
|
|
1033
1265
|
getOutHelpWidth: /* @__PURE__ */ __name(() => process2.stdout.isTTY ? process2.stdout.columns : void 0, "getOutHelpWidth"),
|
|
1034
1266
|
getErrHelpWidth: /* @__PURE__ */ __name(() => process2.stderr.isTTY ? process2.stderr.columns : void 0, "getErrHelpWidth"),
|
|
1035
|
-
|
|
1267
|
+
getOutHasColors: /* @__PURE__ */ __name(() => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()), "getOutHasColors"),
|
|
1268
|
+
getErrHasColors: /* @__PURE__ */ __name(() => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()), "getErrHasColors"),
|
|
1269
|
+
stripColor: /* @__PURE__ */ __name((str) => stripColor(str), "stripColor")
|
|
1036
1270
|
};
|
|
1037
1271
|
this._hidden = false;
|
|
1038
1272
|
this._helpOption = void 0;
|
|
1039
1273
|
this._addImplicitHelpCommand = void 0;
|
|
1040
1274
|
this._helpCommand = void 0;
|
|
1041
1275
|
this._helpConfiguration = {};
|
|
1276
|
+
this._helpGroupHeading = void 0;
|
|
1277
|
+
this._defaultCommandGroup = void 0;
|
|
1278
|
+
this._defaultOptionGroup = void 0;
|
|
1042
1279
|
}
|
|
1043
1280
|
/**
|
|
1044
1281
|
* Copy settings that are useful to have in common across root command and subcommands.
|
|
@@ -1160,21 +1397,28 @@ var require_command = __commonJS({
|
|
|
1160
1397
|
*
|
|
1161
1398
|
* The configuration properties are all functions:
|
|
1162
1399
|
*
|
|
1163
|
-
* //
|
|
1400
|
+
* // change how output being written, defaults to stdout and stderr
|
|
1164
1401
|
* writeOut(str)
|
|
1165
1402
|
* writeErr(str)
|
|
1166
|
-
* //
|
|
1403
|
+
* // change how output being written for errors, defaults to writeErr
|
|
1404
|
+
* outputError(str, write) // used for displaying errors and not used for displaying help
|
|
1405
|
+
* // specify width for wrapping help
|
|
1167
1406
|
* getOutHelpWidth()
|
|
1168
1407
|
* getErrHelpWidth()
|
|
1169
|
-
* //
|
|
1170
|
-
*
|
|
1408
|
+
* // color support, currently only used with Help
|
|
1409
|
+
* getOutHasColors()
|
|
1410
|
+
* getErrHasColors()
|
|
1411
|
+
* stripColor() // used to remove ANSI escape codes if output does not have colors
|
|
1171
1412
|
*
|
|
1172
1413
|
* @param {object} [configuration] - configuration options
|
|
1173
1414
|
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1174
1415
|
*/
|
|
1175
1416
|
configureOutput(configuration) {
|
|
1176
1417
|
if (configuration === void 0) return this._outputConfiguration;
|
|
1177
|
-
|
|
1418
|
+
this._outputConfiguration = {
|
|
1419
|
+
...this._outputConfiguration,
|
|
1420
|
+
...configuration
|
|
1421
|
+
};
|
|
1178
1422
|
return this;
|
|
1179
1423
|
}
|
|
1180
1424
|
/**
|
|
@@ -1245,16 +1489,16 @@ var require_command = __commonJS({
|
|
|
1245
1489
|
*
|
|
1246
1490
|
* @param {string} name
|
|
1247
1491
|
* @param {string} [description]
|
|
1248
|
-
* @param {(Function|*)} [
|
|
1492
|
+
* @param {(Function|*)} [parseArg] - custom argument processing function or default value
|
|
1249
1493
|
* @param {*} [defaultValue]
|
|
1250
1494
|
* @return {Command} `this` command for chaining
|
|
1251
1495
|
*/
|
|
1252
|
-
argument(name, description,
|
|
1496
|
+
argument(name, description, parseArg, defaultValue) {
|
|
1253
1497
|
const argument = this.createArgument(name, description);
|
|
1254
|
-
if (typeof
|
|
1255
|
-
argument.default(defaultValue).argParser(
|
|
1498
|
+
if (typeof parseArg === "function") {
|
|
1499
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
1256
1500
|
} else {
|
|
1257
|
-
argument.default(
|
|
1501
|
+
argument.default(parseArg);
|
|
1258
1502
|
}
|
|
1259
1503
|
this.addArgument(argument);
|
|
1260
1504
|
return this;
|
|
@@ -1284,7 +1528,7 @@ var require_command = __commonJS({
|
|
|
1284
1528
|
*/
|
|
1285
1529
|
addArgument(argument) {
|
|
1286
1530
|
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1287
|
-
if (previousArgument
|
|
1531
|
+
if (previousArgument?.variadic) {
|
|
1288
1532
|
throw new Error(
|
|
1289
1533
|
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
1290
1534
|
);
|
|
@@ -1313,10 +1557,13 @@ var require_command = __commonJS({
|
|
|
1313
1557
|
helpCommand(enableOrNameAndArgs, description) {
|
|
1314
1558
|
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1315
1559
|
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1560
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
1561
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
1562
|
+
}
|
|
1316
1563
|
return this;
|
|
1317
1564
|
}
|
|
1318
|
-
|
|
1319
|
-
const [, helpName, helpArgs] =
|
|
1565
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1566
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1320
1567
|
const helpDescription = description ?? "display help for command";
|
|
1321
1568
|
const helpCommand = this.createCommand(helpName);
|
|
1322
1569
|
helpCommand.helpOption(false);
|
|
@@ -1324,6 +1571,7 @@ var require_command = __commonJS({
|
|
|
1324
1571
|
if (helpDescription) helpCommand.description(helpDescription);
|
|
1325
1572
|
this._addImplicitHelpCommand = true;
|
|
1326
1573
|
this._helpCommand = helpCommand;
|
|
1574
|
+
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
1327
1575
|
return this;
|
|
1328
1576
|
}
|
|
1329
1577
|
/**
|
|
@@ -1340,6 +1588,7 @@ var require_command = __commonJS({
|
|
|
1340
1588
|
}
|
|
1341
1589
|
this._addImplicitHelpCommand = true;
|
|
1342
1590
|
this._helpCommand = helpCommand;
|
|
1591
|
+
this._initCommandGroup(helpCommand);
|
|
1343
1592
|
return this;
|
|
1344
1593
|
}
|
|
1345
1594
|
/**
|
|
@@ -1488,6 +1737,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1488
1737
|
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1489
1738
|
- already used by option '${matchingOption.flags}'`);
|
|
1490
1739
|
}
|
|
1740
|
+
this._initOptionGroup(option);
|
|
1491
1741
|
this.options.push(option);
|
|
1492
1742
|
}
|
|
1493
1743
|
/**
|
|
@@ -1511,6 +1761,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1511
1761
|
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
1512
1762
|
);
|
|
1513
1763
|
}
|
|
1764
|
+
this._initCommandGroup(command);
|
|
1514
1765
|
this.commands.push(command);
|
|
1515
1766
|
}
|
|
1516
1767
|
/**
|
|
@@ -1543,7 +1794,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1543
1794
|
if (val !== null && option.parseArg) {
|
|
1544
1795
|
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1545
1796
|
} else if (val !== null && option.variadic) {
|
|
1546
|
-
val = option.
|
|
1797
|
+
val = option._collectValue(val, oldValue);
|
|
1547
1798
|
}
|
|
1548
1799
|
if (val == null) {
|
|
1549
1800
|
if (option.negate) {
|
|
@@ -1607,7 +1858,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1607
1858
|
* @example
|
|
1608
1859
|
* program
|
|
1609
1860
|
* .option('-p, --pepper', 'add pepper')
|
|
1610
|
-
* .option('
|
|
1861
|
+
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
1611
1862
|
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
1612
1863
|
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
1613
1864
|
*
|
|
@@ -1874,6 +2125,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1874
2125
|
* @return {Command} `this` command for chaining
|
|
1875
2126
|
*/
|
|
1876
2127
|
parse(argv, parseOptions) {
|
|
2128
|
+
this._prepareForParse();
|
|
1877
2129
|
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1878
2130
|
this._parseCommand([], userArgs);
|
|
1879
2131
|
return this;
|
|
@@ -1899,10 +2151,68 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1899
2151
|
* @return {Promise}
|
|
1900
2152
|
*/
|
|
1901
2153
|
async parseAsync(argv, parseOptions) {
|
|
2154
|
+
this._prepareForParse();
|
|
1902
2155
|
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1903
2156
|
await this._parseCommand([], userArgs);
|
|
1904
2157
|
return this;
|
|
1905
2158
|
}
|
|
2159
|
+
_prepareForParse() {
|
|
2160
|
+
if (this._savedState === null) {
|
|
2161
|
+
this.saveStateBeforeParse();
|
|
2162
|
+
} else {
|
|
2163
|
+
this.restoreStateBeforeParse();
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
/**
|
|
2167
|
+
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
2168
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
2169
|
+
*
|
|
2170
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
2171
|
+
*/
|
|
2172
|
+
saveStateBeforeParse() {
|
|
2173
|
+
this._savedState = {
|
|
2174
|
+
// name is stable if supplied by author, but may be unspecified for root command and deduced during parsing
|
|
2175
|
+
_name: this._name,
|
|
2176
|
+
// option values before parse have default values (including false for negated options)
|
|
2177
|
+
// shallow clones
|
|
2178
|
+
_optionValues: { ...this._optionValues },
|
|
2179
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
/**
|
|
2183
|
+
* Restore state before parse for calls after the first.
|
|
2184
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
2185
|
+
*
|
|
2186
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
2187
|
+
*/
|
|
2188
|
+
restoreStateBeforeParse() {
|
|
2189
|
+
if (this._storeOptionsAsProperties)
|
|
2190
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
2191
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
2192
|
+
this._name = this._savedState._name;
|
|
2193
|
+
this._scriptPath = null;
|
|
2194
|
+
this.rawArgs = [];
|
|
2195
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
2196
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
2197
|
+
this.args = [];
|
|
2198
|
+
this.processedArgs = [];
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Throw if expected executable is missing. Add lots of help for author.
|
|
2202
|
+
*
|
|
2203
|
+
* @param {string} executableFile
|
|
2204
|
+
* @param {string} executableDir
|
|
2205
|
+
* @param {string} subcommandName
|
|
2206
|
+
*/
|
|
2207
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2208
|
+
if (fs.existsSync(executableFile)) return;
|
|
2209
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
2210
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
2211
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
2212
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
2213
|
+
- ${executableDirMessage}`;
|
|
2214
|
+
throw new Error(executableMissing);
|
|
2215
|
+
}
|
|
1906
2216
|
/**
|
|
1907
2217
|
* Execute a sub-command executable.
|
|
1908
2218
|
*
|
|
@@ -1931,7 +2241,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1931
2241
|
let resolvedScriptPath;
|
|
1932
2242
|
try {
|
|
1933
2243
|
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1934
|
-
} catch
|
|
2244
|
+
} catch {
|
|
1935
2245
|
resolvedScriptPath = this._scriptPath;
|
|
1936
2246
|
}
|
|
1937
2247
|
executableDir = path.resolve(
|
|
@@ -1966,6 +2276,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1966
2276
|
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1967
2277
|
}
|
|
1968
2278
|
} else {
|
|
2279
|
+
this._checkForMissingExecutable(
|
|
2280
|
+
executableFile,
|
|
2281
|
+
executableDir,
|
|
2282
|
+
subcommand._name
|
|
2283
|
+
);
|
|
1969
2284
|
args.unshift(executableFile);
|
|
1970
2285
|
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1971
2286
|
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
@@ -1997,12 +2312,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1997
2312
|
});
|
|
1998
2313
|
proc.on("error", (err) => {
|
|
1999
2314
|
if (err.code === "ENOENT") {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
throw new Error(executableMissing);
|
|
2315
|
+
this._checkForMissingExecutable(
|
|
2316
|
+
executableFile,
|
|
2317
|
+
executableDir,
|
|
2318
|
+
subcommand._name
|
|
2319
|
+
);
|
|
2006
2320
|
} else if (err.code === "EACCES") {
|
|
2007
2321
|
throw new Error(`'${executableFile}' not executable`);
|
|
2008
2322
|
}
|
|
@@ -2026,6 +2340,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2026
2340
|
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2027
2341
|
const subCommand = this._findCommand(commandName);
|
|
2028
2342
|
if (!subCommand) this.help({ error: true });
|
|
2343
|
+
subCommand._prepareForParse();
|
|
2029
2344
|
let promiseChain;
|
|
2030
2345
|
promiseChain = this._chainOrCallSubCommandHook(
|
|
2031
2346
|
promiseChain,
|
|
@@ -2132,7 +2447,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2132
2447
|
* @private
|
|
2133
2448
|
*/
|
|
2134
2449
|
_chainOrCall(promise, fn) {
|
|
2135
|
-
if (promise
|
|
2450
|
+
if (promise?.then && typeof promise.then === "function") {
|
|
2136
2451
|
return promise.then(() => fn());
|
|
2137
2452
|
}
|
|
2138
2453
|
return fn();
|
|
@@ -2237,7 +2552,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2237
2552
|
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
2238
2553
|
return promiseChain;
|
|
2239
2554
|
}
|
|
2240
|
-
if (this.parent
|
|
2555
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
2241
2556
|
checkForUnknownOptions();
|
|
2242
2557
|
this._processArguments();
|
|
2243
2558
|
this.parent.emit(commandEvent, operands, unknown);
|
|
@@ -2338,6 +2653,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2338
2653
|
* Parse options from `argv` removing known options,
|
|
2339
2654
|
* and return argv split into operands and unknown arguments.
|
|
2340
2655
|
*
|
|
2656
|
+
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
2657
|
+
*
|
|
2341
2658
|
* Examples:
|
|
2342
2659
|
*
|
|
2343
2660
|
* argv => operands, unknown
|
|
@@ -2346,27 +2663,35 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2346
2663
|
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
2347
2664
|
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
2348
2665
|
*
|
|
2349
|
-
* @param {string[]}
|
|
2666
|
+
* @param {string[]} args
|
|
2350
2667
|
* @return {{operands: string[], unknown: string[]}}
|
|
2351
2668
|
*/
|
|
2352
|
-
parseOptions(
|
|
2669
|
+
parseOptions(args) {
|
|
2353
2670
|
const operands = [];
|
|
2354
2671
|
const unknown = [];
|
|
2355
2672
|
let dest = operands;
|
|
2356
|
-
const args = argv.slice();
|
|
2357
2673
|
function maybeOption(arg) {
|
|
2358
2674
|
return arg.length > 1 && arg[0] === "-";
|
|
2359
2675
|
}
|
|
2360
2676
|
__name(maybeOption, "maybeOption");
|
|
2677
|
+
const negativeNumberArg = /* @__PURE__ */ __name((arg) => {
|
|
2678
|
+
if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg)) return false;
|
|
2679
|
+
return !this._getCommandAndAncestors().some(
|
|
2680
|
+
(cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
|
|
2681
|
+
);
|
|
2682
|
+
}, "negativeNumberArg");
|
|
2361
2683
|
let activeVariadicOption = null;
|
|
2362
|
-
|
|
2363
|
-
|
|
2684
|
+
let activeGroup = null;
|
|
2685
|
+
let i = 0;
|
|
2686
|
+
while (i < args.length || activeGroup) {
|
|
2687
|
+
const arg = activeGroup ?? args[i++];
|
|
2688
|
+
activeGroup = null;
|
|
2364
2689
|
if (arg === "--") {
|
|
2365
2690
|
if (dest === unknown) dest.push(arg);
|
|
2366
|
-
dest.push(...args);
|
|
2691
|
+
dest.push(...args.slice(i));
|
|
2367
2692
|
break;
|
|
2368
2693
|
}
|
|
2369
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
2694
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
2370
2695
|
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2371
2696
|
continue;
|
|
2372
2697
|
}
|
|
@@ -2375,13 +2700,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2375
2700
|
const option = this._findOption(arg);
|
|
2376
2701
|
if (option) {
|
|
2377
2702
|
if (option.required) {
|
|
2378
|
-
const value = args
|
|
2703
|
+
const value = args[i++];
|
|
2379
2704
|
if (value === void 0) this.optionMissingArgument(option);
|
|
2380
2705
|
this.emit(`option:${option.name()}`, value);
|
|
2381
2706
|
} else if (option.optional) {
|
|
2382
2707
|
let value = null;
|
|
2383
|
-
if (args.length
|
|
2384
|
-
value = args
|
|
2708
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
2709
|
+
value = args[i++];
|
|
2385
2710
|
}
|
|
2386
2711
|
this.emit(`option:${option.name()}`, value);
|
|
2387
2712
|
} else {
|
|
@@ -2398,7 +2723,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2398
2723
|
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
2399
2724
|
} else {
|
|
2400
2725
|
this.emit(`option:${option.name()}`);
|
|
2401
|
-
|
|
2726
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
2402
2727
|
}
|
|
2403
2728
|
continue;
|
|
2404
2729
|
}
|
|
@@ -2411,27 +2736,24 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2411
2736
|
continue;
|
|
2412
2737
|
}
|
|
2413
2738
|
}
|
|
2414
|
-
if (maybeOption(arg)) {
|
|
2739
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
2415
2740
|
dest = unknown;
|
|
2416
2741
|
}
|
|
2417
2742
|
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2418
2743
|
if (this._findCommand(arg)) {
|
|
2419
2744
|
operands.push(arg);
|
|
2420
|
-
|
|
2745
|
+
unknown.push(...args.slice(i));
|
|
2421
2746
|
break;
|
|
2422
2747
|
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
2423
|
-
operands.push(arg);
|
|
2424
|
-
if (args.length > 0) operands.push(...args);
|
|
2748
|
+
operands.push(arg, ...args.slice(i));
|
|
2425
2749
|
break;
|
|
2426
2750
|
} else if (this._defaultCommandName) {
|
|
2427
|
-
unknown.push(arg);
|
|
2428
|
-
if (args.length > 0) unknown.push(...args);
|
|
2751
|
+
unknown.push(arg, ...args.slice(i));
|
|
2429
2752
|
break;
|
|
2430
2753
|
}
|
|
2431
2754
|
}
|
|
2432
2755
|
if (this._passThroughOptions) {
|
|
2433
|
-
dest.push(arg);
|
|
2434
|
-
if (args.length > 0) dest.push(...args);
|
|
2756
|
+
dest.push(arg, ...args.slice(i));
|
|
2435
2757
|
break;
|
|
2436
2758
|
}
|
|
2437
2759
|
dest.push(arg);
|
|
@@ -2783,6 +3105,69 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2783
3105
|
this._name = str;
|
|
2784
3106
|
return this;
|
|
2785
3107
|
}
|
|
3108
|
+
/**
|
|
3109
|
+
* Set/get the help group heading for this subcommand in parent command's help.
|
|
3110
|
+
*
|
|
3111
|
+
* @param {string} [heading]
|
|
3112
|
+
* @return {Command | string}
|
|
3113
|
+
*/
|
|
3114
|
+
helpGroup(heading) {
|
|
3115
|
+
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
3116
|
+
this._helpGroupHeading = heading;
|
|
3117
|
+
return this;
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Set/get the default help group heading for subcommands added to this command.
|
|
3121
|
+
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
3122
|
+
*
|
|
3123
|
+
* @example
|
|
3124
|
+
* program.commandsGroup('Development Commands:);
|
|
3125
|
+
* program.command('watch')...
|
|
3126
|
+
* program.command('lint')...
|
|
3127
|
+
* ...
|
|
3128
|
+
*
|
|
3129
|
+
* @param {string} [heading]
|
|
3130
|
+
* @returns {Command | string}
|
|
3131
|
+
*/
|
|
3132
|
+
commandsGroup(heading) {
|
|
3133
|
+
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
3134
|
+
this._defaultCommandGroup = heading;
|
|
3135
|
+
return this;
|
|
3136
|
+
}
|
|
3137
|
+
/**
|
|
3138
|
+
* Set/get the default help group heading for options added to this command.
|
|
3139
|
+
* (This does not override a group set directly on the option using .helpGroup().)
|
|
3140
|
+
*
|
|
3141
|
+
* @example
|
|
3142
|
+
* program
|
|
3143
|
+
* .optionsGroup('Development Options:')
|
|
3144
|
+
* .option('-d, --debug', 'output extra debugging')
|
|
3145
|
+
* .option('-p, --profile', 'output profiling information')
|
|
3146
|
+
*
|
|
3147
|
+
* @param {string} [heading]
|
|
3148
|
+
* @returns {Command | string}
|
|
3149
|
+
*/
|
|
3150
|
+
optionsGroup(heading) {
|
|
3151
|
+
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
3152
|
+
this._defaultOptionGroup = heading;
|
|
3153
|
+
return this;
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
* @param {Option} option
|
|
3157
|
+
* @private
|
|
3158
|
+
*/
|
|
3159
|
+
_initOptionGroup(option) {
|
|
3160
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
3161
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* @param {Command} cmd
|
|
3165
|
+
* @private
|
|
3166
|
+
*/
|
|
3167
|
+
_initCommandGroup(cmd) {
|
|
3168
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
3169
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
3170
|
+
}
|
|
2786
3171
|
/**
|
|
2787
3172
|
* Set the name of the command from script filename, such as process.argv[1],
|
|
2788
3173
|
* or require.main.filename, or __filename.
|
|
@@ -2823,26 +3208,47 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2823
3208
|
*/
|
|
2824
3209
|
helpInformation(contextOptions) {
|
|
2825
3210
|
const helper = this.createHelp();
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
3211
|
+
const context = this._getOutputContext(contextOptions);
|
|
3212
|
+
helper.prepareContext({
|
|
3213
|
+
error: context.error,
|
|
3214
|
+
helpWidth: context.helpWidth,
|
|
3215
|
+
outputHasColors: context.hasColors
|
|
3216
|
+
});
|
|
3217
|
+
const text = helper.formatHelp(this, helper);
|
|
3218
|
+
if (context.hasColors) return text;
|
|
3219
|
+
return this._outputConfiguration.stripColor(text);
|
|
2830
3220
|
}
|
|
2831
3221
|
/**
|
|
3222
|
+
* @typedef HelpContext
|
|
3223
|
+
* @type {object}
|
|
3224
|
+
* @property {boolean} error
|
|
3225
|
+
* @property {number} helpWidth
|
|
3226
|
+
* @property {boolean} hasColors
|
|
3227
|
+
* @property {function} write - includes stripColor if needed
|
|
3228
|
+
*
|
|
3229
|
+
* @returns {HelpContext}
|
|
2832
3230
|
* @private
|
|
2833
3231
|
*/
|
|
2834
|
-
|
|
3232
|
+
_getOutputContext(contextOptions) {
|
|
2835
3233
|
contextOptions = contextOptions || {};
|
|
2836
|
-
const
|
|
2837
|
-
let
|
|
2838
|
-
|
|
2839
|
-
|
|
3234
|
+
const error = !!contextOptions.error;
|
|
3235
|
+
let baseWrite;
|
|
3236
|
+
let hasColors;
|
|
3237
|
+
let helpWidth;
|
|
3238
|
+
if (error) {
|
|
3239
|
+
baseWrite = /* @__PURE__ */ __name((str) => this._outputConfiguration.writeErr(str), "baseWrite");
|
|
3240
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
3241
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
2840
3242
|
} else {
|
|
2841
|
-
|
|
3243
|
+
baseWrite = /* @__PURE__ */ __name((str) => this._outputConfiguration.writeOut(str), "baseWrite");
|
|
3244
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
3245
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
2842
3246
|
}
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
3247
|
+
const write = /* @__PURE__ */ __name((str) => {
|
|
3248
|
+
if (!hasColors) str = this._outputConfiguration.stripColor(str);
|
|
3249
|
+
return baseWrite(str);
|
|
3250
|
+
}, "write");
|
|
3251
|
+
return { error, write, hasColors, helpWidth };
|
|
2846
3252
|
}
|
|
2847
3253
|
/**
|
|
2848
3254
|
* Output help information for this command.
|
|
@@ -2857,23 +3263,28 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2857
3263
|
deprecatedCallback = contextOptions;
|
|
2858
3264
|
contextOptions = void 0;
|
|
2859
3265
|
}
|
|
2860
|
-
const
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
3266
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
3267
|
+
const eventContext = {
|
|
3268
|
+
error: outputContext.error,
|
|
3269
|
+
write: outputContext.write,
|
|
3270
|
+
command: this
|
|
3271
|
+
};
|
|
3272
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
3273
|
+
this.emit("beforeHelp", eventContext);
|
|
3274
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
2864
3275
|
if (deprecatedCallback) {
|
|
2865
3276
|
helpInformation = deprecatedCallback(helpInformation);
|
|
2866
3277
|
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2867
3278
|
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2868
3279
|
}
|
|
2869
3280
|
}
|
|
2870
|
-
|
|
3281
|
+
outputContext.write(helpInformation);
|
|
2871
3282
|
if (this._getHelpOption()?.long) {
|
|
2872
3283
|
this.emit(this._getHelpOption().long);
|
|
2873
3284
|
}
|
|
2874
|
-
this.emit("afterHelp",
|
|
3285
|
+
this.emit("afterHelp", eventContext);
|
|
2875
3286
|
this._getCommandAndAncestors().forEach(
|
|
2876
|
-
(command) => command.emit("afterAllHelp",
|
|
3287
|
+
(command) => command.emit("afterAllHelp", eventContext)
|
|
2877
3288
|
);
|
|
2878
3289
|
}
|
|
2879
3290
|
/**
|
|
@@ -2891,15 +3302,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2891
3302
|
helpOption(flags, description) {
|
|
2892
3303
|
if (typeof flags === "boolean") {
|
|
2893
3304
|
if (flags) {
|
|
2894
|
-
this._helpOption
|
|
3305
|
+
if (this._helpOption === null) this._helpOption = void 0;
|
|
3306
|
+
if (this._defaultOptionGroup) {
|
|
3307
|
+
this._initOptionGroup(this._getHelpOption());
|
|
3308
|
+
}
|
|
2895
3309
|
} else {
|
|
2896
3310
|
this._helpOption = null;
|
|
2897
3311
|
}
|
|
2898
3312
|
return this;
|
|
2899
3313
|
}
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
3314
|
+
this._helpOption = this.createOption(
|
|
3315
|
+
flags ?? "-h, --help",
|
|
3316
|
+
description ?? "display help for command"
|
|
3317
|
+
);
|
|
3318
|
+
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
2903
3319
|
return this;
|
|
2904
3320
|
}
|
|
2905
3321
|
/**
|
|
@@ -2924,6 +3340,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2924
3340
|
*/
|
|
2925
3341
|
addHelpOption(option) {
|
|
2926
3342
|
this._helpOption = option;
|
|
3343
|
+
this._initOptionGroup(option);
|
|
2927
3344
|
return this;
|
|
2928
3345
|
}
|
|
2929
3346
|
/**
|
|
@@ -2935,12 +3352,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2935
3352
|
*/
|
|
2936
3353
|
help(contextOptions) {
|
|
2937
3354
|
this.outputHelp(contextOptions);
|
|
2938
|
-
let exitCode = process2.exitCode
|
|
3355
|
+
let exitCode = Number(process2.exitCode ?? 0);
|
|
2939
3356
|
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
2940
3357
|
exitCode = 1;
|
|
2941
3358
|
}
|
|
2942
3359
|
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2943
3360
|
}
|
|
3361
|
+
/**
|
|
3362
|
+
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
3363
|
+
* @typedef HelpTextEventContext
|
|
3364
|
+
* @type {object}
|
|
3365
|
+
* @property {boolean} error
|
|
3366
|
+
* @property {Command} command
|
|
3367
|
+
* @property {function} write
|
|
3368
|
+
*/
|
|
2944
3369
|
/**
|
|
2945
3370
|
* Add additional text to be displayed with the built-in help.
|
|
2946
3371
|
*
|
|
@@ -3017,7 +3442,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3017
3442
|
});
|
|
3018
3443
|
}
|
|
3019
3444
|
__name(incrementNodeInspectorPort, "incrementNodeInspectorPort");
|
|
3445
|
+
function useColor() {
|
|
3446
|
+
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
3447
|
+
return false;
|
|
3448
|
+
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== void 0)
|
|
3449
|
+
return true;
|
|
3450
|
+
return void 0;
|
|
3451
|
+
}
|
|
3452
|
+
__name(useColor, "useColor");
|
|
3020
3453
|
exports.Command = Command2;
|
|
3454
|
+
exports.useColor = useColor;
|
|
3021
3455
|
}
|
|
3022
3456
|
});
|
|
3023
3457
|
|
|
@@ -3065,7 +3499,7 @@ var {
|
|
|
3065
3499
|
} = import_index.default;
|
|
3066
3500
|
|
|
3067
3501
|
// package.json
|
|
3068
|
-
var version = "10.0.0-beta.
|
|
3502
|
+
var version = "10.0.0-beta.10";
|
|
3069
3503
|
|
|
3070
3504
|
// src/bin/run.ts
|
|
3071
3505
|
addToGlobalContext("cliVersion", version);
|
|
@@ -3087,5 +3521,5 @@ createStorybookProgram.action(async (options) => {
|
|
|
3087
3521
|
const isNeitherCiNorSandbox = !isCI() && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX);
|
|
3088
3522
|
options.debug = options.debug ?? false;
|
|
3089
3523
|
options.dev = options.dev ?? isNeitherCiNorSandbox;
|
|
3090
|
-
await
|
|
3524
|
+
await initiate(options).catch(() => process.exit(1));
|
|
3091
3525
|
}).version(String(version)).parse(process.argv);
|