@releasekit/release 0.7.19 → 0.7.20
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/cli.js +3537 -79
- package/dist/dispatcher.js +3546 -88
- package/package.json +6 -6
package/dist/cli.js
CHANGED
|
@@ -560,6 +560,3464 @@ var init_source = __esm({
|
|
|
560
560
|
}
|
|
561
561
|
});
|
|
562
562
|
|
|
563
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js
|
|
564
|
+
var require_error = __commonJS({
|
|
565
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js"(exports2) {
|
|
566
|
+
"use strict";
|
|
567
|
+
var CommanderError2 = class extends Error {
|
|
568
|
+
/**
|
|
569
|
+
* Constructs the CommanderError class
|
|
570
|
+
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
571
|
+
* @param {string} code an id string representing the error
|
|
572
|
+
* @param {string} message human-readable description of the error
|
|
573
|
+
*/
|
|
574
|
+
constructor(exitCode3, code, message) {
|
|
575
|
+
super(message);
|
|
576
|
+
Error.captureStackTrace(this, this.constructor);
|
|
577
|
+
this.name = this.constructor.name;
|
|
578
|
+
this.code = code;
|
|
579
|
+
this.exitCode = exitCode3;
|
|
580
|
+
this.nestedError = void 0;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
584
|
+
/**
|
|
585
|
+
* Constructs the InvalidArgumentError class
|
|
586
|
+
* @param {string} [message] explanation of why argument is invalid
|
|
587
|
+
*/
|
|
588
|
+
constructor(message) {
|
|
589
|
+
super(1, "commander.invalidArgument", message);
|
|
590
|
+
Error.captureStackTrace(this, this.constructor);
|
|
591
|
+
this.name = this.constructor.name;
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
exports2.CommanderError = CommanderError2;
|
|
595
|
+
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/argument.js
|
|
600
|
+
var require_argument = __commonJS({
|
|
601
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/argument.js"(exports2) {
|
|
602
|
+
"use strict";
|
|
603
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
604
|
+
var Argument2 = class {
|
|
605
|
+
/**
|
|
606
|
+
* Initialize a new command argument with the given name and description.
|
|
607
|
+
* The default is that the argument is required, and you can explicitly
|
|
608
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
609
|
+
*
|
|
610
|
+
* @param {string} name
|
|
611
|
+
* @param {string} [description]
|
|
612
|
+
*/
|
|
613
|
+
constructor(name, description) {
|
|
614
|
+
this.description = description || "";
|
|
615
|
+
this.variadic = false;
|
|
616
|
+
this.parseArg = void 0;
|
|
617
|
+
this.defaultValue = void 0;
|
|
618
|
+
this.defaultValueDescription = void 0;
|
|
619
|
+
this.argChoices = void 0;
|
|
620
|
+
switch (name[0]) {
|
|
621
|
+
case "<":
|
|
622
|
+
this.required = true;
|
|
623
|
+
this._name = name.slice(1, -1);
|
|
624
|
+
break;
|
|
625
|
+
case "[":
|
|
626
|
+
this.required = false;
|
|
627
|
+
this._name = name.slice(1, -1);
|
|
628
|
+
break;
|
|
629
|
+
default:
|
|
630
|
+
this.required = true;
|
|
631
|
+
this._name = name;
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
if (this._name.endsWith("...")) {
|
|
635
|
+
this.variadic = true;
|
|
636
|
+
this._name = this._name.slice(0, -3);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Return argument name.
|
|
641
|
+
*
|
|
642
|
+
* @return {string}
|
|
643
|
+
*/
|
|
644
|
+
name() {
|
|
645
|
+
return this._name;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* @package
|
|
649
|
+
*/
|
|
650
|
+
_collectValue(value, previous) {
|
|
651
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
652
|
+
return [value];
|
|
653
|
+
}
|
|
654
|
+
previous.push(value);
|
|
655
|
+
return previous;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
659
|
+
*
|
|
660
|
+
* @param {*} value
|
|
661
|
+
* @param {string} [description]
|
|
662
|
+
* @return {Argument}
|
|
663
|
+
*/
|
|
664
|
+
default(value, description) {
|
|
665
|
+
this.defaultValue = value;
|
|
666
|
+
this.defaultValueDescription = description;
|
|
667
|
+
return this;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Set the custom handler for processing CLI command arguments into argument values.
|
|
671
|
+
*
|
|
672
|
+
* @param {Function} [fn]
|
|
673
|
+
* @return {Argument}
|
|
674
|
+
*/
|
|
675
|
+
argParser(fn) {
|
|
676
|
+
this.parseArg = fn;
|
|
677
|
+
return this;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Only allow argument value to be one of choices.
|
|
681
|
+
*
|
|
682
|
+
* @param {string[]} values
|
|
683
|
+
* @return {Argument}
|
|
684
|
+
*/
|
|
685
|
+
choices(values) {
|
|
686
|
+
this.argChoices = values.slice();
|
|
687
|
+
this.parseArg = (arg, previous) => {
|
|
688
|
+
if (!this.argChoices.includes(arg)) {
|
|
689
|
+
throw new InvalidArgumentError2(
|
|
690
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
if (this.variadic) {
|
|
694
|
+
return this._collectValue(arg, previous);
|
|
695
|
+
}
|
|
696
|
+
return arg;
|
|
697
|
+
};
|
|
698
|
+
return this;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Make argument required.
|
|
702
|
+
*
|
|
703
|
+
* @returns {Argument}
|
|
704
|
+
*/
|
|
705
|
+
argRequired() {
|
|
706
|
+
this.required = true;
|
|
707
|
+
return this;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Make argument optional.
|
|
711
|
+
*
|
|
712
|
+
* @returns {Argument}
|
|
713
|
+
*/
|
|
714
|
+
argOptional() {
|
|
715
|
+
this.required = false;
|
|
716
|
+
return this;
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
function humanReadableArgName(arg) {
|
|
720
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
721
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
722
|
+
}
|
|
723
|
+
exports2.Argument = Argument2;
|
|
724
|
+
exports2.humanReadableArgName = humanReadableArgName;
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/help.js
|
|
729
|
+
var require_help = __commonJS({
|
|
730
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/help.js"(exports2) {
|
|
731
|
+
"use strict";
|
|
732
|
+
var { humanReadableArgName } = require_argument();
|
|
733
|
+
var Help2 = class {
|
|
734
|
+
constructor() {
|
|
735
|
+
this.helpWidth = void 0;
|
|
736
|
+
this.minWidthToWrap = 40;
|
|
737
|
+
this.sortSubcommands = false;
|
|
738
|
+
this.sortOptions = false;
|
|
739
|
+
this.showGlobalOptions = false;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
743
|
+
* and just before calling `formatHelp()`.
|
|
744
|
+
*
|
|
745
|
+
* Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.
|
|
746
|
+
*
|
|
747
|
+
* @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions
|
|
748
|
+
*/
|
|
749
|
+
prepareContext(contextOptions) {
|
|
750
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
754
|
+
*
|
|
755
|
+
* @param {Command} cmd
|
|
756
|
+
* @returns {Command[]}
|
|
757
|
+
*/
|
|
758
|
+
visibleCommands(cmd) {
|
|
759
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
760
|
+
const helpCommand = cmd._getHelpCommand();
|
|
761
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
762
|
+
visibleCommands.push(helpCommand);
|
|
763
|
+
}
|
|
764
|
+
if (this.sortSubcommands) {
|
|
765
|
+
visibleCommands.sort((a, b) => {
|
|
766
|
+
return a.name().localeCompare(b.name());
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
return visibleCommands;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Compare options for sort.
|
|
773
|
+
*
|
|
774
|
+
* @param {Option} a
|
|
775
|
+
* @param {Option} b
|
|
776
|
+
* @returns {number}
|
|
777
|
+
*/
|
|
778
|
+
compareOptions(a, b) {
|
|
779
|
+
const getSortKey = (option) => {
|
|
780
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
781
|
+
};
|
|
782
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
786
|
+
*
|
|
787
|
+
* @param {Command} cmd
|
|
788
|
+
* @returns {Option[]}
|
|
789
|
+
*/
|
|
790
|
+
visibleOptions(cmd) {
|
|
791
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
792
|
+
const helpOption = cmd._getHelpOption();
|
|
793
|
+
if (helpOption && !helpOption.hidden) {
|
|
794
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
795
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
796
|
+
if (!removeShort && !removeLong) {
|
|
797
|
+
visibleOptions.push(helpOption);
|
|
798
|
+
} else if (helpOption.long && !removeLong) {
|
|
799
|
+
visibleOptions.push(
|
|
800
|
+
cmd.createOption(helpOption.long, helpOption.description)
|
|
801
|
+
);
|
|
802
|
+
} else if (helpOption.short && !removeShort) {
|
|
803
|
+
visibleOptions.push(
|
|
804
|
+
cmd.createOption(helpOption.short, helpOption.description)
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (this.sortOptions) {
|
|
809
|
+
visibleOptions.sort(this.compareOptions);
|
|
810
|
+
}
|
|
811
|
+
return visibleOptions;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Get an array of the visible global options. (Not including help.)
|
|
815
|
+
*
|
|
816
|
+
* @param {Command} cmd
|
|
817
|
+
* @returns {Option[]}
|
|
818
|
+
*/
|
|
819
|
+
visibleGlobalOptions(cmd) {
|
|
820
|
+
if (!this.showGlobalOptions) return [];
|
|
821
|
+
const globalOptions = [];
|
|
822
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
823
|
+
const visibleOptions = ancestorCmd.options.filter(
|
|
824
|
+
(option) => !option.hidden
|
|
825
|
+
);
|
|
826
|
+
globalOptions.push(...visibleOptions);
|
|
827
|
+
}
|
|
828
|
+
if (this.sortOptions) {
|
|
829
|
+
globalOptions.sort(this.compareOptions);
|
|
830
|
+
}
|
|
831
|
+
return globalOptions;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Get an array of the arguments if any have a description.
|
|
835
|
+
*
|
|
836
|
+
* @param {Command} cmd
|
|
837
|
+
* @returns {Argument[]}
|
|
838
|
+
*/
|
|
839
|
+
visibleArguments(cmd) {
|
|
840
|
+
if (cmd._argsDescription) {
|
|
841
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
842
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
846
|
+
return cmd.registeredArguments;
|
|
847
|
+
}
|
|
848
|
+
return [];
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Get the command term to show in the list of subcommands.
|
|
852
|
+
*
|
|
853
|
+
* @param {Command} cmd
|
|
854
|
+
* @returns {string}
|
|
855
|
+
*/
|
|
856
|
+
subcommandTerm(cmd) {
|
|
857
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
858
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
859
|
+
(args ? " " + args : "");
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Get the option term to show in the list of options.
|
|
863
|
+
*
|
|
864
|
+
* @param {Option} option
|
|
865
|
+
* @returns {string}
|
|
866
|
+
*/
|
|
867
|
+
optionTerm(option) {
|
|
868
|
+
return option.flags;
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Get the argument term to show in the list of arguments.
|
|
872
|
+
*
|
|
873
|
+
* @param {Argument} argument
|
|
874
|
+
* @returns {string}
|
|
875
|
+
*/
|
|
876
|
+
argumentTerm(argument) {
|
|
877
|
+
return argument.name();
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Get the longest command term length.
|
|
881
|
+
*
|
|
882
|
+
* @param {Command} cmd
|
|
883
|
+
* @param {Help} helper
|
|
884
|
+
* @returns {number}
|
|
885
|
+
*/
|
|
886
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
887
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
888
|
+
return Math.max(
|
|
889
|
+
max,
|
|
890
|
+
this.displayWidth(
|
|
891
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(command))
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
}, 0);
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Get the longest option term length.
|
|
898
|
+
*
|
|
899
|
+
* @param {Command} cmd
|
|
900
|
+
* @param {Help} helper
|
|
901
|
+
* @returns {number}
|
|
902
|
+
*/
|
|
903
|
+
longestOptionTermLength(cmd, helper) {
|
|
904
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
905
|
+
return Math.max(
|
|
906
|
+
max,
|
|
907
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
908
|
+
);
|
|
909
|
+
}, 0);
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Get the longest global option term length.
|
|
913
|
+
*
|
|
914
|
+
* @param {Command} cmd
|
|
915
|
+
* @param {Help} helper
|
|
916
|
+
* @returns {number}
|
|
917
|
+
*/
|
|
918
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
919
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
920
|
+
return Math.max(
|
|
921
|
+
max,
|
|
922
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
923
|
+
);
|
|
924
|
+
}, 0);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Get the longest argument term length.
|
|
928
|
+
*
|
|
929
|
+
* @param {Command} cmd
|
|
930
|
+
* @param {Help} helper
|
|
931
|
+
* @returns {number}
|
|
932
|
+
*/
|
|
933
|
+
longestArgumentTermLength(cmd, helper) {
|
|
934
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
935
|
+
return Math.max(
|
|
936
|
+
max,
|
|
937
|
+
this.displayWidth(
|
|
938
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument))
|
|
939
|
+
)
|
|
940
|
+
);
|
|
941
|
+
}, 0);
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
945
|
+
*
|
|
946
|
+
* @param {Command} cmd
|
|
947
|
+
* @returns {string}
|
|
948
|
+
*/
|
|
949
|
+
commandUsage(cmd) {
|
|
950
|
+
let cmdName = cmd._name;
|
|
951
|
+
if (cmd._aliases[0]) {
|
|
952
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
953
|
+
}
|
|
954
|
+
let ancestorCmdNames = "";
|
|
955
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
956
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
957
|
+
}
|
|
958
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Get the description for the command.
|
|
962
|
+
*
|
|
963
|
+
* @param {Command} cmd
|
|
964
|
+
* @returns {string}
|
|
965
|
+
*/
|
|
966
|
+
commandDescription(cmd) {
|
|
967
|
+
return cmd.description();
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
971
|
+
* (Fallback to description for backwards compatibility.)
|
|
972
|
+
*
|
|
973
|
+
* @param {Command} cmd
|
|
974
|
+
* @returns {string}
|
|
975
|
+
*/
|
|
976
|
+
subcommandDescription(cmd) {
|
|
977
|
+
return cmd.summary() || cmd.description();
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Get the option description to show in the list of options.
|
|
981
|
+
*
|
|
982
|
+
* @param {Option} option
|
|
983
|
+
* @return {string}
|
|
984
|
+
*/
|
|
985
|
+
optionDescription(option) {
|
|
986
|
+
const extraInfo = [];
|
|
987
|
+
if (option.argChoices) {
|
|
988
|
+
extraInfo.push(
|
|
989
|
+
// use stringify to match the display of the default value
|
|
990
|
+
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
if (option.defaultValue !== void 0) {
|
|
994
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
995
|
+
if (showDefault) {
|
|
996
|
+
extraInfo.push(
|
|
997
|
+
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
if (option.presetArg !== void 0 && option.optional) {
|
|
1002
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
1003
|
+
}
|
|
1004
|
+
if (option.envVar !== void 0) {
|
|
1005
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
1006
|
+
}
|
|
1007
|
+
if (extraInfo.length > 0) {
|
|
1008
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1009
|
+
if (option.description) {
|
|
1010
|
+
return `${option.description} ${extraDescription}`;
|
|
1011
|
+
}
|
|
1012
|
+
return extraDescription;
|
|
1013
|
+
}
|
|
1014
|
+
return option.description;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Get the argument description to show in the list of arguments.
|
|
1018
|
+
*
|
|
1019
|
+
* @param {Argument} argument
|
|
1020
|
+
* @return {string}
|
|
1021
|
+
*/
|
|
1022
|
+
argumentDescription(argument) {
|
|
1023
|
+
const extraInfo = [];
|
|
1024
|
+
if (argument.argChoices) {
|
|
1025
|
+
extraInfo.push(
|
|
1026
|
+
// use stringify to match the display of the default value
|
|
1027
|
+
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
if (argument.defaultValue !== void 0) {
|
|
1031
|
+
extraInfo.push(
|
|
1032
|
+
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
if (extraInfo.length > 0) {
|
|
1036
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1037
|
+
if (argument.description) {
|
|
1038
|
+
return `${argument.description} ${extraDescription}`;
|
|
1039
|
+
}
|
|
1040
|
+
return extraDescription;
|
|
1041
|
+
}
|
|
1042
|
+
return argument.description;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
1046
|
+
*
|
|
1047
|
+
* @param {string} heading
|
|
1048
|
+
* @param {string[]} items
|
|
1049
|
+
* @param {Help} helper
|
|
1050
|
+
* @returns string[]
|
|
1051
|
+
*/
|
|
1052
|
+
formatItemList(heading, items, helper) {
|
|
1053
|
+
if (items.length === 0) return [];
|
|
1054
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Group items by their help group heading.
|
|
1058
|
+
*
|
|
1059
|
+
* @param {Command[] | Option[]} unsortedItems
|
|
1060
|
+
* @param {Command[] | Option[]} visibleItems
|
|
1061
|
+
* @param {Function} getGroup
|
|
1062
|
+
* @returns {Map<string, Command[] | Option[]>}
|
|
1063
|
+
*/
|
|
1064
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
1065
|
+
const result = /* @__PURE__ */ new Map();
|
|
1066
|
+
unsortedItems.forEach((item) => {
|
|
1067
|
+
const group = getGroup(item);
|
|
1068
|
+
if (!result.has(group)) result.set(group, []);
|
|
1069
|
+
});
|
|
1070
|
+
visibleItems.forEach((item) => {
|
|
1071
|
+
const group = getGroup(item);
|
|
1072
|
+
if (!result.has(group)) {
|
|
1073
|
+
result.set(group, []);
|
|
1074
|
+
}
|
|
1075
|
+
result.get(group).push(item);
|
|
1076
|
+
});
|
|
1077
|
+
return result;
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Generate the built-in help text.
|
|
1081
|
+
*
|
|
1082
|
+
* @param {Command} cmd
|
|
1083
|
+
* @param {Help} helper
|
|
1084
|
+
* @returns {string}
|
|
1085
|
+
*/
|
|
1086
|
+
formatHelp(cmd, helper) {
|
|
1087
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
1088
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
1089
|
+
function callFormatItem(term, description) {
|
|
1090
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
1091
|
+
}
|
|
1092
|
+
let output3 = [
|
|
1093
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
1094
|
+
""
|
|
1095
|
+
];
|
|
1096
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
1097
|
+
if (commandDescription.length > 0) {
|
|
1098
|
+
output3 = output3.concat([
|
|
1099
|
+
helper.boxWrap(
|
|
1100
|
+
helper.styleCommandDescription(commandDescription),
|
|
1101
|
+
helpWidth
|
|
1102
|
+
),
|
|
1103
|
+
""
|
|
1104
|
+
]);
|
|
1105
|
+
}
|
|
1106
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
1107
|
+
return callFormatItem(
|
|
1108
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
1109
|
+
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
1110
|
+
);
|
|
1111
|
+
});
|
|
1112
|
+
output3 = output3.concat(
|
|
1113
|
+
this.formatItemList("Arguments:", argumentList, helper)
|
|
1114
|
+
);
|
|
1115
|
+
const optionGroups = this.groupItems(
|
|
1116
|
+
cmd.options,
|
|
1117
|
+
helper.visibleOptions(cmd),
|
|
1118
|
+
(option) => option.helpGroupHeading ?? "Options:"
|
|
1119
|
+
);
|
|
1120
|
+
optionGroups.forEach((options, group) => {
|
|
1121
|
+
const optionList = options.map((option) => {
|
|
1122
|
+
return callFormatItem(
|
|
1123
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
1124
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
1125
|
+
);
|
|
1126
|
+
});
|
|
1127
|
+
output3 = output3.concat(this.formatItemList(group, optionList, helper));
|
|
1128
|
+
});
|
|
1129
|
+
if (helper.showGlobalOptions) {
|
|
1130
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
1131
|
+
return callFormatItem(
|
|
1132
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
1133
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
1134
|
+
);
|
|
1135
|
+
});
|
|
1136
|
+
output3 = output3.concat(
|
|
1137
|
+
this.formatItemList("Global Options:", globalOptionList, helper)
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
const commandGroups = this.groupItems(
|
|
1141
|
+
cmd.commands,
|
|
1142
|
+
helper.visibleCommands(cmd),
|
|
1143
|
+
(sub) => sub.helpGroup() || "Commands:"
|
|
1144
|
+
);
|
|
1145
|
+
commandGroups.forEach((commands, group) => {
|
|
1146
|
+
const commandList = commands.map((sub) => {
|
|
1147
|
+
return callFormatItem(
|
|
1148
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
1149
|
+
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
1150
|
+
);
|
|
1151
|
+
});
|
|
1152
|
+
output3 = output3.concat(this.formatItemList(group, commandList, helper));
|
|
1153
|
+
});
|
|
1154
|
+
return output3.join("\n");
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
1158
|
+
*
|
|
1159
|
+
* @param {string} str
|
|
1160
|
+
* @returns {number}
|
|
1161
|
+
*/
|
|
1162
|
+
displayWidth(str3) {
|
|
1163
|
+
return stripColor(str3).length;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
1167
|
+
*
|
|
1168
|
+
* @param {string} str
|
|
1169
|
+
* @returns {string}
|
|
1170
|
+
*/
|
|
1171
|
+
styleTitle(str3) {
|
|
1172
|
+
return str3;
|
|
1173
|
+
}
|
|
1174
|
+
styleUsage(str3) {
|
|
1175
|
+
return str3.split(" ").map((word) => {
|
|
1176
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
1177
|
+
if (word === "[command]") return this.styleSubcommandText(word);
|
|
1178
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1179
|
+
return this.styleArgumentText(word);
|
|
1180
|
+
return this.styleCommandText(word);
|
|
1181
|
+
}).join(" ");
|
|
1182
|
+
}
|
|
1183
|
+
styleCommandDescription(str3) {
|
|
1184
|
+
return this.styleDescriptionText(str3);
|
|
1185
|
+
}
|
|
1186
|
+
styleOptionDescription(str3) {
|
|
1187
|
+
return this.styleDescriptionText(str3);
|
|
1188
|
+
}
|
|
1189
|
+
styleSubcommandDescription(str3) {
|
|
1190
|
+
return this.styleDescriptionText(str3);
|
|
1191
|
+
}
|
|
1192
|
+
styleArgumentDescription(str3) {
|
|
1193
|
+
return this.styleDescriptionText(str3);
|
|
1194
|
+
}
|
|
1195
|
+
styleDescriptionText(str3) {
|
|
1196
|
+
return str3;
|
|
1197
|
+
}
|
|
1198
|
+
styleOptionTerm(str3) {
|
|
1199
|
+
return this.styleOptionText(str3);
|
|
1200
|
+
}
|
|
1201
|
+
styleSubcommandTerm(str3) {
|
|
1202
|
+
return str3.split(" ").map((word) => {
|
|
1203
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
1204
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1205
|
+
return this.styleArgumentText(word);
|
|
1206
|
+
return this.styleSubcommandText(word);
|
|
1207
|
+
}).join(" ");
|
|
1208
|
+
}
|
|
1209
|
+
styleArgumentTerm(str3) {
|
|
1210
|
+
return this.styleArgumentText(str3);
|
|
1211
|
+
}
|
|
1212
|
+
styleOptionText(str3) {
|
|
1213
|
+
return str3;
|
|
1214
|
+
}
|
|
1215
|
+
styleArgumentText(str3) {
|
|
1216
|
+
return str3;
|
|
1217
|
+
}
|
|
1218
|
+
styleSubcommandText(str3) {
|
|
1219
|
+
return str3;
|
|
1220
|
+
}
|
|
1221
|
+
styleCommandText(str3) {
|
|
1222
|
+
return str3;
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Calculate the pad width from the maximum term length.
|
|
1226
|
+
*
|
|
1227
|
+
* @param {Command} cmd
|
|
1228
|
+
* @param {Help} helper
|
|
1229
|
+
* @returns {number}
|
|
1230
|
+
*/
|
|
1231
|
+
padWidth(cmd, helper) {
|
|
1232
|
+
return Math.max(
|
|
1233
|
+
helper.longestOptionTermLength(cmd, helper),
|
|
1234
|
+
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
1235
|
+
helper.longestSubcommandTermLength(cmd, helper),
|
|
1236
|
+
helper.longestArgumentTermLength(cmd, helper)
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
1241
|
+
*
|
|
1242
|
+
* @param {string} str
|
|
1243
|
+
* @returns {boolean}
|
|
1244
|
+
*/
|
|
1245
|
+
preformatted(str3) {
|
|
1246
|
+
return /\n[^\S\r\n]/.test(str3);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
1250
|
+
*
|
|
1251
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
1252
|
+
* TTT DDD DDDD
|
|
1253
|
+
* DD DDD
|
|
1254
|
+
*
|
|
1255
|
+
* @param {string} term
|
|
1256
|
+
* @param {number} termWidth
|
|
1257
|
+
* @param {string} description
|
|
1258
|
+
* @param {Help} helper
|
|
1259
|
+
* @returns {string}
|
|
1260
|
+
*/
|
|
1261
|
+
formatItem(term, termWidth, description, helper) {
|
|
1262
|
+
const itemIndent = 2;
|
|
1263
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
1264
|
+
if (!description) return itemIndentStr + term;
|
|
1265
|
+
const paddedTerm = term.padEnd(
|
|
1266
|
+
termWidth + term.length - helper.displayWidth(term)
|
|
1267
|
+
);
|
|
1268
|
+
const spacerWidth = 2;
|
|
1269
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
1270
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
1271
|
+
let formattedDescription;
|
|
1272
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
1273
|
+
formattedDescription = description;
|
|
1274
|
+
} else {
|
|
1275
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
1276
|
+
formattedDescription = wrappedDescription.replace(
|
|
1277
|
+
/\n/g,
|
|
1278
|
+
"\n" + " ".repeat(termWidth + spacerWidth)
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
1282
|
+
${itemIndentStr}`);
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
1286
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
1287
|
+
*
|
|
1288
|
+
* @param {string} str
|
|
1289
|
+
* @param {number} width
|
|
1290
|
+
* @returns {string}
|
|
1291
|
+
*/
|
|
1292
|
+
boxWrap(str3, width) {
|
|
1293
|
+
if (width < this.minWidthToWrap) return str3;
|
|
1294
|
+
const rawLines = str3.split(/\r\n|\n/);
|
|
1295
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
1296
|
+
const wrappedLines = [];
|
|
1297
|
+
rawLines.forEach((line) => {
|
|
1298
|
+
const chunks = line.match(chunkPattern);
|
|
1299
|
+
if (chunks === null) {
|
|
1300
|
+
wrappedLines.push("");
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
let sumChunks = [chunks.shift()];
|
|
1304
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
1305
|
+
chunks.forEach((chunk) => {
|
|
1306
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
1307
|
+
if (sumWidth + visibleWidth <= width) {
|
|
1308
|
+
sumChunks.push(chunk);
|
|
1309
|
+
sumWidth += visibleWidth;
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
wrappedLines.push(sumChunks.join(""));
|
|
1313
|
+
const nextChunk = chunk.trimStart();
|
|
1314
|
+
sumChunks = [nextChunk];
|
|
1315
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
1316
|
+
});
|
|
1317
|
+
wrappedLines.push(sumChunks.join(""));
|
|
1318
|
+
});
|
|
1319
|
+
return wrappedLines.join("\n");
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
function stripColor(str3) {
|
|
1323
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
1324
|
+
return str3.replace(sgrPattern, "");
|
|
1325
|
+
}
|
|
1326
|
+
exports2.Help = Help2;
|
|
1327
|
+
exports2.stripColor = stripColor;
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
|
|
1331
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/option.js
|
|
1332
|
+
var require_option = __commonJS({
|
|
1333
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/option.js"(exports2) {
|
|
1334
|
+
"use strict";
|
|
1335
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
1336
|
+
var Option2 = class {
|
|
1337
|
+
/**
|
|
1338
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
1339
|
+
*
|
|
1340
|
+
* @param {string} flags
|
|
1341
|
+
* @param {string} [description]
|
|
1342
|
+
*/
|
|
1343
|
+
constructor(flags, description) {
|
|
1344
|
+
this.flags = flags;
|
|
1345
|
+
this.description = description || "";
|
|
1346
|
+
this.required = flags.includes("<");
|
|
1347
|
+
this.optional = flags.includes("[");
|
|
1348
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
1349
|
+
this.mandatory = false;
|
|
1350
|
+
const optionFlags = splitOptionFlags(flags);
|
|
1351
|
+
this.short = optionFlags.shortFlag;
|
|
1352
|
+
this.long = optionFlags.longFlag;
|
|
1353
|
+
this.negate = false;
|
|
1354
|
+
if (this.long) {
|
|
1355
|
+
this.negate = this.long.startsWith("--no-");
|
|
1356
|
+
}
|
|
1357
|
+
this.defaultValue = void 0;
|
|
1358
|
+
this.defaultValueDescription = void 0;
|
|
1359
|
+
this.presetArg = void 0;
|
|
1360
|
+
this.envVar = void 0;
|
|
1361
|
+
this.parseArg = void 0;
|
|
1362
|
+
this.hidden = false;
|
|
1363
|
+
this.argChoices = void 0;
|
|
1364
|
+
this.conflictsWith = [];
|
|
1365
|
+
this.implied = void 0;
|
|
1366
|
+
this.helpGroupHeading = void 0;
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
1370
|
+
*
|
|
1371
|
+
* @param {*} value
|
|
1372
|
+
* @param {string} [description]
|
|
1373
|
+
* @return {Option}
|
|
1374
|
+
*/
|
|
1375
|
+
default(value, description) {
|
|
1376
|
+
this.defaultValue = value;
|
|
1377
|
+
this.defaultValueDescription = description;
|
|
1378
|
+
return this;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
1382
|
+
* The custom processing (parseArg) is called.
|
|
1383
|
+
*
|
|
1384
|
+
* @example
|
|
1385
|
+
* new Option('--color').default('GREYSCALE').preset('RGB');
|
|
1386
|
+
* new Option('--donate [amount]').preset('20').argParser(parseFloat);
|
|
1387
|
+
*
|
|
1388
|
+
* @param {*} arg
|
|
1389
|
+
* @return {Option}
|
|
1390
|
+
*/
|
|
1391
|
+
preset(arg) {
|
|
1392
|
+
this.presetArg = arg;
|
|
1393
|
+
return this;
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Add option name(s) that conflict with this option.
|
|
1397
|
+
* An error will be displayed if conflicting options are found during parsing.
|
|
1398
|
+
*
|
|
1399
|
+
* @example
|
|
1400
|
+
* new Option('--rgb').conflicts('cmyk');
|
|
1401
|
+
* new Option('--js').conflicts(['ts', 'jsx']);
|
|
1402
|
+
*
|
|
1403
|
+
* @param {(string | string[])} names
|
|
1404
|
+
* @return {Option}
|
|
1405
|
+
*/
|
|
1406
|
+
conflicts(names) {
|
|
1407
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
1408
|
+
return this;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Specify implied option values for when this option is set and the implied options are not.
|
|
1412
|
+
*
|
|
1413
|
+
* The custom processing (parseArg) is not called on the implied values.
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* program
|
|
1417
|
+
* .addOption(new Option('--log', 'write logging information to file'))
|
|
1418
|
+
* .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
|
|
1419
|
+
*
|
|
1420
|
+
* @param {object} impliedOptionValues
|
|
1421
|
+
* @return {Option}
|
|
1422
|
+
*/
|
|
1423
|
+
implies(impliedOptionValues) {
|
|
1424
|
+
let newImplied = impliedOptionValues;
|
|
1425
|
+
if (typeof impliedOptionValues === "string") {
|
|
1426
|
+
newImplied = { [impliedOptionValues]: true };
|
|
1427
|
+
}
|
|
1428
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
1429
|
+
return this;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Set environment variable to check for option value.
|
|
1433
|
+
*
|
|
1434
|
+
* An environment variable is only used if when processed the current option value is
|
|
1435
|
+
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
|
|
1436
|
+
*
|
|
1437
|
+
* @param {string} name
|
|
1438
|
+
* @return {Option}
|
|
1439
|
+
*/
|
|
1440
|
+
env(name) {
|
|
1441
|
+
this.envVar = name;
|
|
1442
|
+
return this;
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Set the custom handler for processing CLI option arguments into option values.
|
|
1446
|
+
*
|
|
1447
|
+
* @param {Function} [fn]
|
|
1448
|
+
* @return {Option}
|
|
1449
|
+
*/
|
|
1450
|
+
argParser(fn) {
|
|
1451
|
+
this.parseArg = fn;
|
|
1452
|
+
return this;
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Whether the option is mandatory and must have a value after parsing.
|
|
1456
|
+
*
|
|
1457
|
+
* @param {boolean} [mandatory=true]
|
|
1458
|
+
* @return {Option}
|
|
1459
|
+
*/
|
|
1460
|
+
makeOptionMandatory(mandatory = true) {
|
|
1461
|
+
this.mandatory = !!mandatory;
|
|
1462
|
+
return this;
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Hide option in help.
|
|
1466
|
+
*
|
|
1467
|
+
* @param {boolean} [hide=true]
|
|
1468
|
+
* @return {Option}
|
|
1469
|
+
*/
|
|
1470
|
+
hideHelp(hide = true) {
|
|
1471
|
+
this.hidden = !!hide;
|
|
1472
|
+
return this;
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* @package
|
|
1476
|
+
*/
|
|
1477
|
+
_collectValue(value, previous) {
|
|
1478
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
1479
|
+
return [value];
|
|
1480
|
+
}
|
|
1481
|
+
previous.push(value);
|
|
1482
|
+
return previous;
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Only allow option value to be one of choices.
|
|
1486
|
+
*
|
|
1487
|
+
* @param {string[]} values
|
|
1488
|
+
* @return {Option}
|
|
1489
|
+
*/
|
|
1490
|
+
choices(values) {
|
|
1491
|
+
this.argChoices = values.slice();
|
|
1492
|
+
this.parseArg = (arg, previous) => {
|
|
1493
|
+
if (!this.argChoices.includes(arg)) {
|
|
1494
|
+
throw new InvalidArgumentError2(
|
|
1495
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
if (this.variadic) {
|
|
1499
|
+
return this._collectValue(arg, previous);
|
|
1500
|
+
}
|
|
1501
|
+
return arg;
|
|
1502
|
+
};
|
|
1503
|
+
return this;
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* Return option name.
|
|
1507
|
+
*
|
|
1508
|
+
* @return {string}
|
|
1509
|
+
*/
|
|
1510
|
+
name() {
|
|
1511
|
+
if (this.long) {
|
|
1512
|
+
return this.long.replace(/^--/, "");
|
|
1513
|
+
}
|
|
1514
|
+
return this.short.replace(/^-/, "");
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Return option name, in a camelcase format that can be used
|
|
1518
|
+
* as an object attribute key.
|
|
1519
|
+
*
|
|
1520
|
+
* @return {string}
|
|
1521
|
+
*/
|
|
1522
|
+
attributeName() {
|
|
1523
|
+
if (this.negate) {
|
|
1524
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
1525
|
+
}
|
|
1526
|
+
return camelcase(this.name());
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Set the help group heading.
|
|
1530
|
+
*
|
|
1531
|
+
* @param {string} heading
|
|
1532
|
+
* @return {Option}
|
|
1533
|
+
*/
|
|
1534
|
+
helpGroup(heading) {
|
|
1535
|
+
this.helpGroupHeading = heading;
|
|
1536
|
+
return this;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Check if `arg` matches the short or long flag.
|
|
1540
|
+
*
|
|
1541
|
+
* @param {string} arg
|
|
1542
|
+
* @return {boolean}
|
|
1543
|
+
* @package
|
|
1544
|
+
*/
|
|
1545
|
+
is(arg) {
|
|
1546
|
+
return this.short === arg || this.long === arg;
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Return whether a boolean option.
|
|
1550
|
+
*
|
|
1551
|
+
* Options are one of boolean, negated, required argument, or optional argument.
|
|
1552
|
+
*
|
|
1553
|
+
* @return {boolean}
|
|
1554
|
+
* @package
|
|
1555
|
+
*/
|
|
1556
|
+
isBoolean() {
|
|
1557
|
+
return !this.required && !this.optional && !this.negate;
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
var DualOptions = class {
|
|
1561
|
+
/**
|
|
1562
|
+
* @param {Option[]} options
|
|
1563
|
+
*/
|
|
1564
|
+
constructor(options) {
|
|
1565
|
+
this.positiveOptions = /* @__PURE__ */ new Map();
|
|
1566
|
+
this.negativeOptions = /* @__PURE__ */ new Map();
|
|
1567
|
+
this.dualOptions = /* @__PURE__ */ new Set();
|
|
1568
|
+
options.forEach((option) => {
|
|
1569
|
+
if (option.negate) {
|
|
1570
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
1571
|
+
} else {
|
|
1572
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
this.negativeOptions.forEach((value, key) => {
|
|
1576
|
+
if (this.positiveOptions.has(key)) {
|
|
1577
|
+
this.dualOptions.add(key);
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Did the value come from the option, and not from possible matching dual option?
|
|
1583
|
+
*
|
|
1584
|
+
* @param {*} value
|
|
1585
|
+
* @param {Option} option
|
|
1586
|
+
* @returns {boolean}
|
|
1587
|
+
*/
|
|
1588
|
+
valueFromOption(value, option) {
|
|
1589
|
+
const optionKey = option.attributeName();
|
|
1590
|
+
if (!this.dualOptions.has(optionKey)) return true;
|
|
1591
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
1592
|
+
const negativeValue = preset !== void 0 ? preset : false;
|
|
1593
|
+
return option.negate === (negativeValue === value);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
function camelcase(str3) {
|
|
1597
|
+
return str3.split("-").reduce((str4, word) => {
|
|
1598
|
+
return str4 + word[0].toUpperCase() + word.slice(1);
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
function splitOptionFlags(flags) {
|
|
1602
|
+
let shortFlag;
|
|
1603
|
+
let longFlag;
|
|
1604
|
+
const shortFlagExp = /^-[^-]$/;
|
|
1605
|
+
const longFlagExp = /^--[^-]/;
|
|
1606
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
1607
|
+
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
1608
|
+
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
1609
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
1610
|
+
shortFlag = flagParts.shift();
|
|
1611
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
1612
|
+
shortFlag = longFlag;
|
|
1613
|
+
longFlag = flagParts.shift();
|
|
1614
|
+
}
|
|
1615
|
+
if (flagParts[0].startsWith("-")) {
|
|
1616
|
+
const unsupportedFlag = flagParts[0];
|
|
1617
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
1618
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
1619
|
+
throw new Error(
|
|
1620
|
+
`${baseError}
|
|
1621
|
+
- a short flag is a single dash and a single character
|
|
1622
|
+
- either use a single dash and a single character (for a short flag)
|
|
1623
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`
|
|
1624
|
+
);
|
|
1625
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
1626
|
+
throw new Error(`${baseError}
|
|
1627
|
+
- too many short flags`);
|
|
1628
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
1629
|
+
throw new Error(`${baseError}
|
|
1630
|
+
- too many long flags`);
|
|
1631
|
+
throw new Error(`${baseError}
|
|
1632
|
+
- unrecognised flag format`);
|
|
1633
|
+
}
|
|
1634
|
+
if (shortFlag === void 0 && longFlag === void 0)
|
|
1635
|
+
throw new Error(
|
|
1636
|
+
`option creation failed due to no flags found in '${flags}'.`
|
|
1637
|
+
);
|
|
1638
|
+
return { shortFlag, longFlag };
|
|
1639
|
+
}
|
|
1640
|
+
exports2.Option = Option2;
|
|
1641
|
+
exports2.DualOptions = DualOptions;
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
|
|
1645
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js
|
|
1646
|
+
var require_suggestSimilar = __commonJS({
|
|
1647
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js"(exports2) {
|
|
1648
|
+
"use strict";
|
|
1649
|
+
var maxDistance = 3;
|
|
1650
|
+
function editDistance(a, b) {
|
|
1651
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
1652
|
+
return Math.max(a.length, b.length);
|
|
1653
|
+
const d = [];
|
|
1654
|
+
for (let i = 0; i <= a.length; i++) {
|
|
1655
|
+
d[i] = [i];
|
|
1656
|
+
}
|
|
1657
|
+
for (let j = 0; j <= b.length; j++) {
|
|
1658
|
+
d[0][j] = j;
|
|
1659
|
+
}
|
|
1660
|
+
for (let j = 1; j <= b.length; j++) {
|
|
1661
|
+
for (let i = 1; i <= a.length; i++) {
|
|
1662
|
+
let cost = 1;
|
|
1663
|
+
if (a[i - 1] === b[j - 1]) {
|
|
1664
|
+
cost = 0;
|
|
1665
|
+
} else {
|
|
1666
|
+
cost = 1;
|
|
1667
|
+
}
|
|
1668
|
+
d[i][j] = Math.min(
|
|
1669
|
+
d[i - 1][j] + 1,
|
|
1670
|
+
// deletion
|
|
1671
|
+
d[i][j - 1] + 1,
|
|
1672
|
+
// insertion
|
|
1673
|
+
d[i - 1][j - 1] + cost
|
|
1674
|
+
// substitution
|
|
1675
|
+
);
|
|
1676
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
1677
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
return d[a.length][b.length];
|
|
1682
|
+
}
|
|
1683
|
+
function suggestSimilar(word, candidates) {
|
|
1684
|
+
if (!candidates || candidates.length === 0) return "";
|
|
1685
|
+
candidates = Array.from(new Set(candidates));
|
|
1686
|
+
const searchingOptions = word.startsWith("--");
|
|
1687
|
+
if (searchingOptions) {
|
|
1688
|
+
word = word.slice(2);
|
|
1689
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
1690
|
+
}
|
|
1691
|
+
let similar = [];
|
|
1692
|
+
let bestDistance = maxDistance;
|
|
1693
|
+
const minSimilarity = 0.4;
|
|
1694
|
+
candidates.forEach((candidate) => {
|
|
1695
|
+
if (candidate.length <= 1) return;
|
|
1696
|
+
const distance = editDistance(word, candidate);
|
|
1697
|
+
const length = Math.max(word.length, candidate.length);
|
|
1698
|
+
const similarity = (length - distance) / length;
|
|
1699
|
+
if (similarity > minSimilarity) {
|
|
1700
|
+
if (distance < bestDistance) {
|
|
1701
|
+
bestDistance = distance;
|
|
1702
|
+
similar = [candidate];
|
|
1703
|
+
} else if (distance === bestDistance) {
|
|
1704
|
+
similar.push(candidate);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
1709
|
+
if (searchingOptions) {
|
|
1710
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
1711
|
+
}
|
|
1712
|
+
if (similar.length > 1) {
|
|
1713
|
+
return `
|
|
1714
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
1715
|
+
}
|
|
1716
|
+
if (similar.length === 1) {
|
|
1717
|
+
return `
|
|
1718
|
+
(Did you mean ${similar[0]}?)`;
|
|
1719
|
+
}
|
|
1720
|
+
return "";
|
|
1721
|
+
}
|
|
1722
|
+
exports2.suggestSimilar = suggestSimilar;
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/command.js
|
|
1727
|
+
var require_command = __commonJS({
|
|
1728
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/command.js"(exports2) {
|
|
1729
|
+
"use strict";
|
|
1730
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
1731
|
+
var childProcess = __require("child_process");
|
|
1732
|
+
var path18 = __require("path");
|
|
1733
|
+
var fs15 = __require("fs");
|
|
1734
|
+
var process4 = __require("process");
|
|
1735
|
+
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1736
|
+
var { CommanderError: CommanderError2 } = require_error();
|
|
1737
|
+
var { Help: Help2, stripColor } = require_help();
|
|
1738
|
+
var { Option: Option2, DualOptions } = require_option();
|
|
1739
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
1740
|
+
var Command2 = class _Command extends EventEmitter {
|
|
1741
|
+
/**
|
|
1742
|
+
* Initialize a new `Command`.
|
|
1743
|
+
*
|
|
1744
|
+
* @param {string} [name]
|
|
1745
|
+
*/
|
|
1746
|
+
constructor(name) {
|
|
1747
|
+
super();
|
|
1748
|
+
this.commands = [];
|
|
1749
|
+
this.options = [];
|
|
1750
|
+
this.parent = null;
|
|
1751
|
+
this._allowUnknownOption = false;
|
|
1752
|
+
this._allowExcessArguments = false;
|
|
1753
|
+
this.registeredArguments = [];
|
|
1754
|
+
this._args = this.registeredArguments;
|
|
1755
|
+
this.args = [];
|
|
1756
|
+
this.rawArgs = [];
|
|
1757
|
+
this.processedArgs = [];
|
|
1758
|
+
this._scriptPath = null;
|
|
1759
|
+
this._name = name || "";
|
|
1760
|
+
this._optionValues = {};
|
|
1761
|
+
this._optionValueSources = {};
|
|
1762
|
+
this._storeOptionsAsProperties = false;
|
|
1763
|
+
this._actionHandler = null;
|
|
1764
|
+
this._executableHandler = false;
|
|
1765
|
+
this._executableFile = null;
|
|
1766
|
+
this._executableDir = null;
|
|
1767
|
+
this._defaultCommandName = null;
|
|
1768
|
+
this._exitCallback = null;
|
|
1769
|
+
this._aliases = [];
|
|
1770
|
+
this._combineFlagAndOptionalValue = true;
|
|
1771
|
+
this._description = "";
|
|
1772
|
+
this._summary = "";
|
|
1773
|
+
this._argsDescription = void 0;
|
|
1774
|
+
this._enablePositionalOptions = false;
|
|
1775
|
+
this._passThroughOptions = false;
|
|
1776
|
+
this._lifeCycleHooks = {};
|
|
1777
|
+
this._showHelpAfterError = false;
|
|
1778
|
+
this._showSuggestionAfterError = true;
|
|
1779
|
+
this._savedState = null;
|
|
1780
|
+
this._outputConfiguration = {
|
|
1781
|
+
writeOut: (str3) => process4.stdout.write(str3),
|
|
1782
|
+
writeErr: (str3) => process4.stderr.write(str3),
|
|
1783
|
+
outputError: (str3, write) => write(str3),
|
|
1784
|
+
getOutHelpWidth: () => process4.stdout.isTTY ? process4.stdout.columns : void 0,
|
|
1785
|
+
getErrHelpWidth: () => process4.stderr.isTTY ? process4.stderr.columns : void 0,
|
|
1786
|
+
getOutHasColors: () => useColor() ?? (process4.stdout.isTTY && process4.stdout.hasColors?.()),
|
|
1787
|
+
getErrHasColors: () => useColor() ?? (process4.stderr.isTTY && process4.stderr.hasColors?.()),
|
|
1788
|
+
stripColor: (str3) => stripColor(str3)
|
|
1789
|
+
};
|
|
1790
|
+
this._hidden = false;
|
|
1791
|
+
this._helpOption = void 0;
|
|
1792
|
+
this._addImplicitHelpCommand = void 0;
|
|
1793
|
+
this._helpCommand = void 0;
|
|
1794
|
+
this._helpConfiguration = {};
|
|
1795
|
+
this._helpGroupHeading = void 0;
|
|
1796
|
+
this._defaultCommandGroup = void 0;
|
|
1797
|
+
this._defaultOptionGroup = void 0;
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
1801
|
+
*
|
|
1802
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
1803
|
+
*
|
|
1804
|
+
* @param {Command} sourceCommand
|
|
1805
|
+
* @return {Command} `this` command for chaining
|
|
1806
|
+
*/
|
|
1807
|
+
copyInheritedSettings(sourceCommand) {
|
|
1808
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1809
|
+
this._helpOption = sourceCommand._helpOption;
|
|
1810
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
1811
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1812
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
1813
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1814
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1815
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1816
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1817
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1818
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1819
|
+
return this;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* @returns {Command[]}
|
|
1823
|
+
* @private
|
|
1824
|
+
*/
|
|
1825
|
+
_getCommandAndAncestors() {
|
|
1826
|
+
const result = [];
|
|
1827
|
+
for (let command = this; command; command = command.parent) {
|
|
1828
|
+
result.push(command);
|
|
1829
|
+
}
|
|
1830
|
+
return result;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Define a command.
|
|
1834
|
+
*
|
|
1835
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
1836
|
+
*
|
|
1837
|
+
* @example
|
|
1838
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
1839
|
+
* program
|
|
1840
|
+
* .command('clone <source> [destination]')
|
|
1841
|
+
* .description('clone a repository into a newly created directory')
|
|
1842
|
+
* .action((source, destination) => {
|
|
1843
|
+
* console.log('clone command called');
|
|
1844
|
+
* });
|
|
1845
|
+
*
|
|
1846
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
1847
|
+
* program
|
|
1848
|
+
* .command('start <service>', 'start named service')
|
|
1849
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
1850
|
+
*
|
|
1851
|
+
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
1852
|
+
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
1853
|
+
* @param {object} [execOpts] - configuration options (for executable)
|
|
1854
|
+
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
1855
|
+
*/
|
|
1856
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1857
|
+
let desc = actionOptsOrExecDesc;
|
|
1858
|
+
let opts = execOpts;
|
|
1859
|
+
if (typeof desc === "object" && desc !== null) {
|
|
1860
|
+
opts = desc;
|
|
1861
|
+
desc = null;
|
|
1862
|
+
}
|
|
1863
|
+
opts = opts || {};
|
|
1864
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1865
|
+
const cmd = this.createCommand(name);
|
|
1866
|
+
if (desc) {
|
|
1867
|
+
cmd.description(desc);
|
|
1868
|
+
cmd._executableHandler = true;
|
|
1869
|
+
}
|
|
1870
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1871
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1872
|
+
cmd._executableFile = opts.executableFile || null;
|
|
1873
|
+
if (args) cmd.arguments(args);
|
|
1874
|
+
this._registerCommand(cmd);
|
|
1875
|
+
cmd.parent = this;
|
|
1876
|
+
cmd.copyInheritedSettings(this);
|
|
1877
|
+
if (desc) return this;
|
|
1878
|
+
return cmd;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Factory routine to create a new unattached command.
|
|
1882
|
+
*
|
|
1883
|
+
* See .command() for creating an attached subcommand, which uses this routine to
|
|
1884
|
+
* create the command. You can override createCommand to customise subcommands.
|
|
1885
|
+
*
|
|
1886
|
+
* @param {string} [name]
|
|
1887
|
+
* @return {Command} new command
|
|
1888
|
+
*/
|
|
1889
|
+
createCommand(name) {
|
|
1890
|
+
return new _Command(name);
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
1894
|
+
* or by overriding Help properties using configureHelp().
|
|
1895
|
+
*
|
|
1896
|
+
* @return {Help}
|
|
1897
|
+
*/
|
|
1898
|
+
createHelp() {
|
|
1899
|
+
return Object.assign(new Help2(), this.configureHelp());
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
1903
|
+
* or with a subclass of Help by overriding createHelp().
|
|
1904
|
+
*
|
|
1905
|
+
* @param {object} [configuration] - configuration options
|
|
1906
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1907
|
+
*/
|
|
1908
|
+
configureHelp(configuration) {
|
|
1909
|
+
if (configuration === void 0) return this._helpConfiguration;
|
|
1910
|
+
this._helpConfiguration = configuration;
|
|
1911
|
+
return this;
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* The default output goes to stdout and stderr. You can customise this for special
|
|
1915
|
+
* applications. You can also customise the display of errors by overriding outputError.
|
|
1916
|
+
*
|
|
1917
|
+
* The configuration properties are all functions:
|
|
1918
|
+
*
|
|
1919
|
+
* // change how output being written, defaults to stdout and stderr
|
|
1920
|
+
* writeOut(str)
|
|
1921
|
+
* writeErr(str)
|
|
1922
|
+
* // change how output being written for errors, defaults to writeErr
|
|
1923
|
+
* outputError(str, write) // used for displaying errors and not used for displaying help
|
|
1924
|
+
* // specify width for wrapping help
|
|
1925
|
+
* getOutHelpWidth()
|
|
1926
|
+
* getErrHelpWidth()
|
|
1927
|
+
* // color support, currently only used with Help
|
|
1928
|
+
* getOutHasColors()
|
|
1929
|
+
* getErrHasColors()
|
|
1930
|
+
* stripColor() // used to remove ANSI escape codes if output does not have colors
|
|
1931
|
+
*
|
|
1932
|
+
* @param {object} [configuration] - configuration options
|
|
1933
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1934
|
+
*/
|
|
1935
|
+
configureOutput(configuration) {
|
|
1936
|
+
if (configuration === void 0) return this._outputConfiguration;
|
|
1937
|
+
this._outputConfiguration = {
|
|
1938
|
+
...this._outputConfiguration,
|
|
1939
|
+
...configuration
|
|
1940
|
+
};
|
|
1941
|
+
return this;
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Display the help or a custom message after an error occurs.
|
|
1945
|
+
*
|
|
1946
|
+
* @param {(boolean|string)} [displayHelp]
|
|
1947
|
+
* @return {Command} `this` command for chaining
|
|
1948
|
+
*/
|
|
1949
|
+
showHelpAfterError(displayHelp = true) {
|
|
1950
|
+
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
1951
|
+
this._showHelpAfterError = displayHelp;
|
|
1952
|
+
return this;
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
1956
|
+
*
|
|
1957
|
+
* @param {boolean} [displaySuggestion]
|
|
1958
|
+
* @return {Command} `this` command for chaining
|
|
1959
|
+
*/
|
|
1960
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1961
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1962
|
+
return this;
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* Add a prepared subcommand.
|
|
1966
|
+
*
|
|
1967
|
+
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
1968
|
+
*
|
|
1969
|
+
* @param {Command} cmd - new subcommand
|
|
1970
|
+
* @param {object} [opts] - configuration options
|
|
1971
|
+
* @return {Command} `this` command for chaining
|
|
1972
|
+
*/
|
|
1973
|
+
addCommand(cmd, opts) {
|
|
1974
|
+
if (!cmd._name) {
|
|
1975
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
1976
|
+
- specify the name in Command constructor or using .name()`);
|
|
1977
|
+
}
|
|
1978
|
+
opts = opts || {};
|
|
1979
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1980
|
+
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
1981
|
+
this._registerCommand(cmd);
|
|
1982
|
+
cmd.parent = this;
|
|
1983
|
+
cmd._checkForBrokenPassThrough();
|
|
1984
|
+
return this;
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Factory routine to create a new unattached argument.
|
|
1988
|
+
*
|
|
1989
|
+
* See .argument() for creating an attached argument, which uses this routine to
|
|
1990
|
+
* create the argument. You can override createArgument to return a custom argument.
|
|
1991
|
+
*
|
|
1992
|
+
* @param {string} name
|
|
1993
|
+
* @param {string} [description]
|
|
1994
|
+
* @return {Argument} new argument
|
|
1995
|
+
*/
|
|
1996
|
+
createArgument(name, description) {
|
|
1997
|
+
return new Argument2(name, description);
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Define argument syntax for command.
|
|
2001
|
+
*
|
|
2002
|
+
* The default is that the argument is required, and you can explicitly
|
|
2003
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* program.argument('<input-file>');
|
|
2007
|
+
* program.argument('[output-file]');
|
|
2008
|
+
*
|
|
2009
|
+
* @param {string} name
|
|
2010
|
+
* @param {string} [description]
|
|
2011
|
+
* @param {(Function|*)} [parseArg] - custom argument processing function or default value
|
|
2012
|
+
* @param {*} [defaultValue]
|
|
2013
|
+
* @return {Command} `this` command for chaining
|
|
2014
|
+
*/
|
|
2015
|
+
argument(name, description, parseArg, defaultValue) {
|
|
2016
|
+
const argument = this.createArgument(name, description);
|
|
2017
|
+
if (typeof parseArg === "function") {
|
|
2018
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
2019
|
+
} else {
|
|
2020
|
+
argument.default(parseArg);
|
|
2021
|
+
}
|
|
2022
|
+
this.addArgument(argument);
|
|
2023
|
+
return this;
|
|
2024
|
+
}
|
|
2025
|
+
/**
|
|
2026
|
+
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
2027
|
+
*
|
|
2028
|
+
* See also .argument().
|
|
2029
|
+
*
|
|
2030
|
+
* @example
|
|
2031
|
+
* program.arguments('<cmd> [env]');
|
|
2032
|
+
*
|
|
2033
|
+
* @param {string} names
|
|
2034
|
+
* @return {Command} `this` command for chaining
|
|
2035
|
+
*/
|
|
2036
|
+
arguments(names) {
|
|
2037
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
2038
|
+
this.argument(detail);
|
|
2039
|
+
});
|
|
2040
|
+
return this;
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* Define argument syntax for command, adding a prepared argument.
|
|
2044
|
+
*
|
|
2045
|
+
* @param {Argument} argument
|
|
2046
|
+
* @return {Command} `this` command for chaining
|
|
2047
|
+
*/
|
|
2048
|
+
addArgument(argument) {
|
|
2049
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
2050
|
+
if (previousArgument?.variadic) {
|
|
2051
|
+
throw new Error(
|
|
2052
|
+
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
2053
|
+
);
|
|
2054
|
+
}
|
|
2055
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
2056
|
+
throw new Error(
|
|
2057
|
+
`a default value for a required argument is never used: '${argument.name()}'`
|
|
2058
|
+
);
|
|
2059
|
+
}
|
|
2060
|
+
this.registeredArguments.push(argument);
|
|
2061
|
+
return this;
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
2065
|
+
*
|
|
2066
|
+
* @example
|
|
2067
|
+
* program.helpCommand('help [cmd]');
|
|
2068
|
+
* program.helpCommand('help [cmd]', 'show help');
|
|
2069
|
+
* program.helpCommand(false); // suppress default help command
|
|
2070
|
+
* program.helpCommand(true); // add help command even if no subcommands
|
|
2071
|
+
*
|
|
2072
|
+
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
2073
|
+
* @param {string} [description] - custom description
|
|
2074
|
+
* @return {Command} `this` command for chaining
|
|
2075
|
+
*/
|
|
2076
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
2077
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
2078
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
2079
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
2080
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
2081
|
+
}
|
|
2082
|
+
return this;
|
|
2083
|
+
}
|
|
2084
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
2085
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
2086
|
+
const helpDescription = description ?? "display help for command";
|
|
2087
|
+
const helpCommand = this.createCommand(helpName);
|
|
2088
|
+
helpCommand.helpOption(false);
|
|
2089
|
+
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
2090
|
+
if (helpDescription) helpCommand.description(helpDescription);
|
|
2091
|
+
this._addImplicitHelpCommand = true;
|
|
2092
|
+
this._helpCommand = helpCommand;
|
|
2093
|
+
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
2094
|
+
return this;
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Add prepared custom help command.
|
|
2098
|
+
*
|
|
2099
|
+
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
2100
|
+
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
2101
|
+
* @return {Command} `this` command for chaining
|
|
2102
|
+
*/
|
|
2103
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
2104
|
+
if (typeof helpCommand !== "object") {
|
|
2105
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
2106
|
+
return this;
|
|
2107
|
+
}
|
|
2108
|
+
this._addImplicitHelpCommand = true;
|
|
2109
|
+
this._helpCommand = helpCommand;
|
|
2110
|
+
this._initCommandGroup(helpCommand);
|
|
2111
|
+
return this;
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Lazy create help command.
|
|
2115
|
+
*
|
|
2116
|
+
* @return {(Command|null)}
|
|
2117
|
+
* @package
|
|
2118
|
+
*/
|
|
2119
|
+
_getHelpCommand() {
|
|
2120
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
2121
|
+
if (hasImplicitHelpCommand) {
|
|
2122
|
+
if (this._helpCommand === void 0) {
|
|
2123
|
+
this.helpCommand(void 0, void 0);
|
|
2124
|
+
}
|
|
2125
|
+
return this._helpCommand;
|
|
2126
|
+
}
|
|
2127
|
+
return null;
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Add hook for life cycle event.
|
|
2131
|
+
*
|
|
2132
|
+
* @param {string} event
|
|
2133
|
+
* @param {Function} listener
|
|
2134
|
+
* @return {Command} `this` command for chaining
|
|
2135
|
+
*/
|
|
2136
|
+
hook(event, listener) {
|
|
2137
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
2138
|
+
if (!allowedValues.includes(event)) {
|
|
2139
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
2140
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2141
|
+
}
|
|
2142
|
+
if (this._lifeCycleHooks[event]) {
|
|
2143
|
+
this._lifeCycleHooks[event].push(listener);
|
|
2144
|
+
} else {
|
|
2145
|
+
this._lifeCycleHooks[event] = [listener];
|
|
2146
|
+
}
|
|
2147
|
+
return this;
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Register callback to use as replacement for calling process.exit.
|
|
2151
|
+
*
|
|
2152
|
+
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
2153
|
+
* @return {Command} `this` command for chaining
|
|
2154
|
+
*/
|
|
2155
|
+
exitOverride(fn) {
|
|
2156
|
+
if (fn) {
|
|
2157
|
+
this._exitCallback = fn;
|
|
2158
|
+
} else {
|
|
2159
|
+
this._exitCallback = (err) => {
|
|
2160
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
2161
|
+
throw err;
|
|
2162
|
+
} else {
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
return this;
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Call process.exit, and _exitCallback if defined.
|
|
2170
|
+
*
|
|
2171
|
+
* @param {number} exitCode exit code for using with process.exit
|
|
2172
|
+
* @param {string} code an id string representing the error
|
|
2173
|
+
* @param {string} message human-readable description of the error
|
|
2174
|
+
* @return never
|
|
2175
|
+
* @private
|
|
2176
|
+
*/
|
|
2177
|
+
_exit(exitCode3, code, message) {
|
|
2178
|
+
if (this._exitCallback) {
|
|
2179
|
+
this._exitCallback(new CommanderError2(exitCode3, code, message));
|
|
2180
|
+
}
|
|
2181
|
+
process4.exit(exitCode3);
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Register callback `fn` for the command.
|
|
2185
|
+
*
|
|
2186
|
+
* @example
|
|
2187
|
+
* program
|
|
2188
|
+
* .command('serve')
|
|
2189
|
+
* .description('start service')
|
|
2190
|
+
* .action(function() {
|
|
2191
|
+
* // do work here
|
|
2192
|
+
* });
|
|
2193
|
+
*
|
|
2194
|
+
* @param {Function} fn
|
|
2195
|
+
* @return {Command} `this` command for chaining
|
|
2196
|
+
*/
|
|
2197
|
+
action(fn) {
|
|
2198
|
+
const listener = (args) => {
|
|
2199
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
2200
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
2201
|
+
if (this._storeOptionsAsProperties) {
|
|
2202
|
+
actionArgs[expectedArgsCount] = this;
|
|
2203
|
+
} else {
|
|
2204
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
2205
|
+
}
|
|
2206
|
+
actionArgs.push(this);
|
|
2207
|
+
return fn.apply(this, actionArgs);
|
|
2208
|
+
};
|
|
2209
|
+
this._actionHandler = listener;
|
|
2210
|
+
return this;
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Factory routine to create a new unattached option.
|
|
2214
|
+
*
|
|
2215
|
+
* See .option() for creating an attached option, which uses this routine to
|
|
2216
|
+
* create the option. You can override createOption to return a custom option.
|
|
2217
|
+
*
|
|
2218
|
+
* @param {string} flags
|
|
2219
|
+
* @param {string} [description]
|
|
2220
|
+
* @return {Option} new option
|
|
2221
|
+
*/
|
|
2222
|
+
createOption(flags, description) {
|
|
2223
|
+
return new Option2(flags, description);
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
2227
|
+
*
|
|
2228
|
+
* @param {(Option | Argument)} target
|
|
2229
|
+
* @param {string} value
|
|
2230
|
+
* @param {*} previous
|
|
2231
|
+
* @param {string} invalidArgumentMessage
|
|
2232
|
+
* @private
|
|
2233
|
+
*/
|
|
2234
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
2235
|
+
try {
|
|
2236
|
+
return target.parseArg(value, previous);
|
|
2237
|
+
} catch (err) {
|
|
2238
|
+
if (err.code === "commander.invalidArgument") {
|
|
2239
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
2240
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
2241
|
+
}
|
|
2242
|
+
throw err;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Check for option flag conflicts.
|
|
2247
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
2248
|
+
*
|
|
2249
|
+
* @param {Option} option
|
|
2250
|
+
* @private
|
|
2251
|
+
*/
|
|
2252
|
+
_registerOption(option) {
|
|
2253
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
2254
|
+
if (matchingOption) {
|
|
2255
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
2256
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
2257
|
+
- already used by option '${matchingOption.flags}'`);
|
|
2258
|
+
}
|
|
2259
|
+
this._initOptionGroup(option);
|
|
2260
|
+
this.options.push(option);
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Check for command name and alias conflicts with existing commands.
|
|
2264
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
2265
|
+
*
|
|
2266
|
+
* @param {Command} command
|
|
2267
|
+
* @private
|
|
2268
|
+
*/
|
|
2269
|
+
_registerCommand(command) {
|
|
2270
|
+
const knownBy = (cmd) => {
|
|
2271
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
2272
|
+
};
|
|
2273
|
+
const alreadyUsed = knownBy(command).find(
|
|
2274
|
+
(name) => this._findCommand(name)
|
|
2275
|
+
);
|
|
2276
|
+
if (alreadyUsed) {
|
|
2277
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
2278
|
+
const newCmd = knownBy(command).join("|");
|
|
2279
|
+
throw new Error(
|
|
2280
|
+
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
2281
|
+
);
|
|
2282
|
+
}
|
|
2283
|
+
this._initCommandGroup(command);
|
|
2284
|
+
this.commands.push(command);
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Add an option.
|
|
2288
|
+
*
|
|
2289
|
+
* @param {Option} option
|
|
2290
|
+
* @return {Command} `this` command for chaining
|
|
2291
|
+
*/
|
|
2292
|
+
addOption(option) {
|
|
2293
|
+
this._registerOption(option);
|
|
2294
|
+
const oname = option.name();
|
|
2295
|
+
const name = option.attributeName();
|
|
2296
|
+
if (option.negate) {
|
|
2297
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
2298
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
2299
|
+
this.setOptionValueWithSource(
|
|
2300
|
+
name,
|
|
2301
|
+
option.defaultValue === void 0 ? true : option.defaultValue,
|
|
2302
|
+
"default"
|
|
2303
|
+
);
|
|
2304
|
+
}
|
|
2305
|
+
} else if (option.defaultValue !== void 0) {
|
|
2306
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
2307
|
+
}
|
|
2308
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
2309
|
+
if (val == null && option.presetArg !== void 0) {
|
|
2310
|
+
val = option.presetArg;
|
|
2311
|
+
}
|
|
2312
|
+
const oldValue = this.getOptionValue(name);
|
|
2313
|
+
if (val !== null && option.parseArg) {
|
|
2314
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
2315
|
+
} else if (val !== null && option.variadic) {
|
|
2316
|
+
val = option._collectValue(val, oldValue);
|
|
2317
|
+
}
|
|
2318
|
+
if (val == null) {
|
|
2319
|
+
if (option.negate) {
|
|
2320
|
+
val = false;
|
|
2321
|
+
} else if (option.isBoolean() || option.optional) {
|
|
2322
|
+
val = true;
|
|
2323
|
+
} else {
|
|
2324
|
+
val = "";
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
2328
|
+
};
|
|
2329
|
+
this.on("option:" + oname, (val) => {
|
|
2330
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
2331
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
2332
|
+
});
|
|
2333
|
+
if (option.envVar) {
|
|
2334
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
2335
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
2336
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
return this;
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* Internal implementation shared by .option() and .requiredOption()
|
|
2343
|
+
*
|
|
2344
|
+
* @return {Command} `this` command for chaining
|
|
2345
|
+
* @private
|
|
2346
|
+
*/
|
|
2347
|
+
_optionEx(config2, flags, description, fn, defaultValue) {
|
|
2348
|
+
if (typeof flags === "object" && flags instanceof Option2) {
|
|
2349
|
+
throw new Error(
|
|
2350
|
+
"To add an Option object use addOption() instead of option() or requiredOption()"
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
const option = this.createOption(flags, description);
|
|
2354
|
+
option.makeOptionMandatory(!!config2.mandatory);
|
|
2355
|
+
if (typeof fn === "function") {
|
|
2356
|
+
option.default(defaultValue).argParser(fn);
|
|
2357
|
+
} else if (fn instanceof RegExp) {
|
|
2358
|
+
const regex = fn;
|
|
2359
|
+
fn = (val, def) => {
|
|
2360
|
+
const m = regex.exec(val);
|
|
2361
|
+
return m ? m[0] : def;
|
|
2362
|
+
};
|
|
2363
|
+
option.default(defaultValue).argParser(fn);
|
|
2364
|
+
} else {
|
|
2365
|
+
option.default(fn);
|
|
2366
|
+
}
|
|
2367
|
+
return this.addOption(option);
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
2371
|
+
*
|
|
2372
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
2373
|
+
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
2374
|
+
*
|
|
2375
|
+
* See the README for more details, and see also addOption() and requiredOption().
|
|
2376
|
+
*
|
|
2377
|
+
* @example
|
|
2378
|
+
* program
|
|
2379
|
+
* .option('-p, --pepper', 'add pepper')
|
|
2380
|
+
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
2381
|
+
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
2382
|
+
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
2383
|
+
*
|
|
2384
|
+
* @param {string} flags
|
|
2385
|
+
* @param {string} [description]
|
|
2386
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
2387
|
+
* @param {*} [defaultValue]
|
|
2388
|
+
* @return {Command} `this` command for chaining
|
|
2389
|
+
*/
|
|
2390
|
+
option(flags, description, parseArg, defaultValue) {
|
|
2391
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Add a required option which must have a value after parsing. This usually means
|
|
2395
|
+
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
2396
|
+
*
|
|
2397
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
2398
|
+
*
|
|
2399
|
+
* @param {string} flags
|
|
2400
|
+
* @param {string} [description]
|
|
2401
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
2402
|
+
* @param {*} [defaultValue]
|
|
2403
|
+
* @return {Command} `this` command for chaining
|
|
2404
|
+
*/
|
|
2405
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
2406
|
+
return this._optionEx(
|
|
2407
|
+
{ mandatory: true },
|
|
2408
|
+
flags,
|
|
2409
|
+
description,
|
|
2410
|
+
parseArg,
|
|
2411
|
+
defaultValue
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Alter parsing of short flags with optional values.
|
|
2416
|
+
*
|
|
2417
|
+
* @example
|
|
2418
|
+
* // for `.option('-f,--flag [value]'):
|
|
2419
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
2420
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
2421
|
+
*
|
|
2422
|
+
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
2423
|
+
* @return {Command} `this` command for chaining
|
|
2424
|
+
*/
|
|
2425
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
2426
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
2427
|
+
return this;
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Allow unknown options on the command line.
|
|
2431
|
+
*
|
|
2432
|
+
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
2433
|
+
* @return {Command} `this` command for chaining
|
|
2434
|
+
*/
|
|
2435
|
+
allowUnknownOption(allowUnknown = true) {
|
|
2436
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
2437
|
+
return this;
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
2441
|
+
*
|
|
2442
|
+
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
2443
|
+
* @return {Command} `this` command for chaining
|
|
2444
|
+
*/
|
|
2445
|
+
allowExcessArguments(allowExcess = true) {
|
|
2446
|
+
this._allowExcessArguments = !!allowExcess;
|
|
2447
|
+
return this;
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
2451
|
+
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
2452
|
+
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
2453
|
+
*
|
|
2454
|
+
* @param {boolean} [positional]
|
|
2455
|
+
* @return {Command} `this` command for chaining
|
|
2456
|
+
*/
|
|
2457
|
+
enablePositionalOptions(positional = true) {
|
|
2458
|
+
this._enablePositionalOptions = !!positional;
|
|
2459
|
+
return this;
|
|
2460
|
+
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
2463
|
+
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
2464
|
+
* positional options to have been enabled on the program (parent commands).
|
|
2465
|
+
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
2466
|
+
*
|
|
2467
|
+
* @param {boolean} [passThrough] for unknown options.
|
|
2468
|
+
* @return {Command} `this` command for chaining
|
|
2469
|
+
*/
|
|
2470
|
+
passThroughOptions(passThrough = true) {
|
|
2471
|
+
this._passThroughOptions = !!passThrough;
|
|
2472
|
+
this._checkForBrokenPassThrough();
|
|
2473
|
+
return this;
|
|
2474
|
+
}
|
|
2475
|
+
/**
|
|
2476
|
+
* @private
|
|
2477
|
+
*/
|
|
2478
|
+
_checkForBrokenPassThrough() {
|
|
2479
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
2480
|
+
throw new Error(
|
|
2481
|
+
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* Whether to store option values as properties on command object,
|
|
2487
|
+
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
2488
|
+
*
|
|
2489
|
+
* @param {boolean} [storeAsProperties=true]
|
|
2490
|
+
* @return {Command} `this` command for chaining
|
|
2491
|
+
*/
|
|
2492
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
2493
|
+
if (this.options.length) {
|
|
2494
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
2495
|
+
}
|
|
2496
|
+
if (Object.keys(this._optionValues).length) {
|
|
2497
|
+
throw new Error(
|
|
2498
|
+
"call .storeOptionsAsProperties() before setting option values"
|
|
2499
|
+
);
|
|
2500
|
+
}
|
|
2501
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
2502
|
+
return this;
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Retrieve option value.
|
|
2506
|
+
*
|
|
2507
|
+
* @param {string} key
|
|
2508
|
+
* @return {object} value
|
|
2509
|
+
*/
|
|
2510
|
+
getOptionValue(key) {
|
|
2511
|
+
if (this._storeOptionsAsProperties) {
|
|
2512
|
+
return this[key];
|
|
2513
|
+
}
|
|
2514
|
+
return this._optionValues[key];
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* Store option value.
|
|
2518
|
+
*
|
|
2519
|
+
* @param {string} key
|
|
2520
|
+
* @param {object} value
|
|
2521
|
+
* @return {Command} `this` command for chaining
|
|
2522
|
+
*/
|
|
2523
|
+
setOptionValue(key, value) {
|
|
2524
|
+
return this.setOptionValueWithSource(key, value, void 0);
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* Store option value and where the value came from.
|
|
2528
|
+
*
|
|
2529
|
+
* @param {string} key
|
|
2530
|
+
* @param {object} value
|
|
2531
|
+
* @param {string} source - expected values are default/config/env/cli/implied
|
|
2532
|
+
* @return {Command} `this` command for chaining
|
|
2533
|
+
*/
|
|
2534
|
+
setOptionValueWithSource(key, value, source) {
|
|
2535
|
+
if (this._storeOptionsAsProperties) {
|
|
2536
|
+
this[key] = value;
|
|
2537
|
+
} else {
|
|
2538
|
+
this._optionValues[key] = value;
|
|
2539
|
+
}
|
|
2540
|
+
this._optionValueSources[key] = source;
|
|
2541
|
+
return this;
|
|
2542
|
+
}
|
|
2543
|
+
/**
|
|
2544
|
+
* Get source of option value.
|
|
2545
|
+
* Expected values are default | config | env | cli | implied
|
|
2546
|
+
*
|
|
2547
|
+
* @param {string} key
|
|
2548
|
+
* @return {string}
|
|
2549
|
+
*/
|
|
2550
|
+
getOptionValueSource(key) {
|
|
2551
|
+
return this._optionValueSources[key];
|
|
2552
|
+
}
|
|
2553
|
+
/**
|
|
2554
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
2555
|
+
* Expected values are default | config | env | cli | implied
|
|
2556
|
+
*
|
|
2557
|
+
* @param {string} key
|
|
2558
|
+
* @return {string}
|
|
2559
|
+
*/
|
|
2560
|
+
getOptionValueSourceWithGlobals(key) {
|
|
2561
|
+
let source;
|
|
2562
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2563
|
+
if (cmd.getOptionValueSource(key) !== void 0) {
|
|
2564
|
+
source = cmd.getOptionValueSource(key);
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
return source;
|
|
2568
|
+
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Get user arguments from implied or explicit arguments.
|
|
2571
|
+
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
2572
|
+
*
|
|
2573
|
+
* @private
|
|
2574
|
+
*/
|
|
2575
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
2576
|
+
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
2577
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
2578
|
+
}
|
|
2579
|
+
parseOptions = parseOptions || {};
|
|
2580
|
+
if (argv === void 0 && parseOptions.from === void 0) {
|
|
2581
|
+
if (process4.versions?.electron) {
|
|
2582
|
+
parseOptions.from = "electron";
|
|
2583
|
+
}
|
|
2584
|
+
const execArgv = process4.execArgv ?? [];
|
|
2585
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
2586
|
+
parseOptions.from = "eval";
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
if (argv === void 0) {
|
|
2590
|
+
argv = process4.argv;
|
|
2591
|
+
}
|
|
2592
|
+
this.rawArgs = argv.slice();
|
|
2593
|
+
let userArgs;
|
|
2594
|
+
switch (parseOptions.from) {
|
|
2595
|
+
case void 0:
|
|
2596
|
+
case "node":
|
|
2597
|
+
this._scriptPath = argv[1];
|
|
2598
|
+
userArgs = argv.slice(2);
|
|
2599
|
+
break;
|
|
2600
|
+
case "electron":
|
|
2601
|
+
if (process4.defaultApp) {
|
|
2602
|
+
this._scriptPath = argv[1];
|
|
2603
|
+
userArgs = argv.slice(2);
|
|
2604
|
+
} else {
|
|
2605
|
+
userArgs = argv.slice(1);
|
|
2606
|
+
}
|
|
2607
|
+
break;
|
|
2608
|
+
case "user":
|
|
2609
|
+
userArgs = argv.slice(0);
|
|
2610
|
+
break;
|
|
2611
|
+
case "eval":
|
|
2612
|
+
userArgs = argv.slice(1);
|
|
2613
|
+
break;
|
|
2614
|
+
default:
|
|
2615
|
+
throw new Error(
|
|
2616
|
+
`unexpected parse option { from: '${parseOptions.from}' }`
|
|
2617
|
+
);
|
|
2618
|
+
}
|
|
2619
|
+
if (!this._name && this._scriptPath)
|
|
2620
|
+
this.nameFromFilename(this._scriptPath);
|
|
2621
|
+
this._name = this._name || "program";
|
|
2622
|
+
return userArgs;
|
|
2623
|
+
}
|
|
2624
|
+
/**
|
|
2625
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
2626
|
+
*
|
|
2627
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
2628
|
+
*
|
|
2629
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
2630
|
+
*
|
|
2631
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
2632
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
2633
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
2634
|
+
* - `'user'`: just user arguments
|
|
2635
|
+
*
|
|
2636
|
+
* @example
|
|
2637
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
2638
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
2639
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
2640
|
+
*
|
|
2641
|
+
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
2642
|
+
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
2643
|
+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
2644
|
+
* @return {Command} `this` command for chaining
|
|
2645
|
+
*/
|
|
2646
|
+
parse(argv, parseOptions) {
|
|
2647
|
+
this._prepareForParse();
|
|
2648
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
2649
|
+
this._parseCommand([], userArgs);
|
|
2650
|
+
return this;
|
|
2651
|
+
}
|
|
2652
|
+
/**
|
|
2653
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
2654
|
+
*
|
|
2655
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
2656
|
+
*
|
|
2657
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
2658
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
2659
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
2660
|
+
* - `'user'`: just user arguments
|
|
2661
|
+
*
|
|
2662
|
+
* @example
|
|
2663
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
2664
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
2665
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
2666
|
+
*
|
|
2667
|
+
* @param {string[]} [argv]
|
|
2668
|
+
* @param {object} [parseOptions]
|
|
2669
|
+
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
2670
|
+
* @return {Promise}
|
|
2671
|
+
*/
|
|
2672
|
+
async parseAsync(argv, parseOptions) {
|
|
2673
|
+
this._prepareForParse();
|
|
2674
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
2675
|
+
await this._parseCommand([], userArgs);
|
|
2676
|
+
return this;
|
|
2677
|
+
}
|
|
2678
|
+
_prepareForParse() {
|
|
2679
|
+
if (this._savedState === null) {
|
|
2680
|
+
this.saveStateBeforeParse();
|
|
2681
|
+
} else {
|
|
2682
|
+
this.restoreStateBeforeParse();
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
/**
|
|
2686
|
+
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
2687
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
2688
|
+
*
|
|
2689
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
2690
|
+
*/
|
|
2691
|
+
saveStateBeforeParse() {
|
|
2692
|
+
this._savedState = {
|
|
2693
|
+
// name is stable if supplied by author, but may be unspecified for root command and deduced during parsing
|
|
2694
|
+
_name: this._name,
|
|
2695
|
+
// option values before parse have default values (including false for negated options)
|
|
2696
|
+
// shallow clones
|
|
2697
|
+
_optionValues: { ...this._optionValues },
|
|
2698
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2701
|
+
/**
|
|
2702
|
+
* Restore state before parse for calls after the first.
|
|
2703
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
2704
|
+
*
|
|
2705
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
2706
|
+
*/
|
|
2707
|
+
restoreStateBeforeParse() {
|
|
2708
|
+
if (this._storeOptionsAsProperties)
|
|
2709
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
2710
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
2711
|
+
this._name = this._savedState._name;
|
|
2712
|
+
this._scriptPath = null;
|
|
2713
|
+
this.rawArgs = [];
|
|
2714
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
2715
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
2716
|
+
this.args = [];
|
|
2717
|
+
this.processedArgs = [];
|
|
2718
|
+
}
|
|
2719
|
+
/**
|
|
2720
|
+
* Throw if expected executable is missing. Add lots of help for author.
|
|
2721
|
+
*
|
|
2722
|
+
* @param {string} executableFile
|
|
2723
|
+
* @param {string} executableDir
|
|
2724
|
+
* @param {string} subcommandName
|
|
2725
|
+
*/
|
|
2726
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2727
|
+
if (fs15.existsSync(executableFile)) return;
|
|
2728
|
+
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";
|
|
2729
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
2730
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
2731
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
2732
|
+
- ${executableDirMessage}`;
|
|
2733
|
+
throw new Error(executableMissing);
|
|
2734
|
+
}
|
|
2735
|
+
/**
|
|
2736
|
+
* Execute a sub-command executable.
|
|
2737
|
+
*
|
|
2738
|
+
* @private
|
|
2739
|
+
*/
|
|
2740
|
+
_executeSubCommand(subcommand, args) {
|
|
2741
|
+
args = args.slice();
|
|
2742
|
+
let launchWithNode = false;
|
|
2743
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2744
|
+
function findFile(baseDir, baseName) {
|
|
2745
|
+
const localBin = path18.resolve(baseDir, baseName);
|
|
2746
|
+
if (fs15.existsSync(localBin)) return localBin;
|
|
2747
|
+
if (sourceExt.includes(path18.extname(baseName))) return void 0;
|
|
2748
|
+
const foundExt = sourceExt.find(
|
|
2749
|
+
(ext2) => fs15.existsSync(`${localBin}${ext2}`)
|
|
2750
|
+
);
|
|
2751
|
+
if (foundExt) return `${localBin}${foundExt}`;
|
|
2752
|
+
return void 0;
|
|
2753
|
+
}
|
|
2754
|
+
this._checkForMissingMandatoryOptions();
|
|
2755
|
+
this._checkForConflictingOptions();
|
|
2756
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
2757
|
+
let executableDir = this._executableDir || "";
|
|
2758
|
+
if (this._scriptPath) {
|
|
2759
|
+
let resolvedScriptPath;
|
|
2760
|
+
try {
|
|
2761
|
+
resolvedScriptPath = fs15.realpathSync(this._scriptPath);
|
|
2762
|
+
} catch {
|
|
2763
|
+
resolvedScriptPath = this._scriptPath;
|
|
2764
|
+
}
|
|
2765
|
+
executableDir = path18.resolve(
|
|
2766
|
+
path18.dirname(resolvedScriptPath),
|
|
2767
|
+
executableDir
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2770
|
+
if (executableDir) {
|
|
2771
|
+
let localFile = findFile(executableDir, executableFile);
|
|
2772
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2773
|
+
const legacyName = path18.basename(
|
|
2774
|
+
this._scriptPath,
|
|
2775
|
+
path18.extname(this._scriptPath)
|
|
2776
|
+
);
|
|
2777
|
+
if (legacyName !== this._name) {
|
|
2778
|
+
localFile = findFile(
|
|
2779
|
+
executableDir,
|
|
2780
|
+
`${legacyName}-${subcommand._name}`
|
|
2781
|
+
);
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
executableFile = localFile || executableFile;
|
|
2785
|
+
}
|
|
2786
|
+
launchWithNode = sourceExt.includes(path18.extname(executableFile));
|
|
2787
|
+
let proc;
|
|
2788
|
+
if (process4.platform !== "win32") {
|
|
2789
|
+
if (launchWithNode) {
|
|
2790
|
+
args.unshift(executableFile);
|
|
2791
|
+
args = incrementNodeInspectorPort(process4.execArgv).concat(args);
|
|
2792
|
+
proc = childProcess.spawn(process4.argv[0], args, { stdio: "inherit" });
|
|
2793
|
+
} else {
|
|
2794
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
2795
|
+
}
|
|
2796
|
+
} else {
|
|
2797
|
+
this._checkForMissingExecutable(
|
|
2798
|
+
executableFile,
|
|
2799
|
+
executableDir,
|
|
2800
|
+
subcommand._name
|
|
2801
|
+
);
|
|
2802
|
+
args.unshift(executableFile);
|
|
2803
|
+
args = incrementNodeInspectorPort(process4.execArgv).concat(args);
|
|
2804
|
+
proc = childProcess.spawn(process4.execPath, args, { stdio: "inherit" });
|
|
2805
|
+
}
|
|
2806
|
+
if (!proc.killed) {
|
|
2807
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
2808
|
+
signals.forEach((signal) => {
|
|
2809
|
+
process4.on(signal, () => {
|
|
2810
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
2811
|
+
proc.kill(signal);
|
|
2812
|
+
}
|
|
2813
|
+
});
|
|
2814
|
+
});
|
|
2815
|
+
}
|
|
2816
|
+
const exitCallback = this._exitCallback;
|
|
2817
|
+
proc.on("close", (code) => {
|
|
2818
|
+
code = code ?? 1;
|
|
2819
|
+
if (!exitCallback) {
|
|
2820
|
+
process4.exit(code);
|
|
2821
|
+
} else {
|
|
2822
|
+
exitCallback(
|
|
2823
|
+
new CommanderError2(
|
|
2824
|
+
code,
|
|
2825
|
+
"commander.executeSubCommandAsync",
|
|
2826
|
+
"(close)"
|
|
2827
|
+
)
|
|
2828
|
+
);
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2831
|
+
proc.on("error", (err) => {
|
|
2832
|
+
if (err.code === "ENOENT") {
|
|
2833
|
+
this._checkForMissingExecutable(
|
|
2834
|
+
executableFile,
|
|
2835
|
+
executableDir,
|
|
2836
|
+
subcommand._name
|
|
2837
|
+
);
|
|
2838
|
+
} else if (err.code === "EACCES") {
|
|
2839
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
2840
|
+
}
|
|
2841
|
+
if (!exitCallback) {
|
|
2842
|
+
process4.exit(1);
|
|
2843
|
+
} else {
|
|
2844
|
+
const wrappedError = new CommanderError2(
|
|
2845
|
+
1,
|
|
2846
|
+
"commander.executeSubCommandAsync",
|
|
2847
|
+
"(error)"
|
|
2848
|
+
);
|
|
2849
|
+
wrappedError.nestedError = err;
|
|
2850
|
+
exitCallback(wrappedError);
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
this.runningCommand = proc;
|
|
2854
|
+
}
|
|
2855
|
+
/**
|
|
2856
|
+
* @private
|
|
2857
|
+
*/
|
|
2858
|
+
_dispatchSubcommand(commandName, operands, unknown2) {
|
|
2859
|
+
const subCommand = this._findCommand(commandName);
|
|
2860
|
+
if (!subCommand) this.help({ error: true });
|
|
2861
|
+
subCommand._prepareForParse();
|
|
2862
|
+
let promiseChain;
|
|
2863
|
+
promiseChain = this._chainOrCallSubCommandHook(
|
|
2864
|
+
promiseChain,
|
|
2865
|
+
subCommand,
|
|
2866
|
+
"preSubcommand"
|
|
2867
|
+
);
|
|
2868
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2869
|
+
if (subCommand._executableHandler) {
|
|
2870
|
+
this._executeSubCommand(subCommand, operands.concat(unknown2));
|
|
2871
|
+
} else {
|
|
2872
|
+
return subCommand._parseCommand(operands, unknown2);
|
|
2873
|
+
}
|
|
2874
|
+
});
|
|
2875
|
+
return promiseChain;
|
|
2876
|
+
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Invoke help directly if possible, or dispatch if necessary.
|
|
2879
|
+
* e.g. help foo
|
|
2880
|
+
*
|
|
2881
|
+
* @private
|
|
2882
|
+
*/
|
|
2883
|
+
_dispatchHelpCommand(subcommandName) {
|
|
2884
|
+
if (!subcommandName) {
|
|
2885
|
+
this.help();
|
|
2886
|
+
}
|
|
2887
|
+
const subCommand = this._findCommand(subcommandName);
|
|
2888
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
2889
|
+
subCommand.help();
|
|
2890
|
+
}
|
|
2891
|
+
return this._dispatchSubcommand(
|
|
2892
|
+
subcommandName,
|
|
2893
|
+
[],
|
|
2894
|
+
[this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
|
|
2895
|
+
);
|
|
2896
|
+
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Check this.args against expected this.registeredArguments.
|
|
2899
|
+
*
|
|
2900
|
+
* @private
|
|
2901
|
+
*/
|
|
2902
|
+
_checkNumberOfArguments() {
|
|
2903
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
2904
|
+
if (arg.required && this.args[i] == null) {
|
|
2905
|
+
this.missingArgument(arg.name());
|
|
2906
|
+
}
|
|
2907
|
+
});
|
|
2908
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2911
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
2912
|
+
this._excessArguments(this.args);
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
2917
|
+
*
|
|
2918
|
+
* @private
|
|
2919
|
+
*/
|
|
2920
|
+
_processArguments() {
|
|
2921
|
+
const myParseArg = (argument, value, previous) => {
|
|
2922
|
+
let parsedValue = value;
|
|
2923
|
+
if (value !== null && argument.parseArg) {
|
|
2924
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2925
|
+
parsedValue = this._callParseArg(
|
|
2926
|
+
argument,
|
|
2927
|
+
value,
|
|
2928
|
+
previous,
|
|
2929
|
+
invalidValueMessage
|
|
2930
|
+
);
|
|
2931
|
+
}
|
|
2932
|
+
return parsedValue;
|
|
2933
|
+
};
|
|
2934
|
+
this._checkNumberOfArguments();
|
|
2935
|
+
const processedArgs = [];
|
|
2936
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2937
|
+
let value = declaredArg.defaultValue;
|
|
2938
|
+
if (declaredArg.variadic) {
|
|
2939
|
+
if (index < this.args.length) {
|
|
2940
|
+
value = this.args.slice(index);
|
|
2941
|
+
if (declaredArg.parseArg) {
|
|
2942
|
+
value = value.reduce((processed, v) => {
|
|
2943
|
+
return myParseArg(declaredArg, v, processed);
|
|
2944
|
+
}, declaredArg.defaultValue);
|
|
2945
|
+
}
|
|
2946
|
+
} else if (value === void 0) {
|
|
2947
|
+
value = [];
|
|
2948
|
+
}
|
|
2949
|
+
} else if (index < this.args.length) {
|
|
2950
|
+
value = this.args[index];
|
|
2951
|
+
if (declaredArg.parseArg) {
|
|
2952
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
processedArgs[index] = value;
|
|
2956
|
+
});
|
|
2957
|
+
this.processedArgs = processedArgs;
|
|
2958
|
+
}
|
|
2959
|
+
/**
|
|
2960
|
+
* Once we have a promise we chain, but call synchronously until then.
|
|
2961
|
+
*
|
|
2962
|
+
* @param {(Promise|undefined)} promise
|
|
2963
|
+
* @param {Function} fn
|
|
2964
|
+
* @return {(Promise|undefined)}
|
|
2965
|
+
* @private
|
|
2966
|
+
*/
|
|
2967
|
+
_chainOrCall(promise3, fn) {
|
|
2968
|
+
if (promise3?.then && typeof promise3.then === "function") {
|
|
2969
|
+
return promise3.then(() => fn());
|
|
2970
|
+
}
|
|
2971
|
+
return fn();
|
|
2972
|
+
}
|
|
2973
|
+
/**
|
|
2974
|
+
*
|
|
2975
|
+
* @param {(Promise|undefined)} promise
|
|
2976
|
+
* @param {string} event
|
|
2977
|
+
* @return {(Promise|undefined)}
|
|
2978
|
+
* @private
|
|
2979
|
+
*/
|
|
2980
|
+
_chainOrCallHooks(promise3, event) {
|
|
2981
|
+
let result = promise3;
|
|
2982
|
+
const hooks = [];
|
|
2983
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
2984
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback2) => {
|
|
2985
|
+
hooks.push({ hookedCommand, callback: callback2 });
|
|
2986
|
+
});
|
|
2987
|
+
});
|
|
2988
|
+
if (event === "postAction") {
|
|
2989
|
+
hooks.reverse();
|
|
2990
|
+
}
|
|
2991
|
+
hooks.forEach((hookDetail) => {
|
|
2992
|
+
result = this._chainOrCall(result, () => {
|
|
2993
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2994
|
+
});
|
|
2995
|
+
});
|
|
2996
|
+
return result;
|
|
2997
|
+
}
|
|
2998
|
+
/**
|
|
2999
|
+
*
|
|
3000
|
+
* @param {(Promise|undefined)} promise
|
|
3001
|
+
* @param {Command} subCommand
|
|
3002
|
+
* @param {string} event
|
|
3003
|
+
* @return {(Promise|undefined)}
|
|
3004
|
+
* @private
|
|
3005
|
+
*/
|
|
3006
|
+
_chainOrCallSubCommandHook(promise3, subCommand, event) {
|
|
3007
|
+
let result = promise3;
|
|
3008
|
+
if (this._lifeCycleHooks[event] !== void 0) {
|
|
3009
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
3010
|
+
result = this._chainOrCall(result, () => {
|
|
3011
|
+
return hook(this, subCommand);
|
|
3012
|
+
});
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
return result;
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Process arguments in context of this command.
|
|
3019
|
+
* Returns action result, in case it is a promise.
|
|
3020
|
+
*
|
|
3021
|
+
* @private
|
|
3022
|
+
*/
|
|
3023
|
+
_parseCommand(operands, unknown2) {
|
|
3024
|
+
const parsed = this.parseOptions(unknown2);
|
|
3025
|
+
this._parseOptionsEnv();
|
|
3026
|
+
this._parseOptionsImplied();
|
|
3027
|
+
operands = operands.concat(parsed.operands);
|
|
3028
|
+
unknown2 = parsed.unknown;
|
|
3029
|
+
this.args = operands.concat(unknown2);
|
|
3030
|
+
if (operands && this._findCommand(operands[0])) {
|
|
3031
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown2);
|
|
3032
|
+
}
|
|
3033
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
3034
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
3035
|
+
}
|
|
3036
|
+
if (this._defaultCommandName) {
|
|
3037
|
+
this._outputHelpIfRequested(unknown2);
|
|
3038
|
+
return this._dispatchSubcommand(
|
|
3039
|
+
this._defaultCommandName,
|
|
3040
|
+
operands,
|
|
3041
|
+
unknown2
|
|
3042
|
+
);
|
|
3043
|
+
}
|
|
3044
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
3045
|
+
this.help({ error: true });
|
|
3046
|
+
}
|
|
3047
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
3048
|
+
this._checkForMissingMandatoryOptions();
|
|
3049
|
+
this._checkForConflictingOptions();
|
|
3050
|
+
const checkForUnknownOptions = () => {
|
|
3051
|
+
if (parsed.unknown.length > 0) {
|
|
3052
|
+
this.unknownOption(parsed.unknown[0]);
|
|
3053
|
+
}
|
|
3054
|
+
};
|
|
3055
|
+
const commandEvent = `command:${this.name()}`;
|
|
3056
|
+
if (this._actionHandler) {
|
|
3057
|
+
checkForUnknownOptions();
|
|
3058
|
+
this._processArguments();
|
|
3059
|
+
let promiseChain;
|
|
3060
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
3061
|
+
promiseChain = this._chainOrCall(
|
|
3062
|
+
promiseChain,
|
|
3063
|
+
() => this._actionHandler(this.processedArgs)
|
|
3064
|
+
);
|
|
3065
|
+
if (this.parent) {
|
|
3066
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
3067
|
+
this.parent.emit(commandEvent, operands, unknown2);
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
3071
|
+
return promiseChain;
|
|
3072
|
+
}
|
|
3073
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
3074
|
+
checkForUnknownOptions();
|
|
3075
|
+
this._processArguments();
|
|
3076
|
+
this.parent.emit(commandEvent, operands, unknown2);
|
|
3077
|
+
} else if (operands.length) {
|
|
3078
|
+
if (this._findCommand("*")) {
|
|
3079
|
+
return this._dispatchSubcommand("*", operands, unknown2);
|
|
3080
|
+
}
|
|
3081
|
+
if (this.listenerCount("command:*")) {
|
|
3082
|
+
this.emit("command:*", operands, unknown2);
|
|
3083
|
+
} else if (this.commands.length) {
|
|
3084
|
+
this.unknownCommand();
|
|
3085
|
+
} else {
|
|
3086
|
+
checkForUnknownOptions();
|
|
3087
|
+
this._processArguments();
|
|
3088
|
+
}
|
|
3089
|
+
} else if (this.commands.length) {
|
|
3090
|
+
checkForUnknownOptions();
|
|
3091
|
+
this.help({ error: true });
|
|
3092
|
+
} else {
|
|
3093
|
+
checkForUnknownOptions();
|
|
3094
|
+
this._processArguments();
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
/**
|
|
3098
|
+
* Find matching command.
|
|
3099
|
+
*
|
|
3100
|
+
* @private
|
|
3101
|
+
* @return {Command | undefined}
|
|
3102
|
+
*/
|
|
3103
|
+
_findCommand(name) {
|
|
3104
|
+
if (!name) return void 0;
|
|
3105
|
+
return this.commands.find(
|
|
3106
|
+
(cmd) => cmd._name === name || cmd._aliases.includes(name)
|
|
3107
|
+
);
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
3110
|
+
* Return an option matching `arg` if any.
|
|
3111
|
+
*
|
|
3112
|
+
* @param {string} arg
|
|
3113
|
+
* @return {Option}
|
|
3114
|
+
* @package
|
|
3115
|
+
*/
|
|
3116
|
+
_findOption(arg) {
|
|
3117
|
+
return this.options.find((option) => option.is(arg));
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Display an error message if a mandatory option does not have a value.
|
|
3121
|
+
* Called after checking for help flags in leaf subcommand.
|
|
3122
|
+
*
|
|
3123
|
+
* @private
|
|
3124
|
+
*/
|
|
3125
|
+
_checkForMissingMandatoryOptions() {
|
|
3126
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
3127
|
+
cmd.options.forEach((anOption) => {
|
|
3128
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
|
|
3129
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
3130
|
+
}
|
|
3131
|
+
});
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* Display an error message if conflicting options are used together in this.
|
|
3136
|
+
*
|
|
3137
|
+
* @private
|
|
3138
|
+
*/
|
|
3139
|
+
_checkForConflictingLocalOptions() {
|
|
3140
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
3141
|
+
const optionKey = option.attributeName();
|
|
3142
|
+
if (this.getOptionValue(optionKey) === void 0) {
|
|
3143
|
+
return false;
|
|
3144
|
+
}
|
|
3145
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
3146
|
+
});
|
|
3147
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
3148
|
+
(option) => option.conflictsWith.length > 0
|
|
3149
|
+
);
|
|
3150
|
+
optionsWithConflicting.forEach((option) => {
|
|
3151
|
+
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
3152
|
+
(defined) => option.conflictsWith.includes(defined.attributeName())
|
|
3153
|
+
);
|
|
3154
|
+
if (conflictingAndDefined) {
|
|
3155
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
3156
|
+
}
|
|
3157
|
+
});
|
|
3158
|
+
}
|
|
3159
|
+
/**
|
|
3160
|
+
* Display an error message if conflicting options are used together.
|
|
3161
|
+
* Called after checking for help flags in leaf subcommand.
|
|
3162
|
+
*
|
|
3163
|
+
* @private
|
|
3164
|
+
*/
|
|
3165
|
+
_checkForConflictingOptions() {
|
|
3166
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
3167
|
+
cmd._checkForConflictingLocalOptions();
|
|
3168
|
+
});
|
|
3169
|
+
}
|
|
3170
|
+
/**
|
|
3171
|
+
* Parse options from `argv` removing known options,
|
|
3172
|
+
* and return argv split into operands and unknown arguments.
|
|
3173
|
+
*
|
|
3174
|
+
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
3175
|
+
*
|
|
3176
|
+
* Examples:
|
|
3177
|
+
*
|
|
3178
|
+
* argv => operands, unknown
|
|
3179
|
+
* --known kkk op => [op], []
|
|
3180
|
+
* op --known kkk => [op], []
|
|
3181
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
3182
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
3183
|
+
*
|
|
3184
|
+
* @param {string[]} args
|
|
3185
|
+
* @return {{operands: string[], unknown: string[]}}
|
|
3186
|
+
*/
|
|
3187
|
+
parseOptions(args) {
|
|
3188
|
+
const operands = [];
|
|
3189
|
+
const unknown2 = [];
|
|
3190
|
+
let dest = operands;
|
|
3191
|
+
function maybeOption(arg) {
|
|
3192
|
+
return arg.length > 1 && arg[0] === "-";
|
|
3193
|
+
}
|
|
3194
|
+
const negativeNumberArg = (arg) => {
|
|
3195
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
|
|
3196
|
+
return !this._getCommandAndAncestors().some(
|
|
3197
|
+
(cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
|
|
3198
|
+
);
|
|
3199
|
+
};
|
|
3200
|
+
let activeVariadicOption = null;
|
|
3201
|
+
let activeGroup = null;
|
|
3202
|
+
let i = 0;
|
|
3203
|
+
while (i < args.length || activeGroup) {
|
|
3204
|
+
const arg = activeGroup ?? args[i++];
|
|
3205
|
+
activeGroup = null;
|
|
3206
|
+
if (arg === "--") {
|
|
3207
|
+
if (dest === unknown2) dest.push(arg);
|
|
3208
|
+
dest.push(...args.slice(i));
|
|
3209
|
+
break;
|
|
3210
|
+
}
|
|
3211
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
3212
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
3213
|
+
continue;
|
|
3214
|
+
}
|
|
3215
|
+
activeVariadicOption = null;
|
|
3216
|
+
if (maybeOption(arg)) {
|
|
3217
|
+
const option = this._findOption(arg);
|
|
3218
|
+
if (option) {
|
|
3219
|
+
if (option.required) {
|
|
3220
|
+
const value = args[i++];
|
|
3221
|
+
if (value === void 0) this.optionMissingArgument(option);
|
|
3222
|
+
this.emit(`option:${option.name()}`, value);
|
|
3223
|
+
} else if (option.optional) {
|
|
3224
|
+
let value = null;
|
|
3225
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
3226
|
+
value = args[i++];
|
|
3227
|
+
}
|
|
3228
|
+
this.emit(`option:${option.name()}`, value);
|
|
3229
|
+
} else {
|
|
3230
|
+
this.emit(`option:${option.name()}`);
|
|
3231
|
+
}
|
|
3232
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
3237
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
3238
|
+
if (option) {
|
|
3239
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
3240
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
3241
|
+
} else {
|
|
3242
|
+
this.emit(`option:${option.name()}`);
|
|
3243
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
3244
|
+
}
|
|
3245
|
+
continue;
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
3249
|
+
const index = arg.indexOf("=");
|
|
3250
|
+
const option = this._findOption(arg.slice(0, index));
|
|
3251
|
+
if (option && (option.required || option.optional)) {
|
|
3252
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
3253
|
+
continue;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
3257
|
+
dest = unknown2;
|
|
3258
|
+
}
|
|
3259
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown2.length === 0) {
|
|
3260
|
+
if (this._findCommand(arg)) {
|
|
3261
|
+
operands.push(arg);
|
|
3262
|
+
unknown2.push(...args.slice(i));
|
|
3263
|
+
break;
|
|
3264
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
3265
|
+
operands.push(arg, ...args.slice(i));
|
|
3266
|
+
break;
|
|
3267
|
+
} else if (this._defaultCommandName) {
|
|
3268
|
+
unknown2.push(arg, ...args.slice(i));
|
|
3269
|
+
break;
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
if (this._passThroughOptions) {
|
|
3273
|
+
dest.push(arg, ...args.slice(i));
|
|
3274
|
+
break;
|
|
3275
|
+
}
|
|
3276
|
+
dest.push(arg);
|
|
3277
|
+
}
|
|
3278
|
+
return { operands, unknown: unknown2 };
|
|
3279
|
+
}
|
|
3280
|
+
/**
|
|
3281
|
+
* Return an object containing local option values as key-value pairs.
|
|
3282
|
+
*
|
|
3283
|
+
* @return {object}
|
|
3284
|
+
*/
|
|
3285
|
+
opts() {
|
|
3286
|
+
if (this._storeOptionsAsProperties) {
|
|
3287
|
+
const result = {};
|
|
3288
|
+
const len = this.options.length;
|
|
3289
|
+
for (let i = 0; i < len; i++) {
|
|
3290
|
+
const key = this.options[i].attributeName();
|
|
3291
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
3292
|
+
}
|
|
3293
|
+
return result;
|
|
3294
|
+
}
|
|
3295
|
+
return this._optionValues;
|
|
3296
|
+
}
|
|
3297
|
+
/**
|
|
3298
|
+
* Return an object containing merged local and global option values as key-value pairs.
|
|
3299
|
+
*
|
|
3300
|
+
* @return {object}
|
|
3301
|
+
*/
|
|
3302
|
+
optsWithGlobals() {
|
|
3303
|
+
return this._getCommandAndAncestors().reduce(
|
|
3304
|
+
(combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
|
|
3305
|
+
{}
|
|
3306
|
+
);
|
|
3307
|
+
}
|
|
3308
|
+
/**
|
|
3309
|
+
* Display error message and exit (or call exitOverride).
|
|
3310
|
+
*
|
|
3311
|
+
* @param {string} message
|
|
3312
|
+
* @param {object} [errorOptions]
|
|
3313
|
+
* @param {string} [errorOptions.code] - an id string representing the error
|
|
3314
|
+
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
3315
|
+
*/
|
|
3316
|
+
error(message, errorOptions) {
|
|
3317
|
+
this._outputConfiguration.outputError(
|
|
3318
|
+
`${message}
|
|
3319
|
+
`,
|
|
3320
|
+
this._outputConfiguration.writeErr
|
|
3321
|
+
);
|
|
3322
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
3323
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
3324
|
+
`);
|
|
3325
|
+
} else if (this._showHelpAfterError) {
|
|
3326
|
+
this._outputConfiguration.writeErr("\n");
|
|
3327
|
+
this.outputHelp({ error: true });
|
|
3328
|
+
}
|
|
3329
|
+
const config2 = errorOptions || {};
|
|
3330
|
+
const exitCode3 = config2.exitCode || 1;
|
|
3331
|
+
const code = config2.code || "commander.error";
|
|
3332
|
+
this._exit(exitCode3, code, message);
|
|
3333
|
+
}
|
|
3334
|
+
/**
|
|
3335
|
+
* Apply any option related environment variables, if option does
|
|
3336
|
+
* not have a value from cli or client code.
|
|
3337
|
+
*
|
|
3338
|
+
* @private
|
|
3339
|
+
*/
|
|
3340
|
+
_parseOptionsEnv() {
|
|
3341
|
+
this.options.forEach((option) => {
|
|
3342
|
+
if (option.envVar && option.envVar in process4.env) {
|
|
3343
|
+
const optionKey = option.attributeName();
|
|
3344
|
+
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
3345
|
+
this.getOptionValueSource(optionKey)
|
|
3346
|
+
)) {
|
|
3347
|
+
if (option.required || option.optional) {
|
|
3348
|
+
this.emit(`optionEnv:${option.name()}`, process4.env[option.envVar]);
|
|
3349
|
+
} else {
|
|
3350
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
});
|
|
3355
|
+
}
|
|
3356
|
+
/**
|
|
3357
|
+
* Apply any implied option values, if option is undefined or default value.
|
|
3358
|
+
*
|
|
3359
|
+
* @private
|
|
3360
|
+
*/
|
|
3361
|
+
_parseOptionsImplied() {
|
|
3362
|
+
const dualHelper = new DualOptions(this.options);
|
|
3363
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
3364
|
+
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
3365
|
+
};
|
|
3366
|
+
this.options.filter(
|
|
3367
|
+
(option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
|
|
3368
|
+
this.getOptionValue(option.attributeName()),
|
|
3369
|
+
option
|
|
3370
|
+
)
|
|
3371
|
+
).forEach((option) => {
|
|
3372
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
3373
|
+
this.setOptionValueWithSource(
|
|
3374
|
+
impliedKey,
|
|
3375
|
+
option.implied[impliedKey],
|
|
3376
|
+
"implied"
|
|
3377
|
+
);
|
|
3378
|
+
});
|
|
3379
|
+
});
|
|
3380
|
+
}
|
|
3381
|
+
/**
|
|
3382
|
+
* Argument `name` is missing.
|
|
3383
|
+
*
|
|
3384
|
+
* @param {string} name
|
|
3385
|
+
* @private
|
|
3386
|
+
*/
|
|
3387
|
+
missingArgument(name) {
|
|
3388
|
+
const message = `error: missing required argument '${name}'`;
|
|
3389
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
3390
|
+
}
|
|
3391
|
+
/**
|
|
3392
|
+
* `Option` is missing an argument.
|
|
3393
|
+
*
|
|
3394
|
+
* @param {Option} option
|
|
3395
|
+
* @private
|
|
3396
|
+
*/
|
|
3397
|
+
optionMissingArgument(option) {
|
|
3398
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
3399
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
3400
|
+
}
|
|
3401
|
+
/**
|
|
3402
|
+
* `Option` does not have a value, and is a mandatory option.
|
|
3403
|
+
*
|
|
3404
|
+
* @param {Option} option
|
|
3405
|
+
* @private
|
|
3406
|
+
*/
|
|
3407
|
+
missingMandatoryOptionValue(option) {
|
|
3408
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
3409
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
3410
|
+
}
|
|
3411
|
+
/**
|
|
3412
|
+
* `Option` conflicts with another option.
|
|
3413
|
+
*
|
|
3414
|
+
* @param {Option} option
|
|
3415
|
+
* @param {Option} conflictingOption
|
|
3416
|
+
* @private
|
|
3417
|
+
*/
|
|
3418
|
+
_conflictingOption(option, conflictingOption) {
|
|
3419
|
+
const findBestOptionFromValue = (option2) => {
|
|
3420
|
+
const optionKey = option2.attributeName();
|
|
3421
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
3422
|
+
const negativeOption = this.options.find(
|
|
3423
|
+
(target) => target.negate && optionKey === target.attributeName()
|
|
3424
|
+
);
|
|
3425
|
+
const positiveOption = this.options.find(
|
|
3426
|
+
(target) => !target.negate && optionKey === target.attributeName()
|
|
3427
|
+
);
|
|
3428
|
+
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
|
|
3429
|
+
return negativeOption;
|
|
3430
|
+
}
|
|
3431
|
+
return positiveOption || option2;
|
|
3432
|
+
};
|
|
3433
|
+
const getErrorMessage = (option2) => {
|
|
3434
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
3435
|
+
const optionKey = bestOption.attributeName();
|
|
3436
|
+
const source = this.getOptionValueSource(optionKey);
|
|
3437
|
+
if (source === "env") {
|
|
3438
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
3439
|
+
}
|
|
3440
|
+
return `option '${bestOption.flags}'`;
|
|
3441
|
+
};
|
|
3442
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
3443
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
3444
|
+
}
|
|
3445
|
+
/**
|
|
3446
|
+
* Unknown option `flag`.
|
|
3447
|
+
*
|
|
3448
|
+
* @param {string} flag
|
|
3449
|
+
* @private
|
|
3450
|
+
*/
|
|
3451
|
+
unknownOption(flag) {
|
|
3452
|
+
if (this._allowUnknownOption) return;
|
|
3453
|
+
let suggestion = "";
|
|
3454
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
3455
|
+
let candidateFlags = [];
|
|
3456
|
+
let command = this;
|
|
3457
|
+
do {
|
|
3458
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
3459
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
3460
|
+
command = command.parent;
|
|
3461
|
+
} while (command && !command._enablePositionalOptions);
|
|
3462
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
3463
|
+
}
|
|
3464
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
3465
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
3466
|
+
}
|
|
3467
|
+
/**
|
|
3468
|
+
* Excess arguments, more than expected.
|
|
3469
|
+
*
|
|
3470
|
+
* @param {string[]} receivedArgs
|
|
3471
|
+
* @private
|
|
3472
|
+
*/
|
|
3473
|
+
_excessArguments(receivedArgs) {
|
|
3474
|
+
if (this._allowExcessArguments) return;
|
|
3475
|
+
const expected = this.registeredArguments.length;
|
|
3476
|
+
const s = expected === 1 ? "" : "s";
|
|
3477
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
3478
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
3479
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
3480
|
+
}
|
|
3481
|
+
/**
|
|
3482
|
+
* Unknown command.
|
|
3483
|
+
*
|
|
3484
|
+
* @private
|
|
3485
|
+
*/
|
|
3486
|
+
unknownCommand() {
|
|
3487
|
+
const unknownName = this.args[0];
|
|
3488
|
+
let suggestion = "";
|
|
3489
|
+
if (this._showSuggestionAfterError) {
|
|
3490
|
+
const candidateNames = [];
|
|
3491
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
3492
|
+
candidateNames.push(command.name());
|
|
3493
|
+
if (command.alias()) candidateNames.push(command.alias());
|
|
3494
|
+
});
|
|
3495
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
3496
|
+
}
|
|
3497
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
3498
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
3499
|
+
}
|
|
3500
|
+
/**
|
|
3501
|
+
* Get or set the program version.
|
|
3502
|
+
*
|
|
3503
|
+
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
3504
|
+
*
|
|
3505
|
+
* You can optionally supply the flags and description to override the defaults.
|
|
3506
|
+
*
|
|
3507
|
+
* @param {string} [str]
|
|
3508
|
+
* @param {string} [flags]
|
|
3509
|
+
* @param {string} [description]
|
|
3510
|
+
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
3511
|
+
*/
|
|
3512
|
+
version(str3, flags, description) {
|
|
3513
|
+
if (str3 === void 0) return this._version;
|
|
3514
|
+
this._version = str3;
|
|
3515
|
+
flags = flags || "-V, --version";
|
|
3516
|
+
description = description || "output the version number";
|
|
3517
|
+
const versionOption = this.createOption(flags, description);
|
|
3518
|
+
this._versionOptionName = versionOption.attributeName();
|
|
3519
|
+
this._registerOption(versionOption);
|
|
3520
|
+
this.on("option:" + versionOption.name(), () => {
|
|
3521
|
+
this._outputConfiguration.writeOut(`${str3}
|
|
3522
|
+
`);
|
|
3523
|
+
this._exit(0, "commander.version", str3);
|
|
3524
|
+
});
|
|
3525
|
+
return this;
|
|
3526
|
+
}
|
|
3527
|
+
/**
|
|
3528
|
+
* Set the description.
|
|
3529
|
+
*
|
|
3530
|
+
* @param {string} [str]
|
|
3531
|
+
* @param {object} [argsDescription]
|
|
3532
|
+
* @return {(string|Command)}
|
|
3533
|
+
*/
|
|
3534
|
+
description(str3, argsDescription) {
|
|
3535
|
+
if (str3 === void 0 && argsDescription === void 0)
|
|
3536
|
+
return this._description;
|
|
3537
|
+
this._description = str3;
|
|
3538
|
+
if (argsDescription) {
|
|
3539
|
+
this._argsDescription = argsDescription;
|
|
3540
|
+
}
|
|
3541
|
+
return this;
|
|
3542
|
+
}
|
|
3543
|
+
/**
|
|
3544
|
+
* Set the summary. Used when listed as subcommand of parent.
|
|
3545
|
+
*
|
|
3546
|
+
* @param {string} [str]
|
|
3547
|
+
* @return {(string|Command)}
|
|
3548
|
+
*/
|
|
3549
|
+
summary(str3) {
|
|
3550
|
+
if (str3 === void 0) return this._summary;
|
|
3551
|
+
this._summary = str3;
|
|
3552
|
+
return this;
|
|
3553
|
+
}
|
|
3554
|
+
/**
|
|
3555
|
+
* Set an alias for the command.
|
|
3556
|
+
*
|
|
3557
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
3558
|
+
*
|
|
3559
|
+
* @param {string} [alias]
|
|
3560
|
+
* @return {(string|Command)}
|
|
3561
|
+
*/
|
|
3562
|
+
alias(alias) {
|
|
3563
|
+
if (alias === void 0) return this._aliases[0];
|
|
3564
|
+
let command = this;
|
|
3565
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
3566
|
+
command = this.commands[this.commands.length - 1];
|
|
3567
|
+
}
|
|
3568
|
+
if (alias === command._name)
|
|
3569
|
+
throw new Error("Command alias can't be the same as its name");
|
|
3570
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
3571
|
+
if (matchingCommand) {
|
|
3572
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
3573
|
+
throw new Error(
|
|
3574
|
+
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
|
|
3575
|
+
);
|
|
3576
|
+
}
|
|
3577
|
+
command._aliases.push(alias);
|
|
3578
|
+
return this;
|
|
3579
|
+
}
|
|
3580
|
+
/**
|
|
3581
|
+
* Set aliases for the command.
|
|
3582
|
+
*
|
|
3583
|
+
* Only the first alias is shown in the auto-generated help.
|
|
3584
|
+
*
|
|
3585
|
+
* @param {string[]} [aliases]
|
|
3586
|
+
* @return {(string[]|Command)}
|
|
3587
|
+
*/
|
|
3588
|
+
aliases(aliases) {
|
|
3589
|
+
if (aliases === void 0) return this._aliases;
|
|
3590
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
3591
|
+
return this;
|
|
3592
|
+
}
|
|
3593
|
+
/**
|
|
3594
|
+
* Set / get the command usage `str`.
|
|
3595
|
+
*
|
|
3596
|
+
* @param {string} [str]
|
|
3597
|
+
* @return {(string|Command)}
|
|
3598
|
+
*/
|
|
3599
|
+
usage(str3) {
|
|
3600
|
+
if (str3 === void 0) {
|
|
3601
|
+
if (this._usage) return this._usage;
|
|
3602
|
+
const args = this.registeredArguments.map((arg) => {
|
|
3603
|
+
return humanReadableArgName(arg);
|
|
3604
|
+
});
|
|
3605
|
+
return [].concat(
|
|
3606
|
+
this.options.length || this._helpOption !== null ? "[options]" : [],
|
|
3607
|
+
this.commands.length ? "[command]" : [],
|
|
3608
|
+
this.registeredArguments.length ? args : []
|
|
3609
|
+
).join(" ");
|
|
3610
|
+
}
|
|
3611
|
+
this._usage = str3;
|
|
3612
|
+
return this;
|
|
3613
|
+
}
|
|
3614
|
+
/**
|
|
3615
|
+
* Get or set the name of the command.
|
|
3616
|
+
*
|
|
3617
|
+
* @param {string} [str]
|
|
3618
|
+
* @return {(string|Command)}
|
|
3619
|
+
*/
|
|
3620
|
+
name(str3) {
|
|
3621
|
+
if (str3 === void 0) return this._name;
|
|
3622
|
+
this._name = str3;
|
|
3623
|
+
return this;
|
|
3624
|
+
}
|
|
3625
|
+
/**
|
|
3626
|
+
* Set/get the help group heading for this subcommand in parent command's help.
|
|
3627
|
+
*
|
|
3628
|
+
* @param {string} [heading]
|
|
3629
|
+
* @return {Command | string}
|
|
3630
|
+
*/
|
|
3631
|
+
helpGroup(heading) {
|
|
3632
|
+
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
3633
|
+
this._helpGroupHeading = heading;
|
|
3634
|
+
return this;
|
|
3635
|
+
}
|
|
3636
|
+
/**
|
|
3637
|
+
* Set/get the default help group heading for subcommands added to this command.
|
|
3638
|
+
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
3639
|
+
*
|
|
3640
|
+
* @example
|
|
3641
|
+
* program.commandsGroup('Development Commands:);
|
|
3642
|
+
* program.command('watch')...
|
|
3643
|
+
* program.command('lint')...
|
|
3644
|
+
* ...
|
|
3645
|
+
*
|
|
3646
|
+
* @param {string} [heading]
|
|
3647
|
+
* @returns {Command | string}
|
|
3648
|
+
*/
|
|
3649
|
+
commandsGroup(heading) {
|
|
3650
|
+
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
3651
|
+
this._defaultCommandGroup = heading;
|
|
3652
|
+
return this;
|
|
3653
|
+
}
|
|
3654
|
+
/**
|
|
3655
|
+
* Set/get the default help group heading for options added to this command.
|
|
3656
|
+
* (This does not override a group set directly on the option using .helpGroup().)
|
|
3657
|
+
*
|
|
3658
|
+
* @example
|
|
3659
|
+
* program
|
|
3660
|
+
* .optionsGroup('Development Options:')
|
|
3661
|
+
* .option('-d, --debug', 'output extra debugging')
|
|
3662
|
+
* .option('-p, --profile', 'output profiling information')
|
|
3663
|
+
*
|
|
3664
|
+
* @param {string} [heading]
|
|
3665
|
+
* @returns {Command | string}
|
|
3666
|
+
*/
|
|
3667
|
+
optionsGroup(heading) {
|
|
3668
|
+
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
3669
|
+
this._defaultOptionGroup = heading;
|
|
3670
|
+
return this;
|
|
3671
|
+
}
|
|
3672
|
+
/**
|
|
3673
|
+
* @param {Option} option
|
|
3674
|
+
* @private
|
|
3675
|
+
*/
|
|
3676
|
+
_initOptionGroup(option) {
|
|
3677
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
3678
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
3679
|
+
}
|
|
3680
|
+
/**
|
|
3681
|
+
* @param {Command} cmd
|
|
3682
|
+
* @private
|
|
3683
|
+
*/
|
|
3684
|
+
_initCommandGroup(cmd) {
|
|
3685
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
3686
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
3687
|
+
}
|
|
3688
|
+
/**
|
|
3689
|
+
* Set the name of the command from script filename, such as process.argv[1],
|
|
3690
|
+
* or require.main.filename, or __filename.
|
|
3691
|
+
*
|
|
3692
|
+
* (Used internally and public although not documented in README.)
|
|
3693
|
+
*
|
|
3694
|
+
* @example
|
|
3695
|
+
* program.nameFromFilename(require.main.filename);
|
|
3696
|
+
*
|
|
3697
|
+
* @param {string} filename
|
|
3698
|
+
* @return {Command}
|
|
3699
|
+
*/
|
|
3700
|
+
nameFromFilename(filename) {
|
|
3701
|
+
this._name = path18.basename(filename, path18.extname(filename));
|
|
3702
|
+
return this;
|
|
3703
|
+
}
|
|
3704
|
+
/**
|
|
3705
|
+
* Get or set the directory for searching for executable subcommands of this command.
|
|
3706
|
+
*
|
|
3707
|
+
* @example
|
|
3708
|
+
* program.executableDir(__dirname);
|
|
3709
|
+
* // or
|
|
3710
|
+
* program.executableDir('subcommands');
|
|
3711
|
+
*
|
|
3712
|
+
* @param {string} [path]
|
|
3713
|
+
* @return {(string|null|Command)}
|
|
3714
|
+
*/
|
|
3715
|
+
executableDir(path19) {
|
|
3716
|
+
if (path19 === void 0) return this._executableDir;
|
|
3717
|
+
this._executableDir = path19;
|
|
3718
|
+
return this;
|
|
3719
|
+
}
|
|
3720
|
+
/**
|
|
3721
|
+
* Return program help documentation.
|
|
3722
|
+
*
|
|
3723
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
3724
|
+
* @return {string}
|
|
3725
|
+
*/
|
|
3726
|
+
helpInformation(contextOptions) {
|
|
3727
|
+
const helper = this.createHelp();
|
|
3728
|
+
const context = this._getOutputContext(contextOptions);
|
|
3729
|
+
helper.prepareContext({
|
|
3730
|
+
error: context.error,
|
|
3731
|
+
helpWidth: context.helpWidth,
|
|
3732
|
+
outputHasColors: context.hasColors
|
|
3733
|
+
});
|
|
3734
|
+
const text = helper.formatHelp(this, helper);
|
|
3735
|
+
if (context.hasColors) return text;
|
|
3736
|
+
return this._outputConfiguration.stripColor(text);
|
|
3737
|
+
}
|
|
3738
|
+
/**
|
|
3739
|
+
* @typedef HelpContext
|
|
3740
|
+
* @type {object}
|
|
3741
|
+
* @property {boolean} error
|
|
3742
|
+
* @property {number} helpWidth
|
|
3743
|
+
* @property {boolean} hasColors
|
|
3744
|
+
* @property {function} write - includes stripColor if needed
|
|
3745
|
+
*
|
|
3746
|
+
* @returns {HelpContext}
|
|
3747
|
+
* @private
|
|
3748
|
+
*/
|
|
3749
|
+
_getOutputContext(contextOptions) {
|
|
3750
|
+
contextOptions = contextOptions || {};
|
|
3751
|
+
const error50 = !!contextOptions.error;
|
|
3752
|
+
let baseWrite;
|
|
3753
|
+
let hasColors;
|
|
3754
|
+
let helpWidth;
|
|
3755
|
+
if (error50) {
|
|
3756
|
+
baseWrite = (str3) => this._outputConfiguration.writeErr(str3);
|
|
3757
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
3758
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
3759
|
+
} else {
|
|
3760
|
+
baseWrite = (str3) => this._outputConfiguration.writeOut(str3);
|
|
3761
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
3762
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
3763
|
+
}
|
|
3764
|
+
const write = (str3) => {
|
|
3765
|
+
if (!hasColors) str3 = this._outputConfiguration.stripColor(str3);
|
|
3766
|
+
return baseWrite(str3);
|
|
3767
|
+
};
|
|
3768
|
+
return { error: error50, write, hasColors, helpWidth };
|
|
3769
|
+
}
|
|
3770
|
+
/**
|
|
3771
|
+
* Output help information for this command.
|
|
3772
|
+
*
|
|
3773
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
3774
|
+
*
|
|
3775
|
+
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
3776
|
+
*/
|
|
3777
|
+
outputHelp(contextOptions) {
|
|
3778
|
+
let deprecatedCallback;
|
|
3779
|
+
if (typeof contextOptions === "function") {
|
|
3780
|
+
deprecatedCallback = contextOptions;
|
|
3781
|
+
contextOptions = void 0;
|
|
3782
|
+
}
|
|
3783
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
3784
|
+
const eventContext = {
|
|
3785
|
+
error: outputContext.error,
|
|
3786
|
+
write: outputContext.write,
|
|
3787
|
+
command: this
|
|
3788
|
+
};
|
|
3789
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
3790
|
+
this.emit("beforeHelp", eventContext);
|
|
3791
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
3792
|
+
if (deprecatedCallback) {
|
|
3793
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
3794
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
3795
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
outputContext.write(helpInformation);
|
|
3799
|
+
if (this._getHelpOption()?.long) {
|
|
3800
|
+
this.emit(this._getHelpOption().long);
|
|
3801
|
+
}
|
|
3802
|
+
this.emit("afterHelp", eventContext);
|
|
3803
|
+
this._getCommandAndAncestors().forEach(
|
|
3804
|
+
(command) => command.emit("afterAllHelp", eventContext)
|
|
3805
|
+
);
|
|
3806
|
+
}
|
|
3807
|
+
/**
|
|
3808
|
+
* You can pass in flags and a description to customise the built-in help option.
|
|
3809
|
+
* Pass in false to disable the built-in help option.
|
|
3810
|
+
*
|
|
3811
|
+
* @example
|
|
3812
|
+
* program.helpOption('-?, --help' 'show help'); // customise
|
|
3813
|
+
* program.helpOption(false); // disable
|
|
3814
|
+
*
|
|
3815
|
+
* @param {(string | boolean)} flags
|
|
3816
|
+
* @param {string} [description]
|
|
3817
|
+
* @return {Command} `this` command for chaining
|
|
3818
|
+
*/
|
|
3819
|
+
helpOption(flags, description) {
|
|
3820
|
+
if (typeof flags === "boolean") {
|
|
3821
|
+
if (flags) {
|
|
3822
|
+
if (this._helpOption === null) this._helpOption = void 0;
|
|
3823
|
+
if (this._defaultOptionGroup) {
|
|
3824
|
+
this._initOptionGroup(this._getHelpOption());
|
|
3825
|
+
}
|
|
3826
|
+
} else {
|
|
3827
|
+
this._helpOption = null;
|
|
3828
|
+
}
|
|
3829
|
+
return this;
|
|
3830
|
+
}
|
|
3831
|
+
this._helpOption = this.createOption(
|
|
3832
|
+
flags ?? "-h, --help",
|
|
3833
|
+
description ?? "display help for command"
|
|
3834
|
+
);
|
|
3835
|
+
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
3836
|
+
return this;
|
|
3837
|
+
}
|
|
3838
|
+
/**
|
|
3839
|
+
* Lazy create help option.
|
|
3840
|
+
* Returns null if has been disabled with .helpOption(false).
|
|
3841
|
+
*
|
|
3842
|
+
* @returns {(Option | null)} the help option
|
|
3843
|
+
* @package
|
|
3844
|
+
*/
|
|
3845
|
+
_getHelpOption() {
|
|
3846
|
+
if (this._helpOption === void 0) {
|
|
3847
|
+
this.helpOption(void 0, void 0);
|
|
3848
|
+
}
|
|
3849
|
+
return this._helpOption;
|
|
3850
|
+
}
|
|
3851
|
+
/**
|
|
3852
|
+
* Supply your own option to use for the built-in help option.
|
|
3853
|
+
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
3854
|
+
*
|
|
3855
|
+
* @param {Option} option
|
|
3856
|
+
* @return {Command} `this` command for chaining
|
|
3857
|
+
*/
|
|
3858
|
+
addHelpOption(option) {
|
|
3859
|
+
this._helpOption = option;
|
|
3860
|
+
this._initOptionGroup(option);
|
|
3861
|
+
return this;
|
|
3862
|
+
}
|
|
3863
|
+
/**
|
|
3864
|
+
* Output help information and exit.
|
|
3865
|
+
*
|
|
3866
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
3867
|
+
*
|
|
3868
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
3869
|
+
*/
|
|
3870
|
+
help(contextOptions) {
|
|
3871
|
+
this.outputHelp(contextOptions);
|
|
3872
|
+
let exitCode3 = Number(process4.exitCode ?? 0);
|
|
3873
|
+
if (exitCode3 === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
3874
|
+
exitCode3 = 1;
|
|
3875
|
+
}
|
|
3876
|
+
this._exit(exitCode3, "commander.help", "(outputHelp)");
|
|
3877
|
+
}
|
|
3878
|
+
/**
|
|
3879
|
+
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
3880
|
+
* @typedef HelpTextEventContext
|
|
3881
|
+
* @type {object}
|
|
3882
|
+
* @property {boolean} error
|
|
3883
|
+
* @property {Command} command
|
|
3884
|
+
* @property {function} write
|
|
3885
|
+
*/
|
|
3886
|
+
/**
|
|
3887
|
+
* Add additional text to be displayed with the built-in help.
|
|
3888
|
+
*
|
|
3889
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
3890
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
3891
|
+
*
|
|
3892
|
+
* @param {string} position - before or after built-in help
|
|
3893
|
+
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
3894
|
+
* @return {Command} `this` command for chaining
|
|
3895
|
+
*/
|
|
3896
|
+
addHelpText(position, text) {
|
|
3897
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
3898
|
+
if (!allowedValues.includes(position)) {
|
|
3899
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
3900
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
3901
|
+
}
|
|
3902
|
+
const helpEvent = `${position}Help`;
|
|
3903
|
+
this.on(helpEvent, (context) => {
|
|
3904
|
+
let helpStr;
|
|
3905
|
+
if (typeof text === "function") {
|
|
3906
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
3907
|
+
} else {
|
|
3908
|
+
helpStr = text;
|
|
3909
|
+
}
|
|
3910
|
+
if (helpStr) {
|
|
3911
|
+
context.write(`${helpStr}
|
|
3912
|
+
`);
|
|
3913
|
+
}
|
|
3914
|
+
});
|
|
3915
|
+
return this;
|
|
3916
|
+
}
|
|
3917
|
+
/**
|
|
3918
|
+
* Output help information if help flags specified
|
|
3919
|
+
*
|
|
3920
|
+
* @param {Array} args - array of options to search for help flags
|
|
3921
|
+
* @private
|
|
3922
|
+
*/
|
|
3923
|
+
_outputHelpIfRequested(args) {
|
|
3924
|
+
const helpOption = this._getHelpOption();
|
|
3925
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
3926
|
+
if (helpRequested) {
|
|
3927
|
+
this.outputHelp();
|
|
3928
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
};
|
|
3932
|
+
function incrementNodeInspectorPort(args) {
|
|
3933
|
+
return args.map((arg) => {
|
|
3934
|
+
if (!arg.startsWith("--inspect")) {
|
|
3935
|
+
return arg;
|
|
3936
|
+
}
|
|
3937
|
+
let debugOption;
|
|
3938
|
+
let debugHost = "127.0.0.1";
|
|
3939
|
+
let debugPort = "9229";
|
|
3940
|
+
let match2;
|
|
3941
|
+
if ((match2 = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
3942
|
+
debugOption = match2[1];
|
|
3943
|
+
} else if ((match2 = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
3944
|
+
debugOption = match2[1];
|
|
3945
|
+
if (/^\d+$/.test(match2[3])) {
|
|
3946
|
+
debugPort = match2[3];
|
|
3947
|
+
} else {
|
|
3948
|
+
debugHost = match2[3];
|
|
3949
|
+
}
|
|
3950
|
+
} else if ((match2 = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
3951
|
+
debugOption = match2[1];
|
|
3952
|
+
debugHost = match2[3];
|
|
3953
|
+
debugPort = match2[4];
|
|
3954
|
+
}
|
|
3955
|
+
if (debugOption && debugPort !== "0") {
|
|
3956
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
3957
|
+
}
|
|
3958
|
+
return arg;
|
|
3959
|
+
});
|
|
3960
|
+
}
|
|
3961
|
+
function useColor() {
|
|
3962
|
+
if (process4.env.NO_COLOR || process4.env.FORCE_COLOR === "0" || process4.env.FORCE_COLOR === "false")
|
|
3963
|
+
return false;
|
|
3964
|
+
if (process4.env.FORCE_COLOR || process4.env.CLICOLOR_FORCE !== void 0)
|
|
3965
|
+
return true;
|
|
3966
|
+
return void 0;
|
|
3967
|
+
}
|
|
3968
|
+
exports2.Command = Command2;
|
|
3969
|
+
exports2.useColor = useColor;
|
|
3970
|
+
}
|
|
3971
|
+
});
|
|
3972
|
+
|
|
3973
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/index.js
|
|
3974
|
+
var require_commander = __commonJS({
|
|
3975
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/index.js"(exports2) {
|
|
3976
|
+
"use strict";
|
|
3977
|
+
var { Argument: Argument2 } = require_argument();
|
|
3978
|
+
var { Command: Command2 } = require_command();
|
|
3979
|
+
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
3980
|
+
var { Help: Help2 } = require_help();
|
|
3981
|
+
var { Option: Option2 } = require_option();
|
|
3982
|
+
exports2.program = new Command2();
|
|
3983
|
+
exports2.createCommand = (name) => new Command2(name);
|
|
3984
|
+
exports2.createOption = (flags, description) => new Option2(flags, description);
|
|
3985
|
+
exports2.createArgument = (name, description) => new Argument2(name, description);
|
|
3986
|
+
exports2.Command = Command2;
|
|
3987
|
+
exports2.Option = Option2;
|
|
3988
|
+
exports2.Argument = Argument2;
|
|
3989
|
+
exports2.Help = Help2;
|
|
3990
|
+
exports2.CommanderError = CommanderError2;
|
|
3991
|
+
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
3992
|
+
exports2.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
3993
|
+
}
|
|
3994
|
+
});
|
|
3995
|
+
|
|
3996
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs
|
|
3997
|
+
var import_index, program, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help;
|
|
3998
|
+
var init_esm = __esm({
|
|
3999
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs"() {
|
|
4000
|
+
"use strict";
|
|
4001
|
+
import_index = __toESM(require_commander(), 1);
|
|
4002
|
+
({
|
|
4003
|
+
program,
|
|
4004
|
+
createCommand,
|
|
4005
|
+
createArgument,
|
|
4006
|
+
createOption,
|
|
4007
|
+
CommanderError,
|
|
4008
|
+
InvalidArgumentError,
|
|
4009
|
+
InvalidOptionArgumentError,
|
|
4010
|
+
Command: (
|
|
4011
|
+
// deprecated old name
|
|
4012
|
+
Command
|
|
4013
|
+
),
|
|
4014
|
+
Argument,
|
|
4015
|
+
Option,
|
|
4016
|
+
Help
|
|
4017
|
+
} = import_index.default);
|
|
4018
|
+
}
|
|
4019
|
+
});
|
|
4020
|
+
|
|
563
4021
|
// ../../node_modules/.pnpm/smol-toml@1.6.1/node_modules/smol-toml/dist/error.js
|
|
564
4022
|
function getLineColFromPtr(string4, ptr) {
|
|
565
4023
|
let lines = string4.slice(0, ptr).split(/\r\n|\n|\r/g);
|
|
@@ -21225,7 +24683,7 @@ var init_node_figlet = __esm({
|
|
|
21225
24683
|
|
|
21226
24684
|
// ../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js
|
|
21227
24685
|
var balanced, maybeMatch, range;
|
|
21228
|
-
var
|
|
24686
|
+
var init_esm2 = __esm({
|
|
21229
24687
|
"../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js"() {
|
|
21230
24688
|
"use strict";
|
|
21231
24689
|
balanced = (a, b, str3) => {
|
|
@@ -21426,10 +24884,10 @@ function expand_(str3, max, isTop) {
|
|
|
21426
24884
|
return expansions;
|
|
21427
24885
|
}
|
|
21428
24886
|
var escSlash, escOpen, escClose, escComma, escPeriod, escSlashPattern, escOpenPattern, escClosePattern, escCommaPattern, escPeriodPattern, slashPattern, openPattern, closePattern, commaPattern, periodPattern, EXPANSION_MAX;
|
|
21429
|
-
var
|
|
24887
|
+
var init_esm3 = __esm({
|
|
21430
24888
|
"../../node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js"() {
|
|
21431
24889
|
"use strict";
|
|
21432
|
-
|
|
24890
|
+
init_esm2();
|
|
21433
24891
|
escSlash = "\0SLASH" + Math.random() + "\0";
|
|
21434
24892
|
escOpen = "\0OPEN" + Math.random() + "\0";
|
|
21435
24893
|
escClose = "\0CLOSE" + Math.random() + "\0";
|
|
@@ -22262,10 +25720,10 @@ var init_escape = __esm({
|
|
|
22262
25720
|
|
|
22263
25721
|
// ../../node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js
|
|
22264
25722
|
var minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform, path7, sep, GLOBSTAR, qmark2, star2, twoStarDot, twoStarNoDot, filter, ext, defaults, braceExpand, makeRe, match, globMagic, regExpEscape2, Minimatch;
|
|
22265
|
-
var
|
|
25723
|
+
var init_esm4 = __esm({
|
|
22266
25724
|
"../../node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js"() {
|
|
22267
25725
|
"use strict";
|
|
22268
|
-
|
|
25726
|
+
init_esm3();
|
|
22269
25727
|
init_assert_valid_pattern();
|
|
22270
25728
|
init_ast();
|
|
22271
25729
|
init_escape();
|
|
@@ -30343,7 +33801,6 @@ import fs10 from "fs";
|
|
|
30343
33801
|
import * as path82 from "path";
|
|
30344
33802
|
import { cwd as cwd2 } from "process";
|
|
30345
33803
|
import path92 from "path";
|
|
30346
|
-
import { Command } from "commander";
|
|
30347
33804
|
function parseCargoToml(cargoPath) {
|
|
30348
33805
|
const content = fs9.readFileSync(cargoPath, "utf-8");
|
|
30349
33806
|
return parse(content);
|
|
@@ -32122,9 +35579,10 @@ var init_chunk_UBCKZYTO = __esm({
|
|
|
32122
35579
|
init_node_figlet();
|
|
32123
35580
|
init_dist();
|
|
32124
35581
|
import_semver5 = __toESM(require_semver2(), 1);
|
|
32125
|
-
|
|
35582
|
+
init_esm4();
|
|
32126
35583
|
init_manypkg_get_packages();
|
|
32127
|
-
|
|
35584
|
+
init_esm4();
|
|
35585
|
+
init_esm();
|
|
32128
35586
|
ConfigError2 = class extends ReleaseKitError2 {
|
|
32129
35587
|
code = "CONFIG_ERROR";
|
|
32130
35588
|
suggestions;
|
|
@@ -47927,7 +51385,7 @@ var require_runtime = __commonJS({
|
|
|
47927
51385
|
return ret2;
|
|
47928
51386
|
},
|
|
47929
51387
|
programs: [],
|
|
47930
|
-
program: function
|
|
51388
|
+
program: function program2(i, data, declaredBlockParams, blockParams, depths) {
|
|
47931
51389
|
var programWrapper = this.programs[i], fn = this.fn(i);
|
|
47932
51390
|
if (data || depths || blockParams || declaredBlockParams) {
|
|
47933
51391
|
programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
|
|
@@ -48303,9 +51761,9 @@ var require_parser = __commonJS({
|
|
|
48303
51761
|
this.$ = { strip: yy.stripFlags($$[$0 - 1], $$[$0 - 1]), program: $$[$0] };
|
|
48304
51762
|
break;
|
|
48305
51763
|
case 19:
|
|
48306
|
-
var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$),
|
|
48307
|
-
|
|
48308
|
-
this.$ = { strip: $$[$0 - 2].strip, program, chain: true };
|
|
51764
|
+
var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$), program2 = yy.prepareProgram([inverse], $$[$0 - 1].loc);
|
|
51765
|
+
program2.chained = true;
|
|
51766
|
+
this.$ = { strip: $$[$0 - 2].strip, program: program2, chain: true };
|
|
48309
51767
|
break;
|
|
48310
51768
|
case 20:
|
|
48311
51769
|
this.$ = $$[$0];
|
|
@@ -48997,8 +52455,8 @@ var require_visitor = __commonJS({
|
|
|
48997
52455
|
return object2;
|
|
48998
52456
|
}
|
|
48999
52457
|
},
|
|
49000
|
-
Program: function Program(
|
|
49001
|
-
this.acceptArray(
|
|
52458
|
+
Program: function Program(program2) {
|
|
52459
|
+
this.acceptArray(program2.body);
|
|
49002
52460
|
},
|
|
49003
52461
|
MustacheStatement: visitSubExpression,
|
|
49004
52462
|
Decorator: visitSubExpression,
|
|
@@ -49068,11 +52526,11 @@ var require_whitespace_control = __commonJS({
|
|
|
49068
52526
|
this.options = options;
|
|
49069
52527
|
}
|
|
49070
52528
|
WhitespaceControl.prototype = new _visitor2["default"]();
|
|
49071
|
-
WhitespaceControl.prototype.Program = function(
|
|
52529
|
+
WhitespaceControl.prototype.Program = function(program2) {
|
|
49072
52530
|
var doStandalone = !this.options.ignoreStandalone;
|
|
49073
52531
|
var isRoot2 = !this.isRootSeen;
|
|
49074
52532
|
this.isRootSeen = true;
|
|
49075
|
-
var body =
|
|
52533
|
+
var body = program2.body;
|
|
49076
52534
|
for (var i = 0, l = body.length; i < l; i++) {
|
|
49077
52535
|
var current = body[i], strip3 = this.accept(current);
|
|
49078
52536
|
if (!strip3) {
|
|
@@ -49102,12 +52560,12 @@ var require_whitespace_control = __commonJS({
|
|
|
49102
52560
|
omitLeft((current.inverse || current.program).body);
|
|
49103
52561
|
}
|
|
49104
52562
|
}
|
|
49105
|
-
return
|
|
52563
|
+
return program2;
|
|
49106
52564
|
};
|
|
49107
52565
|
WhitespaceControl.prototype.BlockStatement = WhitespaceControl.prototype.DecoratorBlock = WhitespaceControl.prototype.PartialBlockStatement = function(block) {
|
|
49108
52566
|
this.accept(block.program);
|
|
49109
52567
|
this.accept(block.inverse);
|
|
49110
|
-
var
|
|
52568
|
+
var program2 = block.program || block.inverse, inverse = block.program && block.inverse, firstInverse = inverse, lastInverse = inverse;
|
|
49111
52569
|
if (inverse && inverse.chained) {
|
|
49112
52570
|
firstInverse = inverse.body[0].program;
|
|
49113
52571
|
while (lastInverse.chained) {
|
|
@@ -49119,16 +52577,16 @@ var require_whitespace_control = __commonJS({
|
|
|
49119
52577
|
close: block.closeStrip.close,
|
|
49120
52578
|
// Determine the standalone candiacy. Basically flag our content as being possibly standalone
|
|
49121
52579
|
// so our parent can determine if we actually are standalone
|
|
49122
|
-
openStandalone: isNextWhitespace(
|
|
49123
|
-
closeStandalone: isPrevWhitespace((firstInverse ||
|
|
52580
|
+
openStandalone: isNextWhitespace(program2.body),
|
|
52581
|
+
closeStandalone: isPrevWhitespace((firstInverse || program2).body)
|
|
49124
52582
|
};
|
|
49125
52583
|
if (block.openStrip.close) {
|
|
49126
|
-
omitRight(
|
|
52584
|
+
omitRight(program2.body, null, true);
|
|
49127
52585
|
}
|
|
49128
52586
|
if (inverse) {
|
|
49129
52587
|
var inverseStrip = block.inverseStrip;
|
|
49130
52588
|
if (inverseStrip.open) {
|
|
49131
|
-
omitLeft(
|
|
52589
|
+
omitLeft(program2.body, null, true);
|
|
49132
52590
|
}
|
|
49133
52591
|
if (inverseStrip.close) {
|
|
49134
52592
|
omitRight(firstInverse.body, null, true);
|
|
@@ -49136,12 +52594,12 @@ var require_whitespace_control = __commonJS({
|
|
|
49136
52594
|
if (block.closeStrip.open) {
|
|
49137
52595
|
omitLeft(lastInverse.body, null, true);
|
|
49138
52596
|
}
|
|
49139
|
-
if (!this.options.ignoreStandalone && isPrevWhitespace(
|
|
49140
|
-
omitLeft(
|
|
52597
|
+
if (!this.options.ignoreStandalone && isPrevWhitespace(program2.body) && isNextWhitespace(firstInverse.body)) {
|
|
52598
|
+
omitLeft(program2.body);
|
|
49141
52599
|
omitRight(firstInverse.body);
|
|
49142
52600
|
}
|
|
49143
52601
|
} else if (block.closeStrip.open) {
|
|
49144
|
-
omitLeft(
|
|
52602
|
+
omitLeft(program2.body, null, true);
|
|
49145
52603
|
}
|
|
49146
52604
|
return strip3;
|
|
49147
52605
|
};
|
|
@@ -49299,7 +52757,7 @@ var require_helpers2 = __commonJS({
|
|
|
49299
52757
|
function prepareRawBlock(openRawBlock, contents, close, locInfo) {
|
|
49300
52758
|
validateClose(openRawBlock, close);
|
|
49301
52759
|
locInfo = this.locInfo(locInfo);
|
|
49302
|
-
var
|
|
52760
|
+
var program2 = {
|
|
49303
52761
|
type: "Program",
|
|
49304
52762
|
body: contents,
|
|
49305
52763
|
strip: {},
|
|
@@ -49310,19 +52768,19 @@ var require_helpers2 = __commonJS({
|
|
|
49310
52768
|
path: openRawBlock.path,
|
|
49311
52769
|
params: openRawBlock.params,
|
|
49312
52770
|
hash: openRawBlock.hash,
|
|
49313
|
-
program,
|
|
52771
|
+
program: program2,
|
|
49314
52772
|
openStrip: {},
|
|
49315
52773
|
inverseStrip: {},
|
|
49316
52774
|
closeStrip: {},
|
|
49317
52775
|
loc: locInfo
|
|
49318
52776
|
};
|
|
49319
52777
|
}
|
|
49320
|
-
function prepareBlock(openBlock,
|
|
52778
|
+
function prepareBlock(openBlock, program2, inverseAndProgram, close, inverted, locInfo) {
|
|
49321
52779
|
if (close && close.path) {
|
|
49322
52780
|
validateClose(openBlock, close);
|
|
49323
52781
|
}
|
|
49324
52782
|
var decorator = /\*/.test(openBlock.open);
|
|
49325
|
-
|
|
52783
|
+
program2.blockParams = openBlock.blockParams;
|
|
49326
52784
|
var inverse = void 0, inverseStrip = void 0;
|
|
49327
52785
|
if (inverseAndProgram) {
|
|
49328
52786
|
if (decorator) {
|
|
@@ -49336,15 +52794,15 @@ var require_helpers2 = __commonJS({
|
|
|
49336
52794
|
}
|
|
49337
52795
|
if (inverted) {
|
|
49338
52796
|
inverted = inverse;
|
|
49339
|
-
inverse =
|
|
49340
|
-
|
|
52797
|
+
inverse = program2;
|
|
52798
|
+
program2 = inverted;
|
|
49341
52799
|
}
|
|
49342
52800
|
return {
|
|
49343
52801
|
type: decorator ? "DecoratorBlock" : "BlockStatement",
|
|
49344
52802
|
path: openBlock.path,
|
|
49345
52803
|
params: openBlock.params,
|
|
49346
52804
|
hash: openBlock.hash,
|
|
49347
|
-
program,
|
|
52805
|
+
program: program2,
|
|
49348
52806
|
inverse,
|
|
49349
52807
|
openStrip: openBlock.strip,
|
|
49350
52808
|
inverseStrip,
|
|
@@ -49376,14 +52834,14 @@ var require_helpers2 = __commonJS({
|
|
|
49376
52834
|
loc
|
|
49377
52835
|
};
|
|
49378
52836
|
}
|
|
49379
|
-
function preparePartialBlock(open,
|
|
52837
|
+
function preparePartialBlock(open, program2, close, locInfo) {
|
|
49380
52838
|
validateClose(open, close);
|
|
49381
52839
|
return {
|
|
49382
52840
|
type: "PartialBlockStatement",
|
|
49383
52841
|
name: open.path,
|
|
49384
52842
|
params: open.params,
|
|
49385
52843
|
hash: open.hash,
|
|
49386
|
-
program,
|
|
52844
|
+
program: program2,
|
|
49387
52845
|
openStrip: open.strip,
|
|
49388
52846
|
closeStrip: close && close.strip,
|
|
49389
52847
|
loc: this.locInfo(locInfo)
|
|
@@ -49534,7 +52992,7 @@ var require_compiler = __commonJS({
|
|
|
49534
52992
|
return true;
|
|
49535
52993
|
},
|
|
49536
52994
|
guid: 0,
|
|
49537
|
-
compile: function compile3(
|
|
52995
|
+
compile: function compile3(program2, options) {
|
|
49538
52996
|
this.sourceNode = [];
|
|
49539
52997
|
this.opcodes = [];
|
|
49540
52998
|
this.children = [];
|
|
@@ -49552,10 +53010,10 @@ var require_compiler = __commonJS({
|
|
|
49552
53010
|
log: true,
|
|
49553
53011
|
lookup: true
|
|
49554
53012
|
}, options.knownHelpers);
|
|
49555
|
-
return this.accept(
|
|
53013
|
+
return this.accept(program2);
|
|
49556
53014
|
},
|
|
49557
|
-
compileProgram: function compileProgram(
|
|
49558
|
-
var childCompiler = new this.compiler(), result = childCompiler.compile(
|
|
53015
|
+
compileProgram: function compileProgram(program2) {
|
|
53016
|
+
var childCompiler = new this.compiler(), result = childCompiler.compile(program2, this.options), guid3 = this.guid++;
|
|
49559
53017
|
this.usePartial = this.usePartial || result.usePartial;
|
|
49560
53018
|
this.children[guid3] = result;
|
|
49561
53019
|
this.useDepths = this.useDepths || result.useDepths;
|
|
@@ -49570,34 +53028,34 @@ var require_compiler = __commonJS({
|
|
|
49570
53028
|
this.sourceNode.shift();
|
|
49571
53029
|
return ret;
|
|
49572
53030
|
},
|
|
49573
|
-
Program: function Program(
|
|
49574
|
-
this.options.blockParams.unshift(
|
|
49575
|
-
var body =
|
|
53031
|
+
Program: function Program(program2) {
|
|
53032
|
+
this.options.blockParams.unshift(program2.blockParams);
|
|
53033
|
+
var body = program2.body, bodyLength = body.length;
|
|
49576
53034
|
for (var i = 0; i < bodyLength; i++) {
|
|
49577
53035
|
this.accept(body[i]);
|
|
49578
53036
|
}
|
|
49579
53037
|
this.options.blockParams.shift();
|
|
49580
53038
|
this.isSimple = bodyLength === 1;
|
|
49581
|
-
this.blockParams =
|
|
53039
|
+
this.blockParams = program2.blockParams ? program2.blockParams.length : 0;
|
|
49582
53040
|
return this;
|
|
49583
53041
|
},
|
|
49584
53042
|
BlockStatement: function BlockStatement(block) {
|
|
49585
53043
|
transformLiteralToPath(block);
|
|
49586
|
-
var
|
|
49587
|
-
|
|
53044
|
+
var program2 = block.program, inverse = block.inverse;
|
|
53045
|
+
program2 = program2 && this.compileProgram(program2);
|
|
49588
53046
|
inverse = inverse && this.compileProgram(inverse);
|
|
49589
53047
|
var type2 = this.classifySexpr(block);
|
|
49590
53048
|
if (type2 === "helper") {
|
|
49591
|
-
this.helperSexpr(block,
|
|
53049
|
+
this.helperSexpr(block, program2, inverse);
|
|
49592
53050
|
} else if (type2 === "simple") {
|
|
49593
53051
|
this.simpleSexpr(block);
|
|
49594
|
-
this.opcode("pushProgram",
|
|
53052
|
+
this.opcode("pushProgram", program2);
|
|
49595
53053
|
this.opcode("pushProgram", inverse);
|
|
49596
53054
|
this.opcode("emptyHash");
|
|
49597
53055
|
this.opcode("blockValue", block.path.original);
|
|
49598
53056
|
} else {
|
|
49599
|
-
this.ambiguousSexpr(block,
|
|
49600
|
-
this.opcode("pushProgram",
|
|
53057
|
+
this.ambiguousSexpr(block, program2, inverse);
|
|
53058
|
+
this.opcode("pushProgram", program2);
|
|
49601
53059
|
this.opcode("pushProgram", inverse);
|
|
49602
53060
|
this.opcode("emptyHash");
|
|
49603
53061
|
this.opcode("ambiguousBlockValue");
|
|
@@ -49605,16 +53063,16 @@ var require_compiler = __commonJS({
|
|
|
49605
53063
|
this.opcode("append");
|
|
49606
53064
|
},
|
|
49607
53065
|
DecoratorBlock: function DecoratorBlock(decorator) {
|
|
49608
|
-
var
|
|
49609
|
-
var params = this.setupFullMustacheParams(decorator,
|
|
53066
|
+
var program2 = decorator.program && this.compileProgram(decorator.program);
|
|
53067
|
+
var params = this.setupFullMustacheParams(decorator, program2, void 0), path18 = decorator.path;
|
|
49610
53068
|
this.useDecorators = true;
|
|
49611
53069
|
this.opcode("registerDecorator", params.length, path18.original);
|
|
49612
53070
|
},
|
|
49613
53071
|
PartialStatement: function PartialStatement(partial2) {
|
|
49614
53072
|
this.usePartial = true;
|
|
49615
|
-
var
|
|
49616
|
-
if (
|
|
49617
|
-
|
|
53073
|
+
var program2 = partial2.program;
|
|
53074
|
+
if (program2) {
|
|
53075
|
+
program2 = this.compileProgram(partial2.program);
|
|
49618
53076
|
}
|
|
49619
53077
|
var params = partial2.params;
|
|
49620
53078
|
if (params.length > 1) {
|
|
@@ -49630,7 +53088,7 @@ var require_compiler = __commonJS({
|
|
|
49630
53088
|
if (isDynamic) {
|
|
49631
53089
|
this.accept(partial2.name);
|
|
49632
53090
|
}
|
|
49633
|
-
this.setupFullMustacheParams(partial2,
|
|
53091
|
+
this.setupFullMustacheParams(partial2, program2, void 0, true);
|
|
49634
53092
|
var indent = partial2.indent || "";
|
|
49635
53093
|
if (this.options.preventIndent && indent) {
|
|
49636
53094
|
this.opcode("appendContent", indent);
|
|
@@ -49671,10 +53129,10 @@ var require_compiler = __commonJS({
|
|
|
49671
53129
|
this.ambiguousSexpr(sexpr);
|
|
49672
53130
|
}
|
|
49673
53131
|
},
|
|
49674
|
-
ambiguousSexpr: function ambiguousSexpr(sexpr,
|
|
49675
|
-
var path18 = sexpr.path, name = path18.parts[0], isBlock =
|
|
53132
|
+
ambiguousSexpr: function ambiguousSexpr(sexpr, program2, inverse) {
|
|
53133
|
+
var path18 = sexpr.path, name = path18.parts[0], isBlock = program2 != null || inverse != null;
|
|
49676
53134
|
this.opcode("getContext", path18.depth);
|
|
49677
|
-
this.opcode("pushProgram",
|
|
53135
|
+
this.opcode("pushProgram", program2);
|
|
49678
53136
|
this.opcode("pushProgram", inverse);
|
|
49679
53137
|
path18.strict = true;
|
|
49680
53138
|
this.accept(path18);
|
|
@@ -49686,8 +53144,8 @@ var require_compiler = __commonJS({
|
|
|
49686
53144
|
this.accept(path18);
|
|
49687
53145
|
this.opcode("resolvePossibleLambda");
|
|
49688
53146
|
},
|
|
49689
|
-
helperSexpr: function helperSexpr(sexpr,
|
|
49690
|
-
var params = this.setupFullMustacheParams(sexpr,
|
|
53147
|
+
helperSexpr: function helperSexpr(sexpr, program2, inverse) {
|
|
53148
|
+
var params = this.setupFullMustacheParams(sexpr, program2, inverse), path18 = sexpr.path, name = path18.parts[0];
|
|
49691
53149
|
if (this.options.knownHelpers[name]) {
|
|
49692
53150
|
this.opcode("invokeKnownHelper", params.length, name);
|
|
49693
53151
|
} else if (this.options.knownHelpersOnly) {
|
|
@@ -49814,10 +53272,10 @@ var require_compiler = __commonJS({
|
|
|
49814
53272
|
this.accept(val);
|
|
49815
53273
|
}
|
|
49816
53274
|
},
|
|
49817
|
-
setupFullMustacheParams: function setupFullMustacheParams(sexpr,
|
|
53275
|
+
setupFullMustacheParams: function setupFullMustacheParams(sexpr, program2, inverse, omitEmpty) {
|
|
49818
53276
|
var params = sexpr.params;
|
|
49819
53277
|
this.pushParams(params);
|
|
49820
|
-
this.opcode("pushProgram",
|
|
53278
|
+
this.opcode("pushProgram", program2);
|
|
49821
53279
|
this.opcode("pushProgram", inverse);
|
|
49822
53280
|
if (sexpr.hash) {
|
|
49823
53281
|
this.accept(sexpr.hash);
|
|
@@ -52647,9 +56105,9 @@ var require_javascript_compiler = __commonJS({
|
|
|
52647
56105
|
options.hashTypes = this.popStack();
|
|
52648
56106
|
options.hashContexts = this.popStack();
|
|
52649
56107
|
}
|
|
52650
|
-
var inverse = this.popStack(),
|
|
52651
|
-
if (
|
|
52652
|
-
options.fn =
|
|
56108
|
+
var inverse = this.popStack(), program2 = this.popStack();
|
|
56109
|
+
if (program2 || inverse) {
|
|
56110
|
+
options.fn = program2 || "container.noop";
|
|
52653
56111
|
options.inverse = inverse || "container.noop";
|
|
52654
56112
|
}
|
|
52655
56113
|
var i = paramSize;
|
|
@@ -52801,12 +56259,12 @@ var require_printer = __commonJS({
|
|
|
52801
56259
|
out += string4 + "\n";
|
|
52802
56260
|
return out;
|
|
52803
56261
|
};
|
|
52804
|
-
PrintVisitor.prototype.Program = function(
|
|
52805
|
-
var out = "", body =
|
|
52806
|
-
if (
|
|
56262
|
+
PrintVisitor.prototype.Program = function(program2) {
|
|
56263
|
+
var out = "", body = program2.body, i = void 0, l = void 0;
|
|
56264
|
+
if (program2.blockParams) {
|
|
52807
56265
|
var blockParams = "BLOCK PARAMS: [";
|
|
52808
|
-
for (i = 0, l =
|
|
52809
|
-
blockParams += " " +
|
|
56266
|
+
for (i = 0, l = program2.blockParams.length; i < l; i++) {
|
|
56267
|
+
blockParams += " " + program2.blockParams[i];
|
|
52810
56268
|
}
|
|
52811
56269
|
blockParams += " ]";
|
|
52812
56270
|
out += this.pad(blockParams);
|
|
@@ -57750,7 +61208,6 @@ import * as fs83 from "fs";
|
|
|
57750
61208
|
import * as path62 from "path";
|
|
57751
61209
|
import * as fs102 from "fs";
|
|
57752
61210
|
import * as readline from "readline";
|
|
57753
|
-
import { Command as Command2 } from "commander";
|
|
57754
61211
|
function parseJsonc3(content) {
|
|
57755
61212
|
if (content.length > MAX_JSONC_LENGTH3) {
|
|
57756
61213
|
throw new Error(`JSONC content too long: ${content.length} characters (max ${MAX_JSONC_LENGTH3})`);
|
|
@@ -58873,7 +62330,7 @@ async function writeMonorepoFiles(contexts, config2, dryRun, fileName) {
|
|
|
58873
62330
|
return monoFiles;
|
|
58874
62331
|
}
|
|
58875
62332
|
function createNotesCommand() {
|
|
58876
|
-
const cmd = new
|
|
62333
|
+
const cmd = new Command("notes").description(
|
|
58877
62334
|
"Generate changelogs with LLM-powered enhancement and flexible templating"
|
|
58878
62335
|
);
|
|
58879
62336
|
cmd.command("generate", { isDefault: true }).description("Generate changelog from input data").option("-i, --input <file>", "Input file (default: stdin)").option("--no-changelog", "Disable changelog generation").option("--changelog-mode <mode>", "Changelog location mode (root|packages|both)").option("--changelog-file <name>", "Changelog file name override").option("--release-notes-mode <mode>", "Enable release notes and set location (root|packages|both)").option("--release-notes-file <name>", "Release notes file name override").option("--no-release-notes", "Disable release notes generation").option("-t, --template <path>", "Template file or directory").option("-e, --engine <engine>", "Template engine (handlebars|liquid|ejs)").option("--monorepo <mode>", "Monorepo mode (root|packages|both)").option("--llm-provider <provider>", "LLM provider").option("--llm-model <model>", "LLM model").option("--llm-base-url <url>", "LLM base URL (for openai-compatible provider)").option("--llm-tasks <tasks>", "Comma-separated LLM tasks").option("--no-llm", "Disable LLM processing").option("--target <package>", "Filter to a specific package name").option("--config <path>", "Config file path").option("--regenerate", "Regenerate entire changelog instead of prepending new entries").option("--dry-run", "Preview without writing").option("-v, --verbose", "Increase verbosity", increaseVerbosity, 0).option("-q, --quiet", "Suppress non-error output").action(async (options) => {
|
|
@@ -59074,6 +62531,7 @@ var init_chunk_Y4S5UWCL = __esm({
|
|
|
59074
62531
|
init_ejs();
|
|
59075
62532
|
import_handlebars = __toESM(require_lib(), 1);
|
|
59076
62533
|
init_liquid_node();
|
|
62534
|
+
init_esm();
|
|
59077
62535
|
ConfigError3 = class extends ReleaseKitError3 {
|
|
59078
62536
|
code = "CONFIG_ERROR";
|
|
59079
62537
|
suggestions;
|
|
@@ -59757,7 +63215,6 @@ import * as path74 from "path";
|
|
|
59757
63215
|
import * as fs94 from "fs";
|
|
59758
63216
|
import * as path93 from "path";
|
|
59759
63217
|
import * as fs103 from "fs";
|
|
59760
|
-
import { Command as Command3 } from "commander";
|
|
59761
63218
|
function setLogLevel3(level) {
|
|
59762
63219
|
currentLevel4 = level;
|
|
59763
63220
|
}
|
|
@@ -61215,7 +64672,7 @@ async function readStdin2() {
|
|
|
61215
64672
|
return chunks.join("");
|
|
61216
64673
|
}
|
|
61217
64674
|
function createPublishCommand() {
|
|
61218
|
-
return new
|
|
64675
|
+
return new Command("publish").description("Publish packages to registries with git tagging and GitHub releases").option("--input <path>", "Path to version output JSON (default: stdin)").option("--config <path>", "Path to releasekit config").option("--registry <type>", "Registry to publish to (npm, cargo, all)", "all").option("--npm-auth <method>", "NPM auth method (oidc, token, auto)", "auto").option("--dry-run", "Simulate all operations", false).option("--skip-git", "Skip git commit/tag/push", false).option("--skip-publish", "Skip registry publishing", false).option("--skip-github-release", "Skip GitHub Release creation", false).option("--skip-verification", "Skip post-publish verification", false).option("--json", "Output results as JSON", false).option("--verbose", "Verbose logging", false).action(async (options) => {
|
|
61219
64676
|
if (options.verbose) setLogLevel3("debug");
|
|
61220
64677
|
if (options.json) setJsonMode2(true);
|
|
61221
64678
|
try {
|
|
@@ -61276,6 +64733,7 @@ var init_chunk_OZHNJUFW = __esm({
|
|
|
61276
64733
|
init_dist();
|
|
61277
64734
|
import_semver6 = __toESM(require_semver2(), 1);
|
|
61278
64735
|
init_zod();
|
|
64736
|
+
init_esm();
|
|
61279
64737
|
LOG_LEVELS4 = {
|
|
61280
64738
|
error: 0,
|
|
61281
64739
|
warn: 1,
|
|
@@ -61843,10 +65301,10 @@ var EXIT_CODES = {
|
|
|
61843
65301
|
};
|
|
61844
65302
|
|
|
61845
65303
|
// src/cli.ts
|
|
61846
|
-
|
|
65304
|
+
init_esm();
|
|
61847
65305
|
|
|
61848
65306
|
// src/preview-command.ts
|
|
61849
|
-
|
|
65307
|
+
init_esm();
|
|
61850
65308
|
|
|
61851
65309
|
// ../config/dist/index.js
|
|
61852
65310
|
init_dist();
|
|
@@ -62822,7 +66280,7 @@ async function applyLabelOverrides(options, ciConfig, context, existingOctokit)
|
|
|
62822
66280
|
|
|
62823
66281
|
// src/preview-command.ts
|
|
62824
66282
|
function createPreviewCommand() {
|
|
62825
|
-
return new
|
|
66283
|
+
return new Command("preview").description("Post a release preview comment on the current pull request").option("-c, --config <path>", "Path to config file").option("--project-dir <path>", "Project directory", process.cwd()).option("--pr <number>", "PR number (auto-detected from GitHub Actions)").option("--repo <owner/repo>", "Repository (auto-detected from GITHUB_REPOSITORY)").option("-p, --prerelease [identifier]", "Force prerelease preview (auto-detected by default)").option("--stable", "Force stable release preview (graduation from prerelease)", false).option(
|
|
62826
66284
|
"-d, --dry-run",
|
|
62827
66285
|
"Print the comment to stdout without posting (GitHub context not available in dry-run mode)",
|
|
62828
66286
|
false
|
|
@@ -62845,9 +66303,9 @@ function createPreviewCommand() {
|
|
|
62845
66303
|
}
|
|
62846
66304
|
|
|
62847
66305
|
// src/release-command.ts
|
|
62848
|
-
|
|
66306
|
+
init_esm();
|
|
62849
66307
|
function createReleaseCommand() {
|
|
62850
|
-
return new
|
|
66308
|
+
return new Command("release").description("Run the full release pipeline").option("-c, --config <path>", "Path to config file").option("-d, --dry-run", "Preview all steps without side effects", false).option("-b, --bump <type>", "Force bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --sync", "Use synchronized versioning across all packages", false).option("-t, --target <packages>", "Target specific packages (comma-separated)").option("--branch <name>", "Override the git branch used for push").addOption(new Option("--npm-auth <method>", "NPM auth method").choices(["auto", "oidc", "token"]).default("auto")).option("--skip-notes", "Skip changelog generation", false).option("--skip-publish", "Skip registry publishing and git operations", false).option("--skip-git", "Skip git commit/tag/push", false).option("--skip-github-release", "Skip GitHub release creation", false).option("--skip-verification", "Skip post-publish verification", false).option("-j, --json", "Output results as JSON", false).option("-v, --verbose", "Verbose logging", false).option("-q, --quiet", "Suppress non-error output", false).option("--project-dir <path>", "Project directory", process.cwd()).action(async (opts) => {
|
|
62851
66309
|
const options = {
|
|
62852
66310
|
config: opts.config,
|
|
62853
66311
|
dryRun: opts.dryRun,
|
|
@@ -62884,7 +66342,7 @@ function createReleaseCommand() {
|
|
|
62884
66342
|
|
|
62885
66343
|
// src/cli.ts
|
|
62886
66344
|
function createReleaseProgram() {
|
|
62887
|
-
return new
|
|
66345
|
+
return new Command().name("releasekit-release").description("Unified release pipeline: version, changelog, and publish").version(readPackageVersion(import.meta.url)).addCommand(createReleaseCommand(), { isDefault: true }).addCommand(createPreviewCommand());
|
|
62888
66346
|
}
|
|
62889
66347
|
var isMain = (() => {
|
|
62890
66348
|
try {
|