sniff-qa 0.9.0 → 0.9.1

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.
Files changed (172) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +39 -0
  3. package/NOTICE +7 -4
  4. package/README.md +35 -7
  5. package/THIRD-PARTY-NOTICES.md +1800 -0
  6. package/dist/{accessibility-JXRMWF5Y.js → accessibility-42JOUOGH.js} +8 -2
  7. package/dist/{anthropic-api-7PHYF6PN.js → anthropic-api-VSG2X6FS.js} +7 -5
  8. package/dist/assert-budget-WG4BRCLX.js +10 -0
  9. package/dist/{caps-G3ZGJI7B.js → caps-YZPFNPIN.js} +3 -2
  10. package/dist/{chunk-VEI2O6AK.js → chunk-33JL2AB5.js} +14 -6
  11. package/dist/{chunk-64FUDSRY.js → chunk-3E4W4H6S.js} +8 -5
  12. package/dist/{chunk-T72SLMTY.js → chunk-3NR2K5B3.js} +2 -1
  13. package/dist/chunk-3ROWRVZE.js +422 -0
  14. package/dist/{chunk-MYWWSM3V.js → chunk-3YFE3H23.js} +2 -1
  15. package/dist/{chunk-MMISGY2Q.js → chunk-4F6ZXOPE.js} +2 -1
  16. package/dist/chunk-A4TTASVS.js +27862 -0
  17. package/dist/{chunk-IXDUD2UG.js → chunk-AA744N7E.js} +2 -1
  18. package/dist/chunk-DZMX3VT2.js +267 -0
  19. package/dist/{chunk-NG2IGCAK.js → chunk-FR5QCJLH.js} +2 -1
  20. package/dist/{chunk-GV27IOMC.js → chunk-GC47B6MM.js} +2 -1
  21. package/dist/chunk-HP4TY3UY.js +80 -0
  22. package/dist/chunk-LZAPYYNR.js +4595 -0
  23. package/dist/{chunk-ZM6MGWO4.js → chunk-NBJLMLDA.js} +2 -1
  24. package/dist/chunk-RAGYZ54R.js +15480 -0
  25. package/dist/{chunk-GX36BPK7.js → chunk-RSGFFRXQ.js} +2 -2
  26. package/dist/chunk-SOBWDC35.js +38 -0
  27. package/dist/{chunk-7BLJCICM.js → chunk-US4HFUCH.js} +3 -2
  28. package/dist/chunk-YM22FEIA.js +5807 -0
  29. package/dist/{ci-ISCWZJD3.js → ci-F6FUXT3O.js} +5 -3
  30. package/dist/{classifier-MWQMQ727.js → classifier-5FQ2FBTO.js} +3 -1
  31. package/dist/{claude-code-GJPWO6DN.js → claude-code-J43C22IR.js} +7 -5
  32. package/dist/{claude-exploration-provider-XOVJPJ23.js → claude-exploration-provider-EWQNNE7D.js} +3 -2
  33. package/dist/cli/index.js +69 -31
  34. package/dist/compiler-sfc.cjs-JX56AWNS.js +48568 -0
  35. package/dist/crawl-KN7SW753.js +26 -0
  36. package/dist/{crawl-command-JHZN4GK7.js → crawl-command-Y45FIXNK.js} +7 -6
  37. package/dist/{cross-reference-MHNPSLEN.js → cross-reference-XOOBW6UZ.js} +3 -1
  38. package/dist/{dev-server-detector-XQ5AYPDT.js → dev-server-detector-FMFVKDJR.js} +3 -1
  39. package/dist/{discover-QKGMYPHK.js → discover-HA63UA4K.js} +20 -18
  40. package/dist/dist-3CYER35S.js +8 -0
  41. package/dist/{domain-UQ34YE4B.js → domain-FU3WIW64.js} +45 -30
  42. package/dist/{edge-cases-ZADKDZHL.js → edge-cases-B6IV3IKK.js} +3 -1
  43. package/dist/{element-extractor-OZTFBVKZ.js → element-extractor-QAG4MRUO.js} +18 -6
  44. package/dist/engine-AXB5O4ZH.js +39 -0
  45. package/dist/{ensure-browsers-5NAQQMEC.js → ensure-browsers-TNMHMLRS.js} +59 -12
  46. package/dist/errors-NWB25P4K.js +8 -0
  47. package/dist/esm-IMWPYLSN.js +3469 -0
  48. package/dist/{fix-R33D34NP.js → fix-IXOEHAOS.js} +12 -5
  49. package/dist/{flakiness-OLJAY7CS.js → flakiness-7SSSM4SW.js} +3 -2
  50. package/dist/flakiness-CBKV4U54.js +12 -0
  51. package/dist/{formatter-4VI3ZX5Y.js → formatter-N4CC7SCM.js} +29 -22
  52. package/dist/{framework-detector-ISSM2Q2I.js → framework-detector-4ZVHNT7N.js} +3 -1
  53. package/dist/generator-GGJYWYI2.js +8 -0
  54. package/dist/index.js +9 -6
  55. package/dist/{init-IQKT4ANC.js → init-POX5ZJ6V.js} +4 -2
  56. package/dist/json-4VOVHDQG.js +10 -0
  57. package/dist/{junit-GL44ATRR.js → junit-V24COOSR.js} +3 -1
  58. package/dist/{llm-VJAI6H6G.js → llm-TZ2WZGRZ.js} +3 -1
  59. package/dist/{loader-Z2DUGG5Z.js → loader-AMM63AOJ.js} +12 -3
  60. package/dist/mcp/server.js +13035 -72
  61. package/dist/{model-SP6HJN6J.js → model-BL2AID5Q.js} +6 -5
  62. package/dist/page-hooks-SECSGZR6.js +14 -0
  63. package/dist/{page-state-extractor-GYYLYRFR.js → page-state-extractor-AP4FQVLY.js} +3 -1
  64. package/dist/{performance-7HWKY5O2.js → performance-JVEYVBTV.js} +9 -3
  65. package/dist/{persistence-XLFJ5EY4.js → persistence-SHKJVSIS.js} +5 -4
  66. package/dist/{persistence-KTCRIGHU.js → persistence-SQ6QT3HP.js} +3 -1
  67. package/dist/picocolors-3W2AX5TJ.js +6 -0
  68. package/dist/pixelmatch-GATIVDQX.js +188 -0
  69. package/dist/png-HTC2G4ZG.js +2093 -0
  70. package/dist/{prompt-builder-JT3GQBYP.js → prompt-builder-EI2BFKLZ.js} +3 -1
  71. package/dist/{provider-MMQ6EIBV.js → provider-O3UOALQH.js} +14 -12
  72. package/dist/{quality-run-KJMBBAQT.js → quality-run-CTLX5YA5.js} +12 -10
  73. package/dist/{redaction-CHAIVPCF.js → redaction-QNBV5QZ3.js} +4 -3
  74. package/dist/{registry-5XCXUAYJ.js → registry-JBBTSD7I.js} +3 -1
  75. package/dist/{repo-analyzer-4OURSITY.js → repo-analyzer-4XITIIAF.js} +6 -4
  76. package/dist/{report-SDZWX25B.js → report-4UVJL7QV.js} +3 -1
  77. package/dist/{report-XK2MCX2N.js → report-BOVSPRCR.js} +8 -6
  78. package/dist/{response-parser-PUGNWF7S.js → response-parser-GHVJSYXQ.js} +3 -2
  79. package/dist/{route-discoverer-QBZCRQLJ.js → route-discoverer-ZXYJQIYE.js} +15 -8
  80. package/dist/{runner-RDVVIGBU.js → runner-DOLCFA3S.js} +10 -5
  81. package/dist/{runner-QHSYX7J2.js → runner-MCSDHFLN.js} +12 -7
  82. package/dist/{runner-AXZXNWYH.js → runner-MUBXHOIG.js} +10 -4
  83. package/dist/{scenarios-I7YYVTD2.js → scenarios-T2U6ZDRL.js} +3 -1
  84. package/dist/sdk-FQKA5HSQ.js +7184 -0
  85. package/dist/{source-5LS2B7TN.js → source-T5MHBY5G.js} +14 -7
  86. package/dist/{tiebreak-L5UFNKU2.js → tiebreak-SXBXPT7B.js} +3 -1
  87. package/dist/{unified-OEGLPOGE.js → unified-NUR2X5JV.js} +23 -21
  88. package/dist/{update-baselines-JYKUUIZG.js → update-baselines-TMERPIDV.js} +4 -2
  89. package/dist/version-FEHABGAH.js +10 -0
  90. package/dist/{visual-EUZG2STF.js → visual-XHFPFQFX.js} +5 -3
  91. package/dist/{workflow-template-6DADGPHA.js → workflow-template-7C5CCK67.js} +13 -7
  92. package/dist/{write-report-Y4UPVXUO.js → write-report-6Q4MXBYD.js} +5 -4
  93. package/package.json +18 -9
  94. package/dist/accessibility-JXRMWF5Y.js.map +0 -1
  95. package/dist/anthropic-api-7PHYF6PN.js.map +0 -1
  96. package/dist/assert-budget-NBF3JYM7.js +0 -9
  97. package/dist/assert-budget-NBF3JYM7.js.map +0 -1
  98. package/dist/caps-G3ZGJI7B.js.map +0 -1
  99. package/dist/chunk-64FUDSRY.js.map +0 -1
  100. package/dist/chunk-7BLJCICM.js.map +0 -1
  101. package/dist/chunk-GV27IOMC.js.map +0 -1
  102. package/dist/chunk-GX36BPK7.js.map +0 -1
  103. package/dist/chunk-IXDUD2UG.js.map +0 -1
  104. package/dist/chunk-MMISGY2Q.js.map +0 -1
  105. package/dist/chunk-MYWWSM3V.js.map +0 -1
  106. package/dist/chunk-NG2IGCAK.js.map +0 -1
  107. package/dist/chunk-T72SLMTY.js.map +0 -1
  108. package/dist/chunk-VEI2O6AK.js.map +0 -1
  109. package/dist/chunk-ZM6MGWO4.js.map +0 -1
  110. package/dist/ci-ISCWZJD3.js.map +0 -1
  111. package/dist/classifier-MWQMQ727.js.map +0 -1
  112. package/dist/claude-code-GJPWO6DN.js.map +0 -1
  113. package/dist/claude-exploration-provider-XOVJPJ23.js.map +0 -1
  114. package/dist/cli/index.js.map +0 -1
  115. package/dist/crawl-XPHT3KIZ.js +0 -23
  116. package/dist/crawl-XPHT3KIZ.js.map +0 -1
  117. package/dist/crawl-command-JHZN4GK7.js.map +0 -1
  118. package/dist/cross-reference-MHNPSLEN.js.map +0 -1
  119. package/dist/dev-server-detector-XQ5AYPDT.js.map +0 -1
  120. package/dist/discover-QKGMYPHK.js.map +0 -1
  121. package/dist/domain-UQ34YE4B.js.map +0 -1
  122. package/dist/edge-cases-ZADKDZHL.js.map +0 -1
  123. package/dist/element-extractor-OZTFBVKZ.js.map +0 -1
  124. package/dist/ensure-browsers-5NAQQMEC.js.map +0 -1
  125. package/dist/errors-RFEOR527.js +0 -7
  126. package/dist/errors-RFEOR527.js.map +0 -1
  127. package/dist/fix-R33D34NP.js.map +0 -1
  128. package/dist/flakiness-OLJAY7CS.js.map +0 -1
  129. package/dist/flakiness-OVC7KGN2.js +0 -11
  130. package/dist/flakiness-OVC7KGN2.js.map +0 -1
  131. package/dist/formatter-4VI3ZX5Y.js.map +0 -1
  132. package/dist/framework-detector-ISSM2Q2I.js.map +0 -1
  133. package/dist/generator-AFHVMWC3.js +0 -7
  134. package/dist/generator-AFHVMWC3.js.map +0 -1
  135. package/dist/index.js.map +0 -1
  136. package/dist/init-IQKT4ANC.js.map +0 -1
  137. package/dist/json-YDWEB33Q.js +0 -8
  138. package/dist/json-YDWEB33Q.js.map +0 -1
  139. package/dist/junit-GL44ATRR.js.map +0 -1
  140. package/dist/llm-VJAI6H6G.js.map +0 -1
  141. package/dist/loader-Z2DUGG5Z.js.map +0 -1
  142. package/dist/mcp/server.js.map +0 -1
  143. package/dist/model-SP6HJN6J.js.map +0 -1
  144. package/dist/page-hooks-6RALVZB5.js +0 -13
  145. package/dist/page-hooks-6RALVZB5.js.map +0 -1
  146. package/dist/page-state-extractor-GYYLYRFR.js.map +0 -1
  147. package/dist/performance-7HWKY5O2.js.map +0 -1
  148. package/dist/persistence-KTCRIGHU.js.map +0 -1
  149. package/dist/persistence-XLFJ5EY4.js.map +0 -1
  150. package/dist/prompt-builder-JT3GQBYP.js.map +0 -1
  151. package/dist/provider-MMQ6EIBV.js.map +0 -1
  152. package/dist/quality-run-KJMBBAQT.js.map +0 -1
  153. package/dist/redaction-CHAIVPCF.js.map +0 -1
  154. package/dist/registry-5XCXUAYJ.js.map +0 -1
  155. package/dist/repo-analyzer-4OURSITY.js.map +0 -1
  156. package/dist/report-SDZWX25B.js.map +0 -1
  157. package/dist/report-XK2MCX2N.js.map +0 -1
  158. package/dist/response-parser-PUGNWF7S.js.map +0 -1
  159. package/dist/route-discoverer-QBZCRQLJ.js.map +0 -1
  160. package/dist/runner-AXZXNWYH.js.map +0 -1
  161. package/dist/runner-QHSYX7J2.js.map +0 -1
  162. package/dist/runner-RDVVIGBU.js.map +0 -1
  163. package/dist/scenarios-I7YYVTD2.js.map +0 -1
  164. package/dist/source-5LS2B7TN.js.map +0 -1
  165. package/dist/tiebreak-L5UFNKU2.js.map +0 -1
  166. package/dist/unified-OEGLPOGE.js.map +0 -1
  167. package/dist/update-baselines-JYKUUIZG.js.map +0 -1
  168. package/dist/version-FLE7ZHDX.js +0 -7
  169. package/dist/version-FLE7ZHDX.js.map +0 -1
  170. package/dist/visual-EUZG2STF.js.map +0 -1
  171. package/dist/workflow-template-6DADGPHA.js.map +0 -1
  172. package/dist/write-report-Y4UPVXUO.js.map +0 -1
@@ -0,0 +1,3469 @@
1
+ import { createRequire as __sniffCreateRequire } from 'node:module'; const require = __sniffCreateRequire(import.meta.url);
2
+ import {
3
+ __commonJS,
4
+ __require,
5
+ __toESM
6
+ } from "./chunk-SOBWDC35.js";
7
+
8
+ // node_modules/commander/lib/error.js
9
+ var require_error = __commonJS({
10
+ "node_modules/commander/lib/error.js"(exports) {
11
+ "use strict";
12
+ var CommanderError2 = class extends Error {
13
+ /**
14
+ * Constructs the CommanderError class
15
+ * @param {number} exitCode suggested exit code which could be used with process.exit
16
+ * @param {string} code an id string representing the error
17
+ * @param {string} message human-readable description of the error
18
+ */
19
+ constructor(exitCode, code, message) {
20
+ super(message);
21
+ Error.captureStackTrace(this, this.constructor);
22
+ this.name = this.constructor.name;
23
+ this.code = code;
24
+ this.exitCode = exitCode;
25
+ this.nestedError = void 0;
26
+ }
27
+ };
28
+ var InvalidArgumentError2 = class extends CommanderError2 {
29
+ /**
30
+ * Constructs the InvalidArgumentError class
31
+ * @param {string} [message] explanation of why argument is invalid
32
+ */
33
+ constructor(message) {
34
+ super(1, "commander.invalidArgument", message);
35
+ Error.captureStackTrace(this, this.constructor);
36
+ this.name = this.constructor.name;
37
+ }
38
+ };
39
+ exports.CommanderError = CommanderError2;
40
+ exports.InvalidArgumentError = InvalidArgumentError2;
41
+ }
42
+ });
43
+
44
+ // node_modules/commander/lib/argument.js
45
+ var require_argument = __commonJS({
46
+ "node_modules/commander/lib/argument.js"(exports) {
47
+ "use strict";
48
+ var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
49
+ var Argument2 = class {
50
+ /**
51
+ * Initialize a new command argument with the given name and description.
52
+ * The default is that the argument is required, and you can explicitly
53
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
54
+ *
55
+ * @param {string} name
56
+ * @param {string} [description]
57
+ */
58
+ constructor(name, description) {
59
+ this.description = description || "";
60
+ this.variadic = false;
61
+ this.parseArg = void 0;
62
+ this.defaultValue = void 0;
63
+ this.defaultValueDescription = void 0;
64
+ this.argChoices = void 0;
65
+ switch (name[0]) {
66
+ case "<":
67
+ this.required = true;
68
+ this._name = name.slice(1, -1);
69
+ break;
70
+ case "[":
71
+ this.required = false;
72
+ this._name = name.slice(1, -1);
73
+ break;
74
+ default:
75
+ this.required = true;
76
+ this._name = name;
77
+ break;
78
+ }
79
+ if (this._name.endsWith("...")) {
80
+ this.variadic = true;
81
+ this._name = this._name.slice(0, -3);
82
+ }
83
+ }
84
+ /**
85
+ * Return argument name.
86
+ *
87
+ * @return {string}
88
+ */
89
+ name() {
90
+ return this._name;
91
+ }
92
+ /**
93
+ * @package
94
+ */
95
+ _collectValue(value, previous) {
96
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
97
+ return [value];
98
+ }
99
+ previous.push(value);
100
+ return previous;
101
+ }
102
+ /**
103
+ * Set the default value, and optionally supply the description to be displayed in the help.
104
+ *
105
+ * @param {*} value
106
+ * @param {string} [description]
107
+ * @return {Argument}
108
+ */
109
+ default(value, description) {
110
+ this.defaultValue = value;
111
+ this.defaultValueDescription = description;
112
+ return this;
113
+ }
114
+ /**
115
+ * Set the custom handler for processing CLI command arguments into argument values.
116
+ *
117
+ * @param {Function} [fn]
118
+ * @return {Argument}
119
+ */
120
+ argParser(fn) {
121
+ this.parseArg = fn;
122
+ return this;
123
+ }
124
+ /**
125
+ * Only allow argument value to be one of choices.
126
+ *
127
+ * @param {string[]} values
128
+ * @return {Argument}
129
+ */
130
+ choices(values) {
131
+ this.argChoices = values.slice();
132
+ this.parseArg = (arg, previous) => {
133
+ if (!this.argChoices.includes(arg)) {
134
+ throw new InvalidArgumentError2(
135
+ `Allowed choices are ${this.argChoices.join(", ")}.`
136
+ );
137
+ }
138
+ if (this.variadic) {
139
+ return this._collectValue(arg, previous);
140
+ }
141
+ return arg;
142
+ };
143
+ return this;
144
+ }
145
+ /**
146
+ * Make argument required.
147
+ *
148
+ * @returns {Argument}
149
+ */
150
+ argRequired() {
151
+ this.required = true;
152
+ return this;
153
+ }
154
+ /**
155
+ * Make argument optional.
156
+ *
157
+ * @returns {Argument}
158
+ */
159
+ argOptional() {
160
+ this.required = false;
161
+ return this;
162
+ }
163
+ };
164
+ function humanReadableArgName(arg) {
165
+ const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
166
+ return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
167
+ }
168
+ exports.Argument = Argument2;
169
+ exports.humanReadableArgName = humanReadableArgName;
170
+ }
171
+ });
172
+
173
+ // node_modules/commander/lib/help.js
174
+ var require_help = __commonJS({
175
+ "node_modules/commander/lib/help.js"(exports) {
176
+ "use strict";
177
+ var { humanReadableArgName } = require_argument();
178
+ var Help2 = class {
179
+ constructor() {
180
+ this.helpWidth = void 0;
181
+ this.minWidthToWrap = 40;
182
+ this.sortSubcommands = false;
183
+ this.sortOptions = false;
184
+ this.showGlobalOptions = false;
185
+ }
186
+ /**
187
+ * prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
188
+ * and just before calling `formatHelp()`.
189
+ *
190
+ * Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.
191
+ *
192
+ * @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions
193
+ */
194
+ prepareContext(contextOptions) {
195
+ this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
196
+ }
197
+ /**
198
+ * Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
199
+ *
200
+ * @param {Command} cmd
201
+ * @returns {Command[]}
202
+ */
203
+ visibleCommands(cmd) {
204
+ const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
205
+ const helpCommand = cmd._getHelpCommand();
206
+ if (helpCommand && !helpCommand._hidden) {
207
+ visibleCommands.push(helpCommand);
208
+ }
209
+ if (this.sortSubcommands) {
210
+ visibleCommands.sort((a, b) => {
211
+ return a.name().localeCompare(b.name());
212
+ });
213
+ }
214
+ return visibleCommands;
215
+ }
216
+ /**
217
+ * Compare options for sort.
218
+ *
219
+ * @param {Option} a
220
+ * @param {Option} b
221
+ * @returns {number}
222
+ */
223
+ compareOptions(a, b) {
224
+ const getSortKey = (option) => {
225
+ return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
226
+ };
227
+ return getSortKey(a).localeCompare(getSortKey(b));
228
+ }
229
+ /**
230
+ * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
231
+ *
232
+ * @param {Command} cmd
233
+ * @returns {Option[]}
234
+ */
235
+ visibleOptions(cmd) {
236
+ const visibleOptions = cmd.options.filter((option) => !option.hidden);
237
+ const helpOption = cmd._getHelpOption();
238
+ if (helpOption && !helpOption.hidden) {
239
+ const removeShort = helpOption.short && cmd._findOption(helpOption.short);
240
+ const removeLong = helpOption.long && cmd._findOption(helpOption.long);
241
+ if (!removeShort && !removeLong) {
242
+ visibleOptions.push(helpOption);
243
+ } else if (helpOption.long && !removeLong) {
244
+ visibleOptions.push(
245
+ cmd.createOption(helpOption.long, helpOption.description)
246
+ );
247
+ } else if (helpOption.short && !removeShort) {
248
+ visibleOptions.push(
249
+ cmd.createOption(helpOption.short, helpOption.description)
250
+ );
251
+ }
252
+ }
253
+ if (this.sortOptions) {
254
+ visibleOptions.sort(this.compareOptions);
255
+ }
256
+ return visibleOptions;
257
+ }
258
+ /**
259
+ * Get an array of the visible global options. (Not including help.)
260
+ *
261
+ * @param {Command} cmd
262
+ * @returns {Option[]}
263
+ */
264
+ visibleGlobalOptions(cmd) {
265
+ if (!this.showGlobalOptions) return [];
266
+ const globalOptions = [];
267
+ for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
268
+ const visibleOptions = ancestorCmd.options.filter(
269
+ (option) => !option.hidden
270
+ );
271
+ globalOptions.push(...visibleOptions);
272
+ }
273
+ if (this.sortOptions) {
274
+ globalOptions.sort(this.compareOptions);
275
+ }
276
+ return globalOptions;
277
+ }
278
+ /**
279
+ * Get an array of the arguments if any have a description.
280
+ *
281
+ * @param {Command} cmd
282
+ * @returns {Argument[]}
283
+ */
284
+ visibleArguments(cmd) {
285
+ if (cmd._argsDescription) {
286
+ cmd.registeredArguments.forEach((argument) => {
287
+ argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
288
+ });
289
+ }
290
+ if (cmd.registeredArguments.find((argument) => argument.description)) {
291
+ return cmd.registeredArguments;
292
+ }
293
+ return [];
294
+ }
295
+ /**
296
+ * Get the command term to show in the list of subcommands.
297
+ *
298
+ * @param {Command} cmd
299
+ * @returns {string}
300
+ */
301
+ subcommandTerm(cmd) {
302
+ const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
303
+ return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
304
+ (args ? " " + args : "");
305
+ }
306
+ /**
307
+ * Get the option term to show in the list of options.
308
+ *
309
+ * @param {Option} option
310
+ * @returns {string}
311
+ */
312
+ optionTerm(option) {
313
+ return option.flags;
314
+ }
315
+ /**
316
+ * Get the argument term to show in the list of arguments.
317
+ *
318
+ * @param {Argument} argument
319
+ * @returns {string}
320
+ */
321
+ argumentTerm(argument) {
322
+ return argument.name();
323
+ }
324
+ /**
325
+ * Get the longest command term length.
326
+ *
327
+ * @param {Command} cmd
328
+ * @param {Help} helper
329
+ * @returns {number}
330
+ */
331
+ longestSubcommandTermLength(cmd, helper) {
332
+ return helper.visibleCommands(cmd).reduce((max, command) => {
333
+ return Math.max(
334
+ max,
335
+ this.displayWidth(
336
+ helper.styleSubcommandTerm(helper.subcommandTerm(command))
337
+ )
338
+ );
339
+ }, 0);
340
+ }
341
+ /**
342
+ * Get the longest option term length.
343
+ *
344
+ * @param {Command} cmd
345
+ * @param {Help} helper
346
+ * @returns {number}
347
+ */
348
+ longestOptionTermLength(cmd, helper) {
349
+ return helper.visibleOptions(cmd).reduce((max, option) => {
350
+ return Math.max(
351
+ max,
352
+ this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
353
+ );
354
+ }, 0);
355
+ }
356
+ /**
357
+ * Get the longest global option term length.
358
+ *
359
+ * @param {Command} cmd
360
+ * @param {Help} helper
361
+ * @returns {number}
362
+ */
363
+ longestGlobalOptionTermLength(cmd, helper) {
364
+ return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
365
+ return Math.max(
366
+ max,
367
+ this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
368
+ );
369
+ }, 0);
370
+ }
371
+ /**
372
+ * Get the longest argument term length.
373
+ *
374
+ * @param {Command} cmd
375
+ * @param {Help} helper
376
+ * @returns {number}
377
+ */
378
+ longestArgumentTermLength(cmd, helper) {
379
+ return helper.visibleArguments(cmd).reduce((max, argument) => {
380
+ return Math.max(
381
+ max,
382
+ this.displayWidth(
383
+ helper.styleArgumentTerm(helper.argumentTerm(argument))
384
+ )
385
+ );
386
+ }, 0);
387
+ }
388
+ /**
389
+ * Get the command usage to be displayed at the top of the built-in help.
390
+ *
391
+ * @param {Command} cmd
392
+ * @returns {string}
393
+ */
394
+ commandUsage(cmd) {
395
+ let cmdName = cmd._name;
396
+ if (cmd._aliases[0]) {
397
+ cmdName = cmdName + "|" + cmd._aliases[0];
398
+ }
399
+ let ancestorCmdNames = "";
400
+ for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
401
+ ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
402
+ }
403
+ return ancestorCmdNames + cmdName + " " + cmd.usage();
404
+ }
405
+ /**
406
+ * Get the description for the command.
407
+ *
408
+ * @param {Command} cmd
409
+ * @returns {string}
410
+ */
411
+ commandDescription(cmd) {
412
+ return cmd.description();
413
+ }
414
+ /**
415
+ * Get the subcommand summary to show in the list of subcommands.
416
+ * (Fallback to description for backwards compatibility.)
417
+ *
418
+ * @param {Command} cmd
419
+ * @returns {string}
420
+ */
421
+ subcommandDescription(cmd) {
422
+ return cmd.summary() || cmd.description();
423
+ }
424
+ /**
425
+ * Get the option description to show in the list of options.
426
+ *
427
+ * @param {Option} option
428
+ * @return {string}
429
+ */
430
+ optionDescription(option) {
431
+ const extraInfo = [];
432
+ if (option.argChoices) {
433
+ extraInfo.push(
434
+ // use stringify to match the display of the default value
435
+ `choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
436
+ );
437
+ }
438
+ if (option.defaultValue !== void 0) {
439
+ const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
440
+ if (showDefault) {
441
+ extraInfo.push(
442
+ `default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
443
+ );
444
+ }
445
+ }
446
+ if (option.presetArg !== void 0 && option.optional) {
447
+ extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
448
+ }
449
+ if (option.envVar !== void 0) {
450
+ extraInfo.push(`env: ${option.envVar}`);
451
+ }
452
+ if (extraInfo.length > 0) {
453
+ const extraDescription = `(${extraInfo.join(", ")})`;
454
+ if (option.description) {
455
+ return `${option.description} ${extraDescription}`;
456
+ }
457
+ return extraDescription;
458
+ }
459
+ return option.description;
460
+ }
461
+ /**
462
+ * Get the argument description to show in the list of arguments.
463
+ *
464
+ * @param {Argument} argument
465
+ * @return {string}
466
+ */
467
+ argumentDescription(argument) {
468
+ const extraInfo = [];
469
+ if (argument.argChoices) {
470
+ extraInfo.push(
471
+ // use stringify to match the display of the default value
472
+ `choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
473
+ );
474
+ }
475
+ if (argument.defaultValue !== void 0) {
476
+ extraInfo.push(
477
+ `default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
478
+ );
479
+ }
480
+ if (extraInfo.length > 0) {
481
+ const extraDescription = `(${extraInfo.join(", ")})`;
482
+ if (argument.description) {
483
+ return `${argument.description} ${extraDescription}`;
484
+ }
485
+ return extraDescription;
486
+ }
487
+ return argument.description;
488
+ }
489
+ /**
490
+ * Format a list of items, given a heading and an array of formatted items.
491
+ *
492
+ * @param {string} heading
493
+ * @param {string[]} items
494
+ * @param {Help} helper
495
+ * @returns string[]
496
+ */
497
+ formatItemList(heading, items, helper) {
498
+ if (items.length === 0) return [];
499
+ return [helper.styleTitle(heading), ...items, ""];
500
+ }
501
+ /**
502
+ * Group items by their help group heading.
503
+ *
504
+ * @param {Command[] | Option[]} unsortedItems
505
+ * @param {Command[] | Option[]} visibleItems
506
+ * @param {Function} getGroup
507
+ * @returns {Map<string, Command[] | Option[]>}
508
+ */
509
+ groupItems(unsortedItems, visibleItems, getGroup) {
510
+ const result = /* @__PURE__ */ new Map();
511
+ unsortedItems.forEach((item) => {
512
+ const group = getGroup(item);
513
+ if (!result.has(group)) result.set(group, []);
514
+ });
515
+ visibleItems.forEach((item) => {
516
+ const group = getGroup(item);
517
+ if (!result.has(group)) {
518
+ result.set(group, []);
519
+ }
520
+ result.get(group).push(item);
521
+ });
522
+ return result;
523
+ }
524
+ /**
525
+ * Generate the built-in help text.
526
+ *
527
+ * @param {Command} cmd
528
+ * @param {Help} helper
529
+ * @returns {string}
530
+ */
531
+ formatHelp(cmd, helper) {
532
+ const termWidth = helper.padWidth(cmd, helper);
533
+ const helpWidth = helper.helpWidth ?? 80;
534
+ function callFormatItem(term, description) {
535
+ return helper.formatItem(term, termWidth, description, helper);
536
+ }
537
+ let output = [
538
+ `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
539
+ ""
540
+ ];
541
+ const commandDescription = helper.commandDescription(cmd);
542
+ if (commandDescription.length > 0) {
543
+ output = output.concat([
544
+ helper.boxWrap(
545
+ helper.styleCommandDescription(commandDescription),
546
+ helpWidth
547
+ ),
548
+ ""
549
+ ]);
550
+ }
551
+ const argumentList = helper.visibleArguments(cmd).map((argument) => {
552
+ return callFormatItem(
553
+ helper.styleArgumentTerm(helper.argumentTerm(argument)),
554
+ helper.styleArgumentDescription(helper.argumentDescription(argument))
555
+ );
556
+ });
557
+ output = output.concat(
558
+ this.formatItemList("Arguments:", argumentList, helper)
559
+ );
560
+ const optionGroups = this.groupItems(
561
+ cmd.options,
562
+ helper.visibleOptions(cmd),
563
+ (option) => option.helpGroupHeading ?? "Options:"
564
+ );
565
+ optionGroups.forEach((options, group) => {
566
+ const optionList = options.map((option) => {
567
+ return callFormatItem(
568
+ helper.styleOptionTerm(helper.optionTerm(option)),
569
+ helper.styleOptionDescription(helper.optionDescription(option))
570
+ );
571
+ });
572
+ output = output.concat(this.formatItemList(group, optionList, helper));
573
+ });
574
+ if (helper.showGlobalOptions) {
575
+ const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
576
+ return callFormatItem(
577
+ helper.styleOptionTerm(helper.optionTerm(option)),
578
+ helper.styleOptionDescription(helper.optionDescription(option))
579
+ );
580
+ });
581
+ output = output.concat(
582
+ this.formatItemList("Global Options:", globalOptionList, helper)
583
+ );
584
+ }
585
+ const commandGroups = this.groupItems(
586
+ cmd.commands,
587
+ helper.visibleCommands(cmd),
588
+ (sub) => sub.helpGroup() || "Commands:"
589
+ );
590
+ commandGroups.forEach((commands, group) => {
591
+ const commandList = commands.map((sub) => {
592
+ return callFormatItem(
593
+ helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
594
+ helper.styleSubcommandDescription(helper.subcommandDescription(sub))
595
+ );
596
+ });
597
+ output = output.concat(this.formatItemList(group, commandList, helper));
598
+ });
599
+ return output.join("\n");
600
+ }
601
+ /**
602
+ * Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
603
+ *
604
+ * @param {string} str
605
+ * @returns {number}
606
+ */
607
+ displayWidth(str) {
608
+ return stripColor(str).length;
609
+ }
610
+ /**
611
+ * Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
612
+ *
613
+ * @param {string} str
614
+ * @returns {string}
615
+ */
616
+ styleTitle(str) {
617
+ return str;
618
+ }
619
+ styleUsage(str) {
620
+ return str.split(" ").map((word) => {
621
+ if (word === "[options]") return this.styleOptionText(word);
622
+ if (word === "[command]") return this.styleSubcommandText(word);
623
+ if (word[0] === "[" || word[0] === "<")
624
+ return this.styleArgumentText(word);
625
+ return this.styleCommandText(word);
626
+ }).join(" ");
627
+ }
628
+ styleCommandDescription(str) {
629
+ return this.styleDescriptionText(str);
630
+ }
631
+ styleOptionDescription(str) {
632
+ return this.styleDescriptionText(str);
633
+ }
634
+ styleSubcommandDescription(str) {
635
+ return this.styleDescriptionText(str);
636
+ }
637
+ styleArgumentDescription(str) {
638
+ return this.styleDescriptionText(str);
639
+ }
640
+ styleDescriptionText(str) {
641
+ return str;
642
+ }
643
+ styleOptionTerm(str) {
644
+ return this.styleOptionText(str);
645
+ }
646
+ styleSubcommandTerm(str) {
647
+ return str.split(" ").map((word) => {
648
+ if (word === "[options]") return this.styleOptionText(word);
649
+ if (word[0] === "[" || word[0] === "<")
650
+ return this.styleArgumentText(word);
651
+ return this.styleSubcommandText(word);
652
+ }).join(" ");
653
+ }
654
+ styleArgumentTerm(str) {
655
+ return this.styleArgumentText(str);
656
+ }
657
+ styleOptionText(str) {
658
+ return str;
659
+ }
660
+ styleArgumentText(str) {
661
+ return str;
662
+ }
663
+ styleSubcommandText(str) {
664
+ return str;
665
+ }
666
+ styleCommandText(str) {
667
+ return str;
668
+ }
669
+ /**
670
+ * Calculate the pad width from the maximum term length.
671
+ *
672
+ * @param {Command} cmd
673
+ * @param {Help} helper
674
+ * @returns {number}
675
+ */
676
+ padWidth(cmd, helper) {
677
+ return Math.max(
678
+ helper.longestOptionTermLength(cmd, helper),
679
+ helper.longestGlobalOptionTermLength(cmd, helper),
680
+ helper.longestSubcommandTermLength(cmd, helper),
681
+ helper.longestArgumentTermLength(cmd, helper)
682
+ );
683
+ }
684
+ /**
685
+ * Detect manually wrapped and indented strings by checking for line break followed by whitespace.
686
+ *
687
+ * @param {string} str
688
+ * @returns {boolean}
689
+ */
690
+ preformatted(str) {
691
+ return /\n[^\S\r\n]/.test(str);
692
+ }
693
+ /**
694
+ * Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
695
+ *
696
+ * So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
697
+ * TTT DDD DDDD
698
+ * DD DDD
699
+ *
700
+ * @param {string} term
701
+ * @param {number} termWidth
702
+ * @param {string} description
703
+ * @param {Help} helper
704
+ * @returns {string}
705
+ */
706
+ formatItem(term, termWidth, description, helper) {
707
+ const itemIndent = 2;
708
+ const itemIndentStr = " ".repeat(itemIndent);
709
+ if (!description) return itemIndentStr + term;
710
+ const paddedTerm = term.padEnd(
711
+ termWidth + term.length - helper.displayWidth(term)
712
+ );
713
+ const spacerWidth = 2;
714
+ const helpWidth = this.helpWidth ?? 80;
715
+ const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
716
+ let formattedDescription;
717
+ if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
718
+ formattedDescription = description;
719
+ } else {
720
+ const wrappedDescription = helper.boxWrap(description, remainingWidth);
721
+ formattedDescription = wrappedDescription.replace(
722
+ /\n/g,
723
+ "\n" + " ".repeat(termWidth + spacerWidth)
724
+ );
725
+ }
726
+ return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
727
+ ${itemIndentStr}`);
728
+ }
729
+ /**
730
+ * Wrap a string at whitespace, preserving existing line breaks.
731
+ * Wrapping is skipped if the width is less than `minWidthToWrap`.
732
+ *
733
+ * @param {string} str
734
+ * @param {number} width
735
+ * @returns {string}
736
+ */
737
+ boxWrap(str, width) {
738
+ if (width < this.minWidthToWrap) return str;
739
+ const rawLines = str.split(/\r\n|\n/);
740
+ const chunkPattern = /[\s]*[^\s]+/g;
741
+ const wrappedLines = [];
742
+ rawLines.forEach((line) => {
743
+ const chunks = line.match(chunkPattern);
744
+ if (chunks === null) {
745
+ wrappedLines.push("");
746
+ return;
747
+ }
748
+ let sumChunks = [chunks.shift()];
749
+ let sumWidth = this.displayWidth(sumChunks[0]);
750
+ chunks.forEach((chunk) => {
751
+ const visibleWidth = this.displayWidth(chunk);
752
+ if (sumWidth + visibleWidth <= width) {
753
+ sumChunks.push(chunk);
754
+ sumWidth += visibleWidth;
755
+ return;
756
+ }
757
+ wrappedLines.push(sumChunks.join(""));
758
+ const nextChunk = chunk.trimStart();
759
+ sumChunks = [nextChunk];
760
+ sumWidth = this.displayWidth(nextChunk);
761
+ });
762
+ wrappedLines.push(sumChunks.join(""));
763
+ });
764
+ return wrappedLines.join("\n");
765
+ }
766
+ };
767
+ function stripColor(str) {
768
+ const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
769
+ return str.replace(sgrPattern, "");
770
+ }
771
+ exports.Help = Help2;
772
+ exports.stripColor = stripColor;
773
+ }
774
+ });
775
+
776
+ // node_modules/commander/lib/option.js
777
+ var require_option = __commonJS({
778
+ "node_modules/commander/lib/option.js"(exports) {
779
+ "use strict";
780
+ var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
781
+ var Option2 = class {
782
+ /**
783
+ * Initialize a new `Option` with the given `flags` and `description`.
784
+ *
785
+ * @param {string} flags
786
+ * @param {string} [description]
787
+ */
788
+ constructor(flags, description) {
789
+ this.flags = flags;
790
+ this.description = description || "";
791
+ this.required = flags.includes("<");
792
+ this.optional = flags.includes("[");
793
+ this.variadic = /\w\.\.\.[>\]]$/.test(flags);
794
+ this.mandatory = false;
795
+ const optionFlags = splitOptionFlags(flags);
796
+ this.short = optionFlags.shortFlag;
797
+ this.long = optionFlags.longFlag;
798
+ this.negate = false;
799
+ if (this.long) {
800
+ this.negate = this.long.startsWith("--no-");
801
+ }
802
+ this.defaultValue = void 0;
803
+ this.defaultValueDescription = void 0;
804
+ this.presetArg = void 0;
805
+ this.envVar = void 0;
806
+ this.parseArg = void 0;
807
+ this.hidden = false;
808
+ this.argChoices = void 0;
809
+ this.conflictsWith = [];
810
+ this.implied = void 0;
811
+ this.helpGroupHeading = void 0;
812
+ }
813
+ /**
814
+ * Set the default value, and optionally supply the description to be displayed in the help.
815
+ *
816
+ * @param {*} value
817
+ * @param {string} [description]
818
+ * @return {Option}
819
+ */
820
+ default(value, description) {
821
+ this.defaultValue = value;
822
+ this.defaultValueDescription = description;
823
+ return this;
824
+ }
825
+ /**
826
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
827
+ * The custom processing (parseArg) is called.
828
+ *
829
+ * @example
830
+ * new Option('--color').default('GREYSCALE').preset('RGB');
831
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
832
+ *
833
+ * @param {*} arg
834
+ * @return {Option}
835
+ */
836
+ preset(arg) {
837
+ this.presetArg = arg;
838
+ return this;
839
+ }
840
+ /**
841
+ * Add option name(s) that conflict with this option.
842
+ * An error will be displayed if conflicting options are found during parsing.
843
+ *
844
+ * @example
845
+ * new Option('--rgb').conflicts('cmyk');
846
+ * new Option('--js').conflicts(['ts', 'jsx']);
847
+ *
848
+ * @param {(string | string[])} names
849
+ * @return {Option}
850
+ */
851
+ conflicts(names) {
852
+ this.conflictsWith = this.conflictsWith.concat(names);
853
+ return this;
854
+ }
855
+ /**
856
+ * Specify implied option values for when this option is set and the implied options are not.
857
+ *
858
+ * The custom processing (parseArg) is not called on the implied values.
859
+ *
860
+ * @example
861
+ * program
862
+ * .addOption(new Option('--log', 'write logging information to file'))
863
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
864
+ *
865
+ * @param {object} impliedOptionValues
866
+ * @return {Option}
867
+ */
868
+ implies(impliedOptionValues) {
869
+ let newImplied = impliedOptionValues;
870
+ if (typeof impliedOptionValues === "string") {
871
+ newImplied = { [impliedOptionValues]: true };
872
+ }
873
+ this.implied = Object.assign(this.implied || {}, newImplied);
874
+ return this;
875
+ }
876
+ /**
877
+ * Set environment variable to check for option value.
878
+ *
879
+ * An environment variable is only used if when processed the current option value is
880
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
881
+ *
882
+ * @param {string} name
883
+ * @return {Option}
884
+ */
885
+ env(name) {
886
+ this.envVar = name;
887
+ return this;
888
+ }
889
+ /**
890
+ * Set the custom handler for processing CLI option arguments into option values.
891
+ *
892
+ * @param {Function} [fn]
893
+ * @return {Option}
894
+ */
895
+ argParser(fn) {
896
+ this.parseArg = fn;
897
+ return this;
898
+ }
899
+ /**
900
+ * Whether the option is mandatory and must have a value after parsing.
901
+ *
902
+ * @param {boolean} [mandatory=true]
903
+ * @return {Option}
904
+ */
905
+ makeOptionMandatory(mandatory = true) {
906
+ this.mandatory = !!mandatory;
907
+ return this;
908
+ }
909
+ /**
910
+ * Hide option in help.
911
+ *
912
+ * @param {boolean} [hide=true]
913
+ * @return {Option}
914
+ */
915
+ hideHelp(hide = true) {
916
+ this.hidden = !!hide;
917
+ return this;
918
+ }
919
+ /**
920
+ * @package
921
+ */
922
+ _collectValue(value, previous) {
923
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
924
+ return [value];
925
+ }
926
+ previous.push(value);
927
+ return previous;
928
+ }
929
+ /**
930
+ * Only allow option value to be one of choices.
931
+ *
932
+ * @param {string[]} values
933
+ * @return {Option}
934
+ */
935
+ choices(values) {
936
+ this.argChoices = values.slice();
937
+ this.parseArg = (arg, previous) => {
938
+ if (!this.argChoices.includes(arg)) {
939
+ throw new InvalidArgumentError2(
940
+ `Allowed choices are ${this.argChoices.join(", ")}.`
941
+ );
942
+ }
943
+ if (this.variadic) {
944
+ return this._collectValue(arg, previous);
945
+ }
946
+ return arg;
947
+ };
948
+ return this;
949
+ }
950
+ /**
951
+ * Return option name.
952
+ *
953
+ * @return {string}
954
+ */
955
+ name() {
956
+ if (this.long) {
957
+ return this.long.replace(/^--/, "");
958
+ }
959
+ return this.short.replace(/^-/, "");
960
+ }
961
+ /**
962
+ * Return option name, in a camelcase format that can be used
963
+ * as an object attribute key.
964
+ *
965
+ * @return {string}
966
+ */
967
+ attributeName() {
968
+ if (this.negate) {
969
+ return camelcase(this.name().replace(/^no-/, ""));
970
+ }
971
+ return camelcase(this.name());
972
+ }
973
+ /**
974
+ * Set the help group heading.
975
+ *
976
+ * @param {string} heading
977
+ * @return {Option}
978
+ */
979
+ helpGroup(heading) {
980
+ this.helpGroupHeading = heading;
981
+ return this;
982
+ }
983
+ /**
984
+ * Check if `arg` matches the short or long flag.
985
+ *
986
+ * @param {string} arg
987
+ * @return {boolean}
988
+ * @package
989
+ */
990
+ is(arg) {
991
+ return this.short === arg || this.long === arg;
992
+ }
993
+ /**
994
+ * Return whether a boolean option.
995
+ *
996
+ * Options are one of boolean, negated, required argument, or optional argument.
997
+ *
998
+ * @return {boolean}
999
+ * @package
1000
+ */
1001
+ isBoolean() {
1002
+ return !this.required && !this.optional && !this.negate;
1003
+ }
1004
+ };
1005
+ var DualOptions = class {
1006
+ /**
1007
+ * @param {Option[]} options
1008
+ */
1009
+ constructor(options) {
1010
+ this.positiveOptions = /* @__PURE__ */ new Map();
1011
+ this.negativeOptions = /* @__PURE__ */ new Map();
1012
+ this.dualOptions = /* @__PURE__ */ new Set();
1013
+ options.forEach((option) => {
1014
+ if (option.negate) {
1015
+ this.negativeOptions.set(option.attributeName(), option);
1016
+ } else {
1017
+ this.positiveOptions.set(option.attributeName(), option);
1018
+ }
1019
+ });
1020
+ this.negativeOptions.forEach((value, key) => {
1021
+ if (this.positiveOptions.has(key)) {
1022
+ this.dualOptions.add(key);
1023
+ }
1024
+ });
1025
+ }
1026
+ /**
1027
+ * Did the value come from the option, and not from possible matching dual option?
1028
+ *
1029
+ * @param {*} value
1030
+ * @param {Option} option
1031
+ * @returns {boolean}
1032
+ */
1033
+ valueFromOption(value, option) {
1034
+ const optionKey = option.attributeName();
1035
+ if (!this.dualOptions.has(optionKey)) return true;
1036
+ const preset = this.negativeOptions.get(optionKey).presetArg;
1037
+ const negativeValue = preset !== void 0 ? preset : false;
1038
+ return option.negate === (negativeValue === value);
1039
+ }
1040
+ };
1041
+ function camelcase(str) {
1042
+ return str.split("-").reduce((str2, word) => {
1043
+ return str2 + word[0].toUpperCase() + word.slice(1);
1044
+ });
1045
+ }
1046
+ function splitOptionFlags(flags) {
1047
+ let shortFlag;
1048
+ let longFlag;
1049
+ const shortFlagExp = /^-[^-]$/;
1050
+ const longFlagExp = /^--[^-]/;
1051
+ const flagParts = flags.split(/[ |,]+/).concat("guard");
1052
+ if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
1053
+ if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
1054
+ if (!shortFlag && shortFlagExp.test(flagParts[0]))
1055
+ shortFlag = flagParts.shift();
1056
+ if (!shortFlag && longFlagExp.test(flagParts[0])) {
1057
+ shortFlag = longFlag;
1058
+ longFlag = flagParts.shift();
1059
+ }
1060
+ if (flagParts[0].startsWith("-")) {
1061
+ const unsupportedFlag = flagParts[0];
1062
+ const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
1063
+ if (/^-[^-][^-]/.test(unsupportedFlag))
1064
+ throw new Error(
1065
+ `${baseError}
1066
+ - a short flag is a single dash and a single character
1067
+ - either use a single dash and a single character (for a short flag)
1068
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`
1069
+ );
1070
+ if (shortFlagExp.test(unsupportedFlag))
1071
+ throw new Error(`${baseError}
1072
+ - too many short flags`);
1073
+ if (longFlagExp.test(unsupportedFlag))
1074
+ throw new Error(`${baseError}
1075
+ - too many long flags`);
1076
+ throw new Error(`${baseError}
1077
+ - unrecognised flag format`);
1078
+ }
1079
+ if (shortFlag === void 0 && longFlag === void 0)
1080
+ throw new Error(
1081
+ `option creation failed due to no flags found in '${flags}'.`
1082
+ );
1083
+ return { shortFlag, longFlag };
1084
+ }
1085
+ exports.Option = Option2;
1086
+ exports.DualOptions = DualOptions;
1087
+ }
1088
+ });
1089
+
1090
+ // node_modules/commander/lib/suggestSimilar.js
1091
+ var require_suggestSimilar = __commonJS({
1092
+ "node_modules/commander/lib/suggestSimilar.js"(exports) {
1093
+ "use strict";
1094
+ var maxDistance = 3;
1095
+ function editDistance(a, b) {
1096
+ if (Math.abs(a.length - b.length) > maxDistance)
1097
+ return Math.max(a.length, b.length);
1098
+ const d = [];
1099
+ for (let i = 0; i <= a.length; i++) {
1100
+ d[i] = [i];
1101
+ }
1102
+ for (let j = 0; j <= b.length; j++) {
1103
+ d[0][j] = j;
1104
+ }
1105
+ for (let j = 1; j <= b.length; j++) {
1106
+ for (let i = 1; i <= a.length; i++) {
1107
+ let cost = 1;
1108
+ if (a[i - 1] === b[j - 1]) {
1109
+ cost = 0;
1110
+ } else {
1111
+ cost = 1;
1112
+ }
1113
+ d[i][j] = Math.min(
1114
+ d[i - 1][j] + 1,
1115
+ // deletion
1116
+ d[i][j - 1] + 1,
1117
+ // insertion
1118
+ d[i - 1][j - 1] + cost
1119
+ // substitution
1120
+ );
1121
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
1122
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
1123
+ }
1124
+ }
1125
+ }
1126
+ return d[a.length][b.length];
1127
+ }
1128
+ function suggestSimilar(word, candidates) {
1129
+ if (!candidates || candidates.length === 0) return "";
1130
+ candidates = Array.from(new Set(candidates));
1131
+ const searchingOptions = word.startsWith("--");
1132
+ if (searchingOptions) {
1133
+ word = word.slice(2);
1134
+ candidates = candidates.map((candidate) => candidate.slice(2));
1135
+ }
1136
+ let similar = [];
1137
+ let bestDistance = maxDistance;
1138
+ const minSimilarity = 0.4;
1139
+ candidates.forEach((candidate) => {
1140
+ if (candidate.length <= 1) return;
1141
+ const distance = editDistance(word, candidate);
1142
+ const length = Math.max(word.length, candidate.length);
1143
+ const similarity = (length - distance) / length;
1144
+ if (similarity > minSimilarity) {
1145
+ if (distance < bestDistance) {
1146
+ bestDistance = distance;
1147
+ similar = [candidate];
1148
+ } else if (distance === bestDistance) {
1149
+ similar.push(candidate);
1150
+ }
1151
+ }
1152
+ });
1153
+ similar.sort((a, b) => a.localeCompare(b));
1154
+ if (searchingOptions) {
1155
+ similar = similar.map((candidate) => `--${candidate}`);
1156
+ }
1157
+ if (similar.length > 1) {
1158
+ return `
1159
+ (Did you mean one of ${similar.join(", ")}?)`;
1160
+ }
1161
+ if (similar.length === 1) {
1162
+ return `
1163
+ (Did you mean ${similar[0]}?)`;
1164
+ }
1165
+ return "";
1166
+ }
1167
+ exports.suggestSimilar = suggestSimilar;
1168
+ }
1169
+ });
1170
+
1171
+ // node_modules/commander/lib/command.js
1172
+ var require_command = __commonJS({
1173
+ "node_modules/commander/lib/command.js"(exports) {
1174
+ "use strict";
1175
+ var EventEmitter = __require("events").EventEmitter;
1176
+ var childProcess = __require("child_process");
1177
+ var path = __require("path");
1178
+ var fs = __require("fs");
1179
+ var process = __require("process");
1180
+ var { Argument: Argument2, humanReadableArgName } = require_argument();
1181
+ var { CommanderError: CommanderError2 } = require_error();
1182
+ var { Help: Help2, stripColor } = require_help();
1183
+ var { Option: Option2, DualOptions } = require_option();
1184
+ var { suggestSimilar } = require_suggestSimilar();
1185
+ var Command2 = class _Command extends EventEmitter {
1186
+ /**
1187
+ * Initialize a new `Command`.
1188
+ *
1189
+ * @param {string} [name]
1190
+ */
1191
+ constructor(name) {
1192
+ super();
1193
+ this.commands = [];
1194
+ this.options = [];
1195
+ this.parent = null;
1196
+ this._allowUnknownOption = false;
1197
+ this._allowExcessArguments = false;
1198
+ this.registeredArguments = [];
1199
+ this._args = this.registeredArguments;
1200
+ this.args = [];
1201
+ this.rawArgs = [];
1202
+ this.processedArgs = [];
1203
+ this._scriptPath = null;
1204
+ this._name = name || "";
1205
+ this._optionValues = {};
1206
+ this._optionValueSources = {};
1207
+ this._storeOptionsAsProperties = false;
1208
+ this._actionHandler = null;
1209
+ this._executableHandler = false;
1210
+ this._executableFile = null;
1211
+ this._executableDir = null;
1212
+ this._defaultCommandName = null;
1213
+ this._exitCallback = null;
1214
+ this._aliases = [];
1215
+ this._combineFlagAndOptionalValue = true;
1216
+ this._description = "";
1217
+ this._summary = "";
1218
+ this._argsDescription = void 0;
1219
+ this._enablePositionalOptions = false;
1220
+ this._passThroughOptions = false;
1221
+ this._lifeCycleHooks = {};
1222
+ this._showHelpAfterError = false;
1223
+ this._showSuggestionAfterError = true;
1224
+ this._savedState = null;
1225
+ this._outputConfiguration = {
1226
+ writeOut: (str) => process.stdout.write(str),
1227
+ writeErr: (str) => process.stderr.write(str),
1228
+ outputError: (str, write) => write(str),
1229
+ getOutHelpWidth: () => process.stdout.isTTY ? process.stdout.columns : void 0,
1230
+ getErrHelpWidth: () => process.stderr.isTTY ? process.stderr.columns : void 0,
1231
+ getOutHasColors: () => useColor() ?? (process.stdout.isTTY && process.stdout.hasColors?.()),
1232
+ getErrHasColors: () => useColor() ?? (process.stderr.isTTY && process.stderr.hasColors?.()),
1233
+ stripColor: (str) => stripColor(str)
1234
+ };
1235
+ this._hidden = false;
1236
+ this._helpOption = void 0;
1237
+ this._addImplicitHelpCommand = void 0;
1238
+ this._helpCommand = void 0;
1239
+ this._helpConfiguration = {};
1240
+ this._helpGroupHeading = void 0;
1241
+ this._defaultCommandGroup = void 0;
1242
+ this._defaultOptionGroup = void 0;
1243
+ }
1244
+ /**
1245
+ * Copy settings that are useful to have in common across root command and subcommands.
1246
+ *
1247
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
1248
+ *
1249
+ * @param {Command} sourceCommand
1250
+ * @return {Command} `this` command for chaining
1251
+ */
1252
+ copyInheritedSettings(sourceCommand) {
1253
+ this._outputConfiguration = sourceCommand._outputConfiguration;
1254
+ this._helpOption = sourceCommand._helpOption;
1255
+ this._helpCommand = sourceCommand._helpCommand;
1256
+ this._helpConfiguration = sourceCommand._helpConfiguration;
1257
+ this._exitCallback = sourceCommand._exitCallback;
1258
+ this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
1259
+ this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
1260
+ this._allowExcessArguments = sourceCommand._allowExcessArguments;
1261
+ this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
1262
+ this._showHelpAfterError = sourceCommand._showHelpAfterError;
1263
+ this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
1264
+ return this;
1265
+ }
1266
+ /**
1267
+ * @returns {Command[]}
1268
+ * @private
1269
+ */
1270
+ _getCommandAndAncestors() {
1271
+ const result = [];
1272
+ for (let command = this; command; command = command.parent) {
1273
+ result.push(command);
1274
+ }
1275
+ return result;
1276
+ }
1277
+ /**
1278
+ * Define a command.
1279
+ *
1280
+ * There are two styles of command: pay attention to where to put the description.
1281
+ *
1282
+ * @example
1283
+ * // Command implemented using action handler (description is supplied separately to `.command`)
1284
+ * program
1285
+ * .command('clone <source> [destination]')
1286
+ * .description('clone a repository into a newly created directory')
1287
+ * .action((source, destination) => {
1288
+ * console.log('clone command called');
1289
+ * });
1290
+ *
1291
+ * // Command implemented using separate executable file (description is second parameter to `.command`)
1292
+ * program
1293
+ * .command('start <service>', 'start named service')
1294
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
1295
+ *
1296
+ * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
1297
+ * @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
1298
+ * @param {object} [execOpts] - configuration options (for executable)
1299
+ * @return {Command} returns new command for action handler, or `this` for executable command
1300
+ */
1301
+ command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
1302
+ let desc = actionOptsOrExecDesc;
1303
+ let opts = execOpts;
1304
+ if (typeof desc === "object" && desc !== null) {
1305
+ opts = desc;
1306
+ desc = null;
1307
+ }
1308
+ opts = opts || {};
1309
+ const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
1310
+ const cmd = this.createCommand(name);
1311
+ if (desc) {
1312
+ cmd.description(desc);
1313
+ cmd._executableHandler = true;
1314
+ }
1315
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
1316
+ cmd._hidden = !!(opts.noHelp || opts.hidden);
1317
+ cmd._executableFile = opts.executableFile || null;
1318
+ if (args) cmd.arguments(args);
1319
+ this._registerCommand(cmd);
1320
+ cmd.parent = this;
1321
+ cmd.copyInheritedSettings(this);
1322
+ if (desc) return this;
1323
+ return cmd;
1324
+ }
1325
+ /**
1326
+ * Factory routine to create a new unattached command.
1327
+ *
1328
+ * See .command() for creating an attached subcommand, which uses this routine to
1329
+ * create the command. You can override createCommand to customise subcommands.
1330
+ *
1331
+ * @param {string} [name]
1332
+ * @return {Command} new command
1333
+ */
1334
+ createCommand(name) {
1335
+ return new _Command(name);
1336
+ }
1337
+ /**
1338
+ * You can customise the help with a subclass of Help by overriding createHelp,
1339
+ * or by overriding Help properties using configureHelp().
1340
+ *
1341
+ * @return {Help}
1342
+ */
1343
+ createHelp() {
1344
+ return Object.assign(new Help2(), this.configureHelp());
1345
+ }
1346
+ /**
1347
+ * You can customise the help by overriding Help properties using configureHelp(),
1348
+ * or with a subclass of Help by overriding createHelp().
1349
+ *
1350
+ * @param {object} [configuration] - configuration options
1351
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
1352
+ */
1353
+ configureHelp(configuration) {
1354
+ if (configuration === void 0) return this._helpConfiguration;
1355
+ this._helpConfiguration = configuration;
1356
+ return this;
1357
+ }
1358
+ /**
1359
+ * The default output goes to stdout and stderr. You can customise this for special
1360
+ * applications. You can also customise the display of errors by overriding outputError.
1361
+ *
1362
+ * The configuration properties are all functions:
1363
+ *
1364
+ * // change how output being written, defaults to stdout and stderr
1365
+ * writeOut(str)
1366
+ * writeErr(str)
1367
+ * // change how output being written for errors, defaults to writeErr
1368
+ * outputError(str, write) // used for displaying errors and not used for displaying help
1369
+ * // specify width for wrapping help
1370
+ * getOutHelpWidth()
1371
+ * getErrHelpWidth()
1372
+ * // color support, currently only used with Help
1373
+ * getOutHasColors()
1374
+ * getErrHasColors()
1375
+ * stripColor() // used to remove ANSI escape codes if output does not have colors
1376
+ *
1377
+ * @param {object} [configuration] - configuration options
1378
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
1379
+ */
1380
+ configureOutput(configuration) {
1381
+ if (configuration === void 0) return this._outputConfiguration;
1382
+ this._outputConfiguration = {
1383
+ ...this._outputConfiguration,
1384
+ ...configuration
1385
+ };
1386
+ return this;
1387
+ }
1388
+ /**
1389
+ * Display the help or a custom message after an error occurs.
1390
+ *
1391
+ * @param {(boolean|string)} [displayHelp]
1392
+ * @return {Command} `this` command for chaining
1393
+ */
1394
+ showHelpAfterError(displayHelp = true) {
1395
+ if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
1396
+ this._showHelpAfterError = displayHelp;
1397
+ return this;
1398
+ }
1399
+ /**
1400
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
1401
+ *
1402
+ * @param {boolean} [displaySuggestion]
1403
+ * @return {Command} `this` command for chaining
1404
+ */
1405
+ showSuggestionAfterError(displaySuggestion = true) {
1406
+ this._showSuggestionAfterError = !!displaySuggestion;
1407
+ return this;
1408
+ }
1409
+ /**
1410
+ * Add a prepared subcommand.
1411
+ *
1412
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
1413
+ *
1414
+ * @param {Command} cmd - new subcommand
1415
+ * @param {object} [opts] - configuration options
1416
+ * @return {Command} `this` command for chaining
1417
+ */
1418
+ addCommand(cmd, opts) {
1419
+ if (!cmd._name) {
1420
+ throw new Error(`Command passed to .addCommand() must have a name
1421
+ - specify the name in Command constructor or using .name()`);
1422
+ }
1423
+ opts = opts || {};
1424
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
1425
+ if (opts.noHelp || opts.hidden) cmd._hidden = true;
1426
+ this._registerCommand(cmd);
1427
+ cmd.parent = this;
1428
+ cmd._checkForBrokenPassThrough();
1429
+ return this;
1430
+ }
1431
+ /**
1432
+ * Factory routine to create a new unattached argument.
1433
+ *
1434
+ * See .argument() for creating an attached argument, which uses this routine to
1435
+ * create the argument. You can override createArgument to return a custom argument.
1436
+ *
1437
+ * @param {string} name
1438
+ * @param {string} [description]
1439
+ * @return {Argument} new argument
1440
+ */
1441
+ createArgument(name, description) {
1442
+ return new Argument2(name, description);
1443
+ }
1444
+ /**
1445
+ * Define argument syntax for command.
1446
+ *
1447
+ * The default is that the argument is required, and you can explicitly
1448
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
1449
+ *
1450
+ * @example
1451
+ * program.argument('<input-file>');
1452
+ * program.argument('[output-file]');
1453
+ *
1454
+ * @param {string} name
1455
+ * @param {string} [description]
1456
+ * @param {(Function|*)} [parseArg] - custom argument processing function or default value
1457
+ * @param {*} [defaultValue]
1458
+ * @return {Command} `this` command for chaining
1459
+ */
1460
+ argument(name, description, parseArg, defaultValue) {
1461
+ const argument = this.createArgument(name, description);
1462
+ if (typeof parseArg === "function") {
1463
+ argument.default(defaultValue).argParser(parseArg);
1464
+ } else {
1465
+ argument.default(parseArg);
1466
+ }
1467
+ this.addArgument(argument);
1468
+ return this;
1469
+ }
1470
+ /**
1471
+ * Define argument syntax for command, adding multiple at once (without descriptions).
1472
+ *
1473
+ * See also .argument().
1474
+ *
1475
+ * @example
1476
+ * program.arguments('<cmd> [env]');
1477
+ *
1478
+ * @param {string} names
1479
+ * @return {Command} `this` command for chaining
1480
+ */
1481
+ arguments(names) {
1482
+ names.trim().split(/ +/).forEach((detail) => {
1483
+ this.argument(detail);
1484
+ });
1485
+ return this;
1486
+ }
1487
+ /**
1488
+ * Define argument syntax for command, adding a prepared argument.
1489
+ *
1490
+ * @param {Argument} argument
1491
+ * @return {Command} `this` command for chaining
1492
+ */
1493
+ addArgument(argument) {
1494
+ const previousArgument = this.registeredArguments.slice(-1)[0];
1495
+ if (previousArgument?.variadic) {
1496
+ throw new Error(
1497
+ `only the last argument can be variadic '${previousArgument.name()}'`
1498
+ );
1499
+ }
1500
+ if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
1501
+ throw new Error(
1502
+ `a default value for a required argument is never used: '${argument.name()}'`
1503
+ );
1504
+ }
1505
+ this.registeredArguments.push(argument);
1506
+ return this;
1507
+ }
1508
+ /**
1509
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
1510
+ *
1511
+ * @example
1512
+ * program.helpCommand('help [cmd]');
1513
+ * program.helpCommand('help [cmd]', 'show help');
1514
+ * program.helpCommand(false); // suppress default help command
1515
+ * program.helpCommand(true); // add help command even if no subcommands
1516
+ *
1517
+ * @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
1518
+ * @param {string} [description] - custom description
1519
+ * @return {Command} `this` command for chaining
1520
+ */
1521
+ helpCommand(enableOrNameAndArgs, description) {
1522
+ if (typeof enableOrNameAndArgs === "boolean") {
1523
+ this._addImplicitHelpCommand = enableOrNameAndArgs;
1524
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
1525
+ this._initCommandGroup(this._getHelpCommand());
1526
+ }
1527
+ return this;
1528
+ }
1529
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
1530
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
1531
+ const helpDescription = description ?? "display help for command";
1532
+ const helpCommand = this.createCommand(helpName);
1533
+ helpCommand.helpOption(false);
1534
+ if (helpArgs) helpCommand.arguments(helpArgs);
1535
+ if (helpDescription) helpCommand.description(helpDescription);
1536
+ this._addImplicitHelpCommand = true;
1537
+ this._helpCommand = helpCommand;
1538
+ if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
1539
+ return this;
1540
+ }
1541
+ /**
1542
+ * Add prepared custom help command.
1543
+ *
1544
+ * @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
1545
+ * @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
1546
+ * @return {Command} `this` command for chaining
1547
+ */
1548
+ addHelpCommand(helpCommand, deprecatedDescription) {
1549
+ if (typeof helpCommand !== "object") {
1550
+ this.helpCommand(helpCommand, deprecatedDescription);
1551
+ return this;
1552
+ }
1553
+ this._addImplicitHelpCommand = true;
1554
+ this._helpCommand = helpCommand;
1555
+ this._initCommandGroup(helpCommand);
1556
+ return this;
1557
+ }
1558
+ /**
1559
+ * Lazy create help command.
1560
+ *
1561
+ * @return {(Command|null)}
1562
+ * @package
1563
+ */
1564
+ _getHelpCommand() {
1565
+ const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
1566
+ if (hasImplicitHelpCommand) {
1567
+ if (this._helpCommand === void 0) {
1568
+ this.helpCommand(void 0, void 0);
1569
+ }
1570
+ return this._helpCommand;
1571
+ }
1572
+ return null;
1573
+ }
1574
+ /**
1575
+ * Add hook for life cycle event.
1576
+ *
1577
+ * @param {string} event
1578
+ * @param {Function} listener
1579
+ * @return {Command} `this` command for chaining
1580
+ */
1581
+ hook(event, listener) {
1582
+ const allowedValues = ["preSubcommand", "preAction", "postAction"];
1583
+ if (!allowedValues.includes(event)) {
1584
+ throw new Error(`Unexpected value for event passed to hook : '${event}'.
1585
+ Expecting one of '${allowedValues.join("', '")}'`);
1586
+ }
1587
+ if (this._lifeCycleHooks[event]) {
1588
+ this._lifeCycleHooks[event].push(listener);
1589
+ } else {
1590
+ this._lifeCycleHooks[event] = [listener];
1591
+ }
1592
+ return this;
1593
+ }
1594
+ /**
1595
+ * Register callback to use as replacement for calling process.exit.
1596
+ *
1597
+ * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
1598
+ * @return {Command} `this` command for chaining
1599
+ */
1600
+ exitOverride(fn) {
1601
+ if (fn) {
1602
+ this._exitCallback = fn;
1603
+ } else {
1604
+ this._exitCallback = (err) => {
1605
+ if (err.code !== "commander.executeSubCommandAsync") {
1606
+ throw err;
1607
+ } else {
1608
+ }
1609
+ };
1610
+ }
1611
+ return this;
1612
+ }
1613
+ /**
1614
+ * Call process.exit, and _exitCallback if defined.
1615
+ *
1616
+ * @param {number} exitCode exit code for using with process.exit
1617
+ * @param {string} code an id string representing the error
1618
+ * @param {string} message human-readable description of the error
1619
+ * @return never
1620
+ * @private
1621
+ */
1622
+ _exit(exitCode, code, message) {
1623
+ if (this._exitCallback) {
1624
+ this._exitCallback(new CommanderError2(exitCode, code, message));
1625
+ }
1626
+ process.exit(exitCode);
1627
+ }
1628
+ /**
1629
+ * Register callback `fn` for the command.
1630
+ *
1631
+ * @example
1632
+ * program
1633
+ * .command('serve')
1634
+ * .description('start service')
1635
+ * .action(function() {
1636
+ * // do work here
1637
+ * });
1638
+ *
1639
+ * @param {Function} fn
1640
+ * @return {Command} `this` command for chaining
1641
+ */
1642
+ action(fn) {
1643
+ const listener = (args) => {
1644
+ const expectedArgsCount = this.registeredArguments.length;
1645
+ const actionArgs = args.slice(0, expectedArgsCount);
1646
+ if (this._storeOptionsAsProperties) {
1647
+ actionArgs[expectedArgsCount] = this;
1648
+ } else {
1649
+ actionArgs[expectedArgsCount] = this.opts();
1650
+ }
1651
+ actionArgs.push(this);
1652
+ return fn.apply(this, actionArgs);
1653
+ };
1654
+ this._actionHandler = listener;
1655
+ return this;
1656
+ }
1657
+ /**
1658
+ * Factory routine to create a new unattached option.
1659
+ *
1660
+ * See .option() for creating an attached option, which uses this routine to
1661
+ * create the option. You can override createOption to return a custom option.
1662
+ *
1663
+ * @param {string} flags
1664
+ * @param {string} [description]
1665
+ * @return {Option} new option
1666
+ */
1667
+ createOption(flags, description) {
1668
+ return new Option2(flags, description);
1669
+ }
1670
+ /**
1671
+ * Wrap parseArgs to catch 'commander.invalidArgument'.
1672
+ *
1673
+ * @param {(Option | Argument)} target
1674
+ * @param {string} value
1675
+ * @param {*} previous
1676
+ * @param {string} invalidArgumentMessage
1677
+ * @private
1678
+ */
1679
+ _callParseArg(target, value, previous, invalidArgumentMessage) {
1680
+ try {
1681
+ return target.parseArg(value, previous);
1682
+ } catch (err) {
1683
+ if (err.code === "commander.invalidArgument") {
1684
+ const message = `${invalidArgumentMessage} ${err.message}`;
1685
+ this.error(message, { exitCode: err.exitCode, code: err.code });
1686
+ }
1687
+ throw err;
1688
+ }
1689
+ }
1690
+ /**
1691
+ * Check for option flag conflicts.
1692
+ * Register option if no conflicts found, or throw on conflict.
1693
+ *
1694
+ * @param {Option} option
1695
+ * @private
1696
+ */
1697
+ _registerOption(option) {
1698
+ const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
1699
+ if (matchingOption) {
1700
+ const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
1701
+ throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1702
+ - already used by option '${matchingOption.flags}'`);
1703
+ }
1704
+ this._initOptionGroup(option);
1705
+ this.options.push(option);
1706
+ }
1707
+ /**
1708
+ * Check for command name and alias conflicts with existing commands.
1709
+ * Register command if no conflicts found, or throw on conflict.
1710
+ *
1711
+ * @param {Command} command
1712
+ * @private
1713
+ */
1714
+ _registerCommand(command) {
1715
+ const knownBy = (cmd) => {
1716
+ return [cmd.name()].concat(cmd.aliases());
1717
+ };
1718
+ const alreadyUsed = knownBy(command).find(
1719
+ (name) => this._findCommand(name)
1720
+ );
1721
+ if (alreadyUsed) {
1722
+ const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
1723
+ const newCmd = knownBy(command).join("|");
1724
+ throw new Error(
1725
+ `cannot add command '${newCmd}' as already have command '${existingCmd}'`
1726
+ );
1727
+ }
1728
+ this._initCommandGroup(command);
1729
+ this.commands.push(command);
1730
+ }
1731
+ /**
1732
+ * Add an option.
1733
+ *
1734
+ * @param {Option} option
1735
+ * @return {Command} `this` command for chaining
1736
+ */
1737
+ addOption(option) {
1738
+ this._registerOption(option);
1739
+ const oname = option.name();
1740
+ const name = option.attributeName();
1741
+ if (option.negate) {
1742
+ const positiveLongFlag = option.long.replace(/^--no-/, "--");
1743
+ if (!this._findOption(positiveLongFlag)) {
1744
+ this.setOptionValueWithSource(
1745
+ name,
1746
+ option.defaultValue === void 0 ? true : option.defaultValue,
1747
+ "default"
1748
+ );
1749
+ }
1750
+ } else if (option.defaultValue !== void 0) {
1751
+ this.setOptionValueWithSource(name, option.defaultValue, "default");
1752
+ }
1753
+ const handleOptionValue = (val, invalidValueMessage, valueSource) => {
1754
+ if (val == null && option.presetArg !== void 0) {
1755
+ val = option.presetArg;
1756
+ }
1757
+ const oldValue = this.getOptionValue(name);
1758
+ if (val !== null && option.parseArg) {
1759
+ val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1760
+ } else if (val !== null && option.variadic) {
1761
+ val = option._collectValue(val, oldValue);
1762
+ }
1763
+ if (val == null) {
1764
+ if (option.negate) {
1765
+ val = false;
1766
+ } else if (option.isBoolean() || option.optional) {
1767
+ val = true;
1768
+ } else {
1769
+ val = "";
1770
+ }
1771
+ }
1772
+ this.setOptionValueWithSource(name, val, valueSource);
1773
+ };
1774
+ this.on("option:" + oname, (val) => {
1775
+ const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
1776
+ handleOptionValue(val, invalidValueMessage, "cli");
1777
+ });
1778
+ if (option.envVar) {
1779
+ this.on("optionEnv:" + oname, (val) => {
1780
+ const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
1781
+ handleOptionValue(val, invalidValueMessage, "env");
1782
+ });
1783
+ }
1784
+ return this;
1785
+ }
1786
+ /**
1787
+ * Internal implementation shared by .option() and .requiredOption()
1788
+ *
1789
+ * @return {Command} `this` command for chaining
1790
+ * @private
1791
+ */
1792
+ _optionEx(config, flags, description, fn, defaultValue) {
1793
+ if (typeof flags === "object" && flags instanceof Option2) {
1794
+ throw new Error(
1795
+ "To add an Option object use addOption() instead of option() or requiredOption()"
1796
+ );
1797
+ }
1798
+ const option = this.createOption(flags, description);
1799
+ option.makeOptionMandatory(!!config.mandatory);
1800
+ if (typeof fn === "function") {
1801
+ option.default(defaultValue).argParser(fn);
1802
+ } else if (fn instanceof RegExp) {
1803
+ const regex = fn;
1804
+ fn = (val, def) => {
1805
+ const m = regex.exec(val);
1806
+ return m ? m[0] : def;
1807
+ };
1808
+ option.default(defaultValue).argParser(fn);
1809
+ } else {
1810
+ option.default(fn);
1811
+ }
1812
+ return this.addOption(option);
1813
+ }
1814
+ /**
1815
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
1816
+ *
1817
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
1818
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
1819
+ *
1820
+ * See the README for more details, and see also addOption() and requiredOption().
1821
+ *
1822
+ * @example
1823
+ * program
1824
+ * .option('-p, --pepper', 'add pepper')
1825
+ * .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
1826
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
1827
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
1828
+ *
1829
+ * @param {string} flags
1830
+ * @param {string} [description]
1831
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1832
+ * @param {*} [defaultValue]
1833
+ * @return {Command} `this` command for chaining
1834
+ */
1835
+ option(flags, description, parseArg, defaultValue) {
1836
+ return this._optionEx({}, flags, description, parseArg, defaultValue);
1837
+ }
1838
+ /**
1839
+ * Add a required option which must have a value after parsing. This usually means
1840
+ * the option must be specified on the command line. (Otherwise the same as .option().)
1841
+ *
1842
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1843
+ *
1844
+ * @param {string} flags
1845
+ * @param {string} [description]
1846
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1847
+ * @param {*} [defaultValue]
1848
+ * @return {Command} `this` command for chaining
1849
+ */
1850
+ requiredOption(flags, description, parseArg, defaultValue) {
1851
+ return this._optionEx(
1852
+ { mandatory: true },
1853
+ flags,
1854
+ description,
1855
+ parseArg,
1856
+ defaultValue
1857
+ );
1858
+ }
1859
+ /**
1860
+ * Alter parsing of short flags with optional values.
1861
+ *
1862
+ * @example
1863
+ * // for `.option('-f,--flag [value]'):
1864
+ * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
1865
+ * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
1866
+ *
1867
+ * @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
1868
+ * @return {Command} `this` command for chaining
1869
+ */
1870
+ combineFlagAndOptionalValue(combine = true) {
1871
+ this._combineFlagAndOptionalValue = !!combine;
1872
+ return this;
1873
+ }
1874
+ /**
1875
+ * Allow unknown options on the command line.
1876
+ *
1877
+ * @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
1878
+ * @return {Command} `this` command for chaining
1879
+ */
1880
+ allowUnknownOption(allowUnknown = true) {
1881
+ this._allowUnknownOption = !!allowUnknown;
1882
+ return this;
1883
+ }
1884
+ /**
1885
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1886
+ *
1887
+ * @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
1888
+ * @return {Command} `this` command for chaining
1889
+ */
1890
+ allowExcessArguments(allowExcess = true) {
1891
+ this._allowExcessArguments = !!allowExcess;
1892
+ return this;
1893
+ }
1894
+ /**
1895
+ * Enable positional options. Positional means global options are specified before subcommands which lets
1896
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1897
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
1898
+ *
1899
+ * @param {boolean} [positional]
1900
+ * @return {Command} `this` command for chaining
1901
+ */
1902
+ enablePositionalOptions(positional = true) {
1903
+ this._enablePositionalOptions = !!positional;
1904
+ return this;
1905
+ }
1906
+ /**
1907
+ * Pass through options that come after command-arguments rather than treat them as command-options,
1908
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
1909
+ * positional options to have been enabled on the program (parent commands).
1910
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
1911
+ *
1912
+ * @param {boolean} [passThrough] for unknown options.
1913
+ * @return {Command} `this` command for chaining
1914
+ */
1915
+ passThroughOptions(passThrough = true) {
1916
+ this._passThroughOptions = !!passThrough;
1917
+ this._checkForBrokenPassThrough();
1918
+ return this;
1919
+ }
1920
+ /**
1921
+ * @private
1922
+ */
1923
+ _checkForBrokenPassThrough() {
1924
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1925
+ throw new Error(
1926
+ `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
1927
+ );
1928
+ }
1929
+ }
1930
+ /**
1931
+ * Whether to store option values as properties on command object,
1932
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
1933
+ *
1934
+ * @param {boolean} [storeAsProperties=true]
1935
+ * @return {Command} `this` command for chaining
1936
+ */
1937
+ storeOptionsAsProperties(storeAsProperties = true) {
1938
+ if (this.options.length) {
1939
+ throw new Error("call .storeOptionsAsProperties() before adding options");
1940
+ }
1941
+ if (Object.keys(this._optionValues).length) {
1942
+ throw new Error(
1943
+ "call .storeOptionsAsProperties() before setting option values"
1944
+ );
1945
+ }
1946
+ this._storeOptionsAsProperties = !!storeAsProperties;
1947
+ return this;
1948
+ }
1949
+ /**
1950
+ * Retrieve option value.
1951
+ *
1952
+ * @param {string} key
1953
+ * @return {object} value
1954
+ */
1955
+ getOptionValue(key) {
1956
+ if (this._storeOptionsAsProperties) {
1957
+ return this[key];
1958
+ }
1959
+ return this._optionValues[key];
1960
+ }
1961
+ /**
1962
+ * Store option value.
1963
+ *
1964
+ * @param {string} key
1965
+ * @param {object} value
1966
+ * @return {Command} `this` command for chaining
1967
+ */
1968
+ setOptionValue(key, value) {
1969
+ return this.setOptionValueWithSource(key, value, void 0);
1970
+ }
1971
+ /**
1972
+ * Store option value and where the value came from.
1973
+ *
1974
+ * @param {string} key
1975
+ * @param {object} value
1976
+ * @param {string} source - expected values are default/config/env/cli/implied
1977
+ * @return {Command} `this` command for chaining
1978
+ */
1979
+ setOptionValueWithSource(key, value, source) {
1980
+ if (this._storeOptionsAsProperties) {
1981
+ this[key] = value;
1982
+ } else {
1983
+ this._optionValues[key] = value;
1984
+ }
1985
+ this._optionValueSources[key] = source;
1986
+ return this;
1987
+ }
1988
+ /**
1989
+ * Get source of option value.
1990
+ * Expected values are default | config | env | cli | implied
1991
+ *
1992
+ * @param {string} key
1993
+ * @return {string}
1994
+ */
1995
+ getOptionValueSource(key) {
1996
+ return this._optionValueSources[key];
1997
+ }
1998
+ /**
1999
+ * Get source of option value. See also .optsWithGlobals().
2000
+ * Expected values are default | config | env | cli | implied
2001
+ *
2002
+ * @param {string} key
2003
+ * @return {string}
2004
+ */
2005
+ getOptionValueSourceWithGlobals(key) {
2006
+ let source;
2007
+ this._getCommandAndAncestors().forEach((cmd) => {
2008
+ if (cmd.getOptionValueSource(key) !== void 0) {
2009
+ source = cmd.getOptionValueSource(key);
2010
+ }
2011
+ });
2012
+ return source;
2013
+ }
2014
+ /**
2015
+ * Get user arguments from implied or explicit arguments.
2016
+ * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
2017
+ *
2018
+ * @private
2019
+ */
2020
+ _prepareUserArgs(argv, parseOptions) {
2021
+ if (argv !== void 0 && !Array.isArray(argv)) {
2022
+ throw new Error("first parameter to parse must be array or undefined");
2023
+ }
2024
+ parseOptions = parseOptions || {};
2025
+ if (argv === void 0 && parseOptions.from === void 0) {
2026
+ if (process.versions?.electron) {
2027
+ parseOptions.from = "electron";
2028
+ }
2029
+ const execArgv = process.execArgv ?? [];
2030
+ if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
2031
+ parseOptions.from = "eval";
2032
+ }
2033
+ }
2034
+ if (argv === void 0) {
2035
+ argv = process.argv;
2036
+ }
2037
+ this.rawArgs = argv.slice();
2038
+ let userArgs;
2039
+ switch (parseOptions.from) {
2040
+ case void 0:
2041
+ case "node":
2042
+ this._scriptPath = argv[1];
2043
+ userArgs = argv.slice(2);
2044
+ break;
2045
+ case "electron":
2046
+ if (process.defaultApp) {
2047
+ this._scriptPath = argv[1];
2048
+ userArgs = argv.slice(2);
2049
+ } else {
2050
+ userArgs = argv.slice(1);
2051
+ }
2052
+ break;
2053
+ case "user":
2054
+ userArgs = argv.slice(0);
2055
+ break;
2056
+ case "eval":
2057
+ userArgs = argv.slice(1);
2058
+ break;
2059
+ default:
2060
+ throw new Error(
2061
+ `unexpected parse option { from: '${parseOptions.from}' }`
2062
+ );
2063
+ }
2064
+ if (!this._name && this._scriptPath)
2065
+ this.nameFromFilename(this._scriptPath);
2066
+ this._name = this._name || "program";
2067
+ return userArgs;
2068
+ }
2069
+ /**
2070
+ * Parse `argv`, setting options and invoking commands when defined.
2071
+ *
2072
+ * Use parseAsync instead of parse if any of your action handlers are async.
2073
+ *
2074
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
2075
+ *
2076
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
2077
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
2078
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
2079
+ * - `'user'`: just user arguments
2080
+ *
2081
+ * @example
2082
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
2083
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
2084
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
2085
+ *
2086
+ * @param {string[]} [argv] - optional, defaults to process.argv
2087
+ * @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
2088
+ * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
2089
+ * @return {Command} `this` command for chaining
2090
+ */
2091
+ parse(argv, parseOptions) {
2092
+ this._prepareForParse();
2093
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
2094
+ this._parseCommand([], userArgs);
2095
+ return this;
2096
+ }
2097
+ /**
2098
+ * Parse `argv`, setting options and invoking commands when defined.
2099
+ *
2100
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
2101
+ *
2102
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
2103
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
2104
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
2105
+ * - `'user'`: just user arguments
2106
+ *
2107
+ * @example
2108
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
2109
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
2110
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
2111
+ *
2112
+ * @param {string[]} [argv]
2113
+ * @param {object} [parseOptions]
2114
+ * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
2115
+ * @return {Promise}
2116
+ */
2117
+ async parseAsync(argv, parseOptions) {
2118
+ this._prepareForParse();
2119
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
2120
+ await this._parseCommand([], userArgs);
2121
+ return this;
2122
+ }
2123
+ _prepareForParse() {
2124
+ if (this._savedState === null) {
2125
+ this.saveStateBeforeParse();
2126
+ } else {
2127
+ this.restoreStateBeforeParse();
2128
+ }
2129
+ }
2130
+ /**
2131
+ * Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
2132
+ * Not usually called directly, but available for subclasses to save their custom state.
2133
+ *
2134
+ * This is called in a lazy way. Only commands used in parsing chain will have state saved.
2135
+ */
2136
+ saveStateBeforeParse() {
2137
+ this._savedState = {
2138
+ // name is stable if supplied by author, but may be unspecified for root command and deduced during parsing
2139
+ _name: this._name,
2140
+ // option values before parse have default values (including false for negated options)
2141
+ // shallow clones
2142
+ _optionValues: { ...this._optionValues },
2143
+ _optionValueSources: { ...this._optionValueSources }
2144
+ };
2145
+ }
2146
+ /**
2147
+ * Restore state before parse for calls after the first.
2148
+ * Not usually called directly, but available for subclasses to save their custom state.
2149
+ *
2150
+ * This is called in a lazy way. Only commands used in parsing chain will have state restored.
2151
+ */
2152
+ restoreStateBeforeParse() {
2153
+ if (this._storeOptionsAsProperties)
2154
+ throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
2155
+ - either make a new Command for each call to parse, or stop storing options as properties`);
2156
+ this._name = this._savedState._name;
2157
+ this._scriptPath = null;
2158
+ this.rawArgs = [];
2159
+ this._optionValues = { ...this._savedState._optionValues };
2160
+ this._optionValueSources = { ...this._savedState._optionValueSources };
2161
+ this.args = [];
2162
+ this.processedArgs = [];
2163
+ }
2164
+ /**
2165
+ * Throw if expected executable is missing. Add lots of help for author.
2166
+ *
2167
+ * @param {string} executableFile
2168
+ * @param {string} executableDir
2169
+ * @param {string} subcommandName
2170
+ */
2171
+ _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
2172
+ if (fs.existsSync(executableFile)) return;
2173
+ 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";
2174
+ const executableMissing = `'${executableFile}' does not exist
2175
+ - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
2176
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
2177
+ - ${executableDirMessage}`;
2178
+ throw new Error(executableMissing);
2179
+ }
2180
+ /**
2181
+ * Execute a sub-command executable.
2182
+ *
2183
+ * @private
2184
+ */
2185
+ _executeSubCommand(subcommand, args) {
2186
+ args = args.slice();
2187
+ let launchWithNode = false;
2188
+ const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
2189
+ function findFile(baseDir, baseName) {
2190
+ const localBin = path.resolve(baseDir, baseName);
2191
+ if (fs.existsSync(localBin)) return localBin;
2192
+ if (sourceExt.includes(path.extname(baseName))) return void 0;
2193
+ const foundExt = sourceExt.find(
2194
+ (ext) => fs.existsSync(`${localBin}${ext}`)
2195
+ );
2196
+ if (foundExt) return `${localBin}${foundExt}`;
2197
+ return void 0;
2198
+ }
2199
+ this._checkForMissingMandatoryOptions();
2200
+ this._checkForConflictingOptions();
2201
+ let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
2202
+ let executableDir = this._executableDir || "";
2203
+ if (this._scriptPath) {
2204
+ let resolvedScriptPath;
2205
+ try {
2206
+ resolvedScriptPath = fs.realpathSync(this._scriptPath);
2207
+ } catch {
2208
+ resolvedScriptPath = this._scriptPath;
2209
+ }
2210
+ executableDir = path.resolve(
2211
+ path.dirname(resolvedScriptPath),
2212
+ executableDir
2213
+ );
2214
+ }
2215
+ if (executableDir) {
2216
+ let localFile = findFile(executableDir, executableFile);
2217
+ if (!localFile && !subcommand._executableFile && this._scriptPath) {
2218
+ const legacyName = path.basename(
2219
+ this._scriptPath,
2220
+ path.extname(this._scriptPath)
2221
+ );
2222
+ if (legacyName !== this._name) {
2223
+ localFile = findFile(
2224
+ executableDir,
2225
+ `${legacyName}-${subcommand._name}`
2226
+ );
2227
+ }
2228
+ }
2229
+ executableFile = localFile || executableFile;
2230
+ }
2231
+ launchWithNode = sourceExt.includes(path.extname(executableFile));
2232
+ let proc;
2233
+ if (process.platform !== "win32") {
2234
+ if (launchWithNode) {
2235
+ args.unshift(executableFile);
2236
+ args = incrementNodeInspectorPort(process.execArgv).concat(args);
2237
+ proc = childProcess.spawn(process.argv[0], args, { stdio: "inherit" });
2238
+ } else {
2239
+ proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
2240
+ }
2241
+ } else {
2242
+ this._checkForMissingExecutable(
2243
+ executableFile,
2244
+ executableDir,
2245
+ subcommand._name
2246
+ );
2247
+ args.unshift(executableFile);
2248
+ args = incrementNodeInspectorPort(process.execArgv).concat(args);
2249
+ proc = childProcess.spawn(process.execPath, args, { stdio: "inherit" });
2250
+ }
2251
+ if (!proc.killed) {
2252
+ const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
2253
+ signals.forEach((signal) => {
2254
+ process.on(signal, () => {
2255
+ if (proc.killed === false && proc.exitCode === null) {
2256
+ proc.kill(signal);
2257
+ }
2258
+ });
2259
+ });
2260
+ }
2261
+ const exitCallback = this._exitCallback;
2262
+ proc.on("close", (code) => {
2263
+ code = code ?? 1;
2264
+ if (!exitCallback) {
2265
+ process.exit(code);
2266
+ } else {
2267
+ exitCallback(
2268
+ new CommanderError2(
2269
+ code,
2270
+ "commander.executeSubCommandAsync",
2271
+ "(close)"
2272
+ )
2273
+ );
2274
+ }
2275
+ });
2276
+ proc.on("error", (err) => {
2277
+ if (err.code === "ENOENT") {
2278
+ this._checkForMissingExecutable(
2279
+ executableFile,
2280
+ executableDir,
2281
+ subcommand._name
2282
+ );
2283
+ } else if (err.code === "EACCES") {
2284
+ throw new Error(`'${executableFile}' not executable`);
2285
+ }
2286
+ if (!exitCallback) {
2287
+ process.exit(1);
2288
+ } else {
2289
+ const wrappedError = new CommanderError2(
2290
+ 1,
2291
+ "commander.executeSubCommandAsync",
2292
+ "(error)"
2293
+ );
2294
+ wrappedError.nestedError = err;
2295
+ exitCallback(wrappedError);
2296
+ }
2297
+ });
2298
+ this.runningCommand = proc;
2299
+ }
2300
+ /**
2301
+ * @private
2302
+ */
2303
+ _dispatchSubcommand(commandName, operands, unknown) {
2304
+ const subCommand = this._findCommand(commandName);
2305
+ if (!subCommand) this.help({ error: true });
2306
+ subCommand._prepareForParse();
2307
+ let promiseChain;
2308
+ promiseChain = this._chainOrCallSubCommandHook(
2309
+ promiseChain,
2310
+ subCommand,
2311
+ "preSubcommand"
2312
+ );
2313
+ promiseChain = this._chainOrCall(promiseChain, () => {
2314
+ if (subCommand._executableHandler) {
2315
+ this._executeSubCommand(subCommand, operands.concat(unknown));
2316
+ } else {
2317
+ return subCommand._parseCommand(operands, unknown);
2318
+ }
2319
+ });
2320
+ return promiseChain;
2321
+ }
2322
+ /**
2323
+ * Invoke help directly if possible, or dispatch if necessary.
2324
+ * e.g. help foo
2325
+ *
2326
+ * @private
2327
+ */
2328
+ _dispatchHelpCommand(subcommandName) {
2329
+ if (!subcommandName) {
2330
+ this.help();
2331
+ }
2332
+ const subCommand = this._findCommand(subcommandName);
2333
+ if (subCommand && !subCommand._executableHandler) {
2334
+ subCommand.help();
2335
+ }
2336
+ return this._dispatchSubcommand(
2337
+ subcommandName,
2338
+ [],
2339
+ [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
2340
+ );
2341
+ }
2342
+ /**
2343
+ * Check this.args against expected this.registeredArguments.
2344
+ *
2345
+ * @private
2346
+ */
2347
+ _checkNumberOfArguments() {
2348
+ this.registeredArguments.forEach((arg, i) => {
2349
+ if (arg.required && this.args[i] == null) {
2350
+ this.missingArgument(arg.name());
2351
+ }
2352
+ });
2353
+ if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
2354
+ return;
2355
+ }
2356
+ if (this.args.length > this.registeredArguments.length) {
2357
+ this._excessArguments(this.args);
2358
+ }
2359
+ }
2360
+ /**
2361
+ * Process this.args using this.registeredArguments and save as this.processedArgs!
2362
+ *
2363
+ * @private
2364
+ */
2365
+ _processArguments() {
2366
+ const myParseArg = (argument, value, previous) => {
2367
+ let parsedValue = value;
2368
+ if (value !== null && argument.parseArg) {
2369
+ const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
2370
+ parsedValue = this._callParseArg(
2371
+ argument,
2372
+ value,
2373
+ previous,
2374
+ invalidValueMessage
2375
+ );
2376
+ }
2377
+ return parsedValue;
2378
+ };
2379
+ this._checkNumberOfArguments();
2380
+ const processedArgs = [];
2381
+ this.registeredArguments.forEach((declaredArg, index) => {
2382
+ let value = declaredArg.defaultValue;
2383
+ if (declaredArg.variadic) {
2384
+ if (index < this.args.length) {
2385
+ value = this.args.slice(index);
2386
+ if (declaredArg.parseArg) {
2387
+ value = value.reduce((processed, v) => {
2388
+ return myParseArg(declaredArg, v, processed);
2389
+ }, declaredArg.defaultValue);
2390
+ }
2391
+ } else if (value === void 0) {
2392
+ value = [];
2393
+ }
2394
+ } else if (index < this.args.length) {
2395
+ value = this.args[index];
2396
+ if (declaredArg.parseArg) {
2397
+ value = myParseArg(declaredArg, value, declaredArg.defaultValue);
2398
+ }
2399
+ }
2400
+ processedArgs[index] = value;
2401
+ });
2402
+ this.processedArgs = processedArgs;
2403
+ }
2404
+ /**
2405
+ * Once we have a promise we chain, but call synchronously until then.
2406
+ *
2407
+ * @param {(Promise|undefined)} promise
2408
+ * @param {Function} fn
2409
+ * @return {(Promise|undefined)}
2410
+ * @private
2411
+ */
2412
+ _chainOrCall(promise, fn) {
2413
+ if (promise?.then && typeof promise.then === "function") {
2414
+ return promise.then(() => fn());
2415
+ }
2416
+ return fn();
2417
+ }
2418
+ /**
2419
+ *
2420
+ * @param {(Promise|undefined)} promise
2421
+ * @param {string} event
2422
+ * @return {(Promise|undefined)}
2423
+ * @private
2424
+ */
2425
+ _chainOrCallHooks(promise, event) {
2426
+ let result = promise;
2427
+ const hooks = [];
2428
+ this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
2429
+ hookedCommand._lifeCycleHooks[event].forEach((callback) => {
2430
+ hooks.push({ hookedCommand, callback });
2431
+ });
2432
+ });
2433
+ if (event === "postAction") {
2434
+ hooks.reverse();
2435
+ }
2436
+ hooks.forEach((hookDetail) => {
2437
+ result = this._chainOrCall(result, () => {
2438
+ return hookDetail.callback(hookDetail.hookedCommand, this);
2439
+ });
2440
+ });
2441
+ return result;
2442
+ }
2443
+ /**
2444
+ *
2445
+ * @param {(Promise|undefined)} promise
2446
+ * @param {Command} subCommand
2447
+ * @param {string} event
2448
+ * @return {(Promise|undefined)}
2449
+ * @private
2450
+ */
2451
+ _chainOrCallSubCommandHook(promise, subCommand, event) {
2452
+ let result = promise;
2453
+ if (this._lifeCycleHooks[event] !== void 0) {
2454
+ this._lifeCycleHooks[event].forEach((hook) => {
2455
+ result = this._chainOrCall(result, () => {
2456
+ return hook(this, subCommand);
2457
+ });
2458
+ });
2459
+ }
2460
+ return result;
2461
+ }
2462
+ /**
2463
+ * Process arguments in context of this command.
2464
+ * Returns action result, in case it is a promise.
2465
+ *
2466
+ * @private
2467
+ */
2468
+ _parseCommand(operands, unknown) {
2469
+ const parsed = this.parseOptions(unknown);
2470
+ this._parseOptionsEnv();
2471
+ this._parseOptionsImplied();
2472
+ operands = operands.concat(parsed.operands);
2473
+ unknown = parsed.unknown;
2474
+ this.args = operands.concat(unknown);
2475
+ if (operands && this._findCommand(operands[0])) {
2476
+ return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
2477
+ }
2478
+ if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
2479
+ return this._dispatchHelpCommand(operands[1]);
2480
+ }
2481
+ if (this._defaultCommandName) {
2482
+ this._outputHelpIfRequested(unknown);
2483
+ return this._dispatchSubcommand(
2484
+ this._defaultCommandName,
2485
+ operands,
2486
+ unknown
2487
+ );
2488
+ }
2489
+ if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
2490
+ this.help({ error: true });
2491
+ }
2492
+ this._outputHelpIfRequested(parsed.unknown);
2493
+ this._checkForMissingMandatoryOptions();
2494
+ this._checkForConflictingOptions();
2495
+ const checkForUnknownOptions = () => {
2496
+ if (parsed.unknown.length > 0) {
2497
+ this.unknownOption(parsed.unknown[0]);
2498
+ }
2499
+ };
2500
+ const commandEvent = `command:${this.name()}`;
2501
+ if (this._actionHandler) {
2502
+ checkForUnknownOptions();
2503
+ this._processArguments();
2504
+ let promiseChain;
2505
+ promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
2506
+ promiseChain = this._chainOrCall(
2507
+ promiseChain,
2508
+ () => this._actionHandler(this.processedArgs)
2509
+ );
2510
+ if (this.parent) {
2511
+ promiseChain = this._chainOrCall(promiseChain, () => {
2512
+ this.parent.emit(commandEvent, operands, unknown);
2513
+ });
2514
+ }
2515
+ promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
2516
+ return promiseChain;
2517
+ }
2518
+ if (this.parent?.listenerCount(commandEvent)) {
2519
+ checkForUnknownOptions();
2520
+ this._processArguments();
2521
+ this.parent.emit(commandEvent, operands, unknown);
2522
+ } else if (operands.length) {
2523
+ if (this._findCommand("*")) {
2524
+ return this._dispatchSubcommand("*", operands, unknown);
2525
+ }
2526
+ if (this.listenerCount("command:*")) {
2527
+ this.emit("command:*", operands, unknown);
2528
+ } else if (this.commands.length) {
2529
+ this.unknownCommand();
2530
+ } else {
2531
+ checkForUnknownOptions();
2532
+ this._processArguments();
2533
+ }
2534
+ } else if (this.commands.length) {
2535
+ checkForUnknownOptions();
2536
+ this.help({ error: true });
2537
+ } else {
2538
+ checkForUnknownOptions();
2539
+ this._processArguments();
2540
+ }
2541
+ }
2542
+ /**
2543
+ * Find matching command.
2544
+ *
2545
+ * @private
2546
+ * @return {Command | undefined}
2547
+ */
2548
+ _findCommand(name) {
2549
+ if (!name) return void 0;
2550
+ return this.commands.find(
2551
+ (cmd) => cmd._name === name || cmd._aliases.includes(name)
2552
+ );
2553
+ }
2554
+ /**
2555
+ * Return an option matching `arg` if any.
2556
+ *
2557
+ * @param {string} arg
2558
+ * @return {Option}
2559
+ * @package
2560
+ */
2561
+ _findOption(arg) {
2562
+ return this.options.find((option) => option.is(arg));
2563
+ }
2564
+ /**
2565
+ * Display an error message if a mandatory option does not have a value.
2566
+ * Called after checking for help flags in leaf subcommand.
2567
+ *
2568
+ * @private
2569
+ */
2570
+ _checkForMissingMandatoryOptions() {
2571
+ this._getCommandAndAncestors().forEach((cmd) => {
2572
+ cmd.options.forEach((anOption) => {
2573
+ if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
2574
+ cmd.missingMandatoryOptionValue(anOption);
2575
+ }
2576
+ });
2577
+ });
2578
+ }
2579
+ /**
2580
+ * Display an error message if conflicting options are used together in this.
2581
+ *
2582
+ * @private
2583
+ */
2584
+ _checkForConflictingLocalOptions() {
2585
+ const definedNonDefaultOptions = this.options.filter((option) => {
2586
+ const optionKey = option.attributeName();
2587
+ if (this.getOptionValue(optionKey) === void 0) {
2588
+ return false;
2589
+ }
2590
+ return this.getOptionValueSource(optionKey) !== "default";
2591
+ });
2592
+ const optionsWithConflicting = definedNonDefaultOptions.filter(
2593
+ (option) => option.conflictsWith.length > 0
2594
+ );
2595
+ optionsWithConflicting.forEach((option) => {
2596
+ const conflictingAndDefined = definedNonDefaultOptions.find(
2597
+ (defined) => option.conflictsWith.includes(defined.attributeName())
2598
+ );
2599
+ if (conflictingAndDefined) {
2600
+ this._conflictingOption(option, conflictingAndDefined);
2601
+ }
2602
+ });
2603
+ }
2604
+ /**
2605
+ * Display an error message if conflicting options are used together.
2606
+ * Called after checking for help flags in leaf subcommand.
2607
+ *
2608
+ * @private
2609
+ */
2610
+ _checkForConflictingOptions() {
2611
+ this._getCommandAndAncestors().forEach((cmd) => {
2612
+ cmd._checkForConflictingLocalOptions();
2613
+ });
2614
+ }
2615
+ /**
2616
+ * Parse options from `argv` removing known options,
2617
+ * and return argv split into operands and unknown arguments.
2618
+ *
2619
+ * Side effects: modifies command by storing options. Does not reset state if called again.
2620
+ *
2621
+ * Examples:
2622
+ *
2623
+ * argv => operands, unknown
2624
+ * --known kkk op => [op], []
2625
+ * op --known kkk => [op], []
2626
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
2627
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
2628
+ *
2629
+ * @param {string[]} args
2630
+ * @return {{operands: string[], unknown: string[]}}
2631
+ */
2632
+ parseOptions(args) {
2633
+ const operands = [];
2634
+ const unknown = [];
2635
+ let dest = operands;
2636
+ function maybeOption(arg) {
2637
+ return arg.length > 1 && arg[0] === "-";
2638
+ }
2639
+ const negativeNumberArg = (arg) => {
2640
+ if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
2641
+ return !this._getCommandAndAncestors().some(
2642
+ (cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
2643
+ );
2644
+ };
2645
+ let activeVariadicOption = null;
2646
+ let activeGroup = null;
2647
+ let i = 0;
2648
+ while (i < args.length || activeGroup) {
2649
+ const arg = activeGroup ?? args[i++];
2650
+ activeGroup = null;
2651
+ if (arg === "--") {
2652
+ if (dest === unknown) dest.push(arg);
2653
+ dest.push(...args.slice(i));
2654
+ break;
2655
+ }
2656
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
2657
+ this.emit(`option:${activeVariadicOption.name()}`, arg);
2658
+ continue;
2659
+ }
2660
+ activeVariadicOption = null;
2661
+ if (maybeOption(arg)) {
2662
+ const option = this._findOption(arg);
2663
+ if (option) {
2664
+ if (option.required) {
2665
+ const value = args[i++];
2666
+ if (value === void 0) this.optionMissingArgument(option);
2667
+ this.emit(`option:${option.name()}`, value);
2668
+ } else if (option.optional) {
2669
+ let value = null;
2670
+ if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
2671
+ value = args[i++];
2672
+ }
2673
+ this.emit(`option:${option.name()}`, value);
2674
+ } else {
2675
+ this.emit(`option:${option.name()}`);
2676
+ }
2677
+ activeVariadicOption = option.variadic ? option : null;
2678
+ continue;
2679
+ }
2680
+ }
2681
+ if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
2682
+ const option = this._findOption(`-${arg[1]}`);
2683
+ if (option) {
2684
+ if (option.required || option.optional && this._combineFlagAndOptionalValue) {
2685
+ this.emit(`option:${option.name()}`, arg.slice(2));
2686
+ } else {
2687
+ this.emit(`option:${option.name()}`);
2688
+ activeGroup = `-${arg.slice(2)}`;
2689
+ }
2690
+ continue;
2691
+ }
2692
+ }
2693
+ if (/^--[^=]+=/.test(arg)) {
2694
+ const index = arg.indexOf("=");
2695
+ const option = this._findOption(arg.slice(0, index));
2696
+ if (option && (option.required || option.optional)) {
2697
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
2698
+ continue;
2699
+ }
2700
+ }
2701
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
2702
+ dest = unknown;
2703
+ }
2704
+ if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
2705
+ if (this._findCommand(arg)) {
2706
+ operands.push(arg);
2707
+ unknown.push(...args.slice(i));
2708
+ break;
2709
+ } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
2710
+ operands.push(arg, ...args.slice(i));
2711
+ break;
2712
+ } else if (this._defaultCommandName) {
2713
+ unknown.push(arg, ...args.slice(i));
2714
+ break;
2715
+ }
2716
+ }
2717
+ if (this._passThroughOptions) {
2718
+ dest.push(arg, ...args.slice(i));
2719
+ break;
2720
+ }
2721
+ dest.push(arg);
2722
+ }
2723
+ return { operands, unknown };
2724
+ }
2725
+ /**
2726
+ * Return an object containing local option values as key-value pairs.
2727
+ *
2728
+ * @return {object}
2729
+ */
2730
+ opts() {
2731
+ if (this._storeOptionsAsProperties) {
2732
+ const result = {};
2733
+ const len = this.options.length;
2734
+ for (let i = 0; i < len; i++) {
2735
+ const key = this.options[i].attributeName();
2736
+ result[key] = key === this._versionOptionName ? this._version : this[key];
2737
+ }
2738
+ return result;
2739
+ }
2740
+ return this._optionValues;
2741
+ }
2742
+ /**
2743
+ * Return an object containing merged local and global option values as key-value pairs.
2744
+ *
2745
+ * @return {object}
2746
+ */
2747
+ optsWithGlobals() {
2748
+ return this._getCommandAndAncestors().reduce(
2749
+ (combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
2750
+ {}
2751
+ );
2752
+ }
2753
+ /**
2754
+ * Display error message and exit (or call exitOverride).
2755
+ *
2756
+ * @param {string} message
2757
+ * @param {object} [errorOptions]
2758
+ * @param {string} [errorOptions.code] - an id string representing the error
2759
+ * @param {number} [errorOptions.exitCode] - used with process.exit
2760
+ */
2761
+ error(message, errorOptions) {
2762
+ this._outputConfiguration.outputError(
2763
+ `${message}
2764
+ `,
2765
+ this._outputConfiguration.writeErr
2766
+ );
2767
+ if (typeof this._showHelpAfterError === "string") {
2768
+ this._outputConfiguration.writeErr(`${this._showHelpAfterError}
2769
+ `);
2770
+ } else if (this._showHelpAfterError) {
2771
+ this._outputConfiguration.writeErr("\n");
2772
+ this.outputHelp({ error: true });
2773
+ }
2774
+ const config = errorOptions || {};
2775
+ const exitCode = config.exitCode || 1;
2776
+ const code = config.code || "commander.error";
2777
+ this._exit(exitCode, code, message);
2778
+ }
2779
+ /**
2780
+ * Apply any option related environment variables, if option does
2781
+ * not have a value from cli or client code.
2782
+ *
2783
+ * @private
2784
+ */
2785
+ _parseOptionsEnv() {
2786
+ this.options.forEach((option) => {
2787
+ if (option.envVar && option.envVar in process.env) {
2788
+ const optionKey = option.attributeName();
2789
+ if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
2790
+ this.getOptionValueSource(optionKey)
2791
+ )) {
2792
+ if (option.required || option.optional) {
2793
+ this.emit(`optionEnv:${option.name()}`, process.env[option.envVar]);
2794
+ } else {
2795
+ this.emit(`optionEnv:${option.name()}`);
2796
+ }
2797
+ }
2798
+ }
2799
+ });
2800
+ }
2801
+ /**
2802
+ * Apply any implied option values, if option is undefined or default value.
2803
+ *
2804
+ * @private
2805
+ */
2806
+ _parseOptionsImplied() {
2807
+ const dualHelper = new DualOptions(this.options);
2808
+ const hasCustomOptionValue = (optionKey) => {
2809
+ return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
2810
+ };
2811
+ this.options.filter(
2812
+ (option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
2813
+ this.getOptionValue(option.attributeName()),
2814
+ option
2815
+ )
2816
+ ).forEach((option) => {
2817
+ Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
2818
+ this.setOptionValueWithSource(
2819
+ impliedKey,
2820
+ option.implied[impliedKey],
2821
+ "implied"
2822
+ );
2823
+ });
2824
+ });
2825
+ }
2826
+ /**
2827
+ * Argument `name` is missing.
2828
+ *
2829
+ * @param {string} name
2830
+ * @private
2831
+ */
2832
+ missingArgument(name) {
2833
+ const message = `error: missing required argument '${name}'`;
2834
+ this.error(message, { code: "commander.missingArgument" });
2835
+ }
2836
+ /**
2837
+ * `Option` is missing an argument.
2838
+ *
2839
+ * @param {Option} option
2840
+ * @private
2841
+ */
2842
+ optionMissingArgument(option) {
2843
+ const message = `error: option '${option.flags}' argument missing`;
2844
+ this.error(message, { code: "commander.optionMissingArgument" });
2845
+ }
2846
+ /**
2847
+ * `Option` does not have a value, and is a mandatory option.
2848
+ *
2849
+ * @param {Option} option
2850
+ * @private
2851
+ */
2852
+ missingMandatoryOptionValue(option) {
2853
+ const message = `error: required option '${option.flags}' not specified`;
2854
+ this.error(message, { code: "commander.missingMandatoryOptionValue" });
2855
+ }
2856
+ /**
2857
+ * `Option` conflicts with another option.
2858
+ *
2859
+ * @param {Option} option
2860
+ * @param {Option} conflictingOption
2861
+ * @private
2862
+ */
2863
+ _conflictingOption(option, conflictingOption) {
2864
+ const findBestOptionFromValue = (option2) => {
2865
+ const optionKey = option2.attributeName();
2866
+ const optionValue = this.getOptionValue(optionKey);
2867
+ const negativeOption = this.options.find(
2868
+ (target) => target.negate && optionKey === target.attributeName()
2869
+ );
2870
+ const positiveOption = this.options.find(
2871
+ (target) => !target.negate && optionKey === target.attributeName()
2872
+ );
2873
+ if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
2874
+ return negativeOption;
2875
+ }
2876
+ return positiveOption || option2;
2877
+ };
2878
+ const getErrorMessage = (option2) => {
2879
+ const bestOption = findBestOptionFromValue(option2);
2880
+ const optionKey = bestOption.attributeName();
2881
+ const source = this.getOptionValueSource(optionKey);
2882
+ if (source === "env") {
2883
+ return `environment variable '${bestOption.envVar}'`;
2884
+ }
2885
+ return `option '${bestOption.flags}'`;
2886
+ };
2887
+ const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
2888
+ this.error(message, { code: "commander.conflictingOption" });
2889
+ }
2890
+ /**
2891
+ * Unknown option `flag`.
2892
+ *
2893
+ * @param {string} flag
2894
+ * @private
2895
+ */
2896
+ unknownOption(flag) {
2897
+ if (this._allowUnknownOption) return;
2898
+ let suggestion = "";
2899
+ if (flag.startsWith("--") && this._showSuggestionAfterError) {
2900
+ let candidateFlags = [];
2901
+ let command = this;
2902
+ do {
2903
+ const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
2904
+ candidateFlags = candidateFlags.concat(moreFlags);
2905
+ command = command.parent;
2906
+ } while (command && !command._enablePositionalOptions);
2907
+ suggestion = suggestSimilar(flag, candidateFlags);
2908
+ }
2909
+ const message = `error: unknown option '${flag}'${suggestion}`;
2910
+ this.error(message, { code: "commander.unknownOption" });
2911
+ }
2912
+ /**
2913
+ * Excess arguments, more than expected.
2914
+ *
2915
+ * @param {string[]} receivedArgs
2916
+ * @private
2917
+ */
2918
+ _excessArguments(receivedArgs) {
2919
+ if (this._allowExcessArguments) return;
2920
+ const expected = this.registeredArguments.length;
2921
+ const s = expected === 1 ? "" : "s";
2922
+ const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
2923
+ const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
2924
+ this.error(message, { code: "commander.excessArguments" });
2925
+ }
2926
+ /**
2927
+ * Unknown command.
2928
+ *
2929
+ * @private
2930
+ */
2931
+ unknownCommand() {
2932
+ const unknownName = this.args[0];
2933
+ let suggestion = "";
2934
+ if (this._showSuggestionAfterError) {
2935
+ const candidateNames = [];
2936
+ this.createHelp().visibleCommands(this).forEach((command) => {
2937
+ candidateNames.push(command.name());
2938
+ if (command.alias()) candidateNames.push(command.alias());
2939
+ });
2940
+ suggestion = suggestSimilar(unknownName, candidateNames);
2941
+ }
2942
+ const message = `error: unknown command '${unknownName}'${suggestion}`;
2943
+ this.error(message, { code: "commander.unknownCommand" });
2944
+ }
2945
+ /**
2946
+ * Get or set the program version.
2947
+ *
2948
+ * This method auto-registers the "-V, --version" option which will print the version number.
2949
+ *
2950
+ * You can optionally supply the flags and description to override the defaults.
2951
+ *
2952
+ * @param {string} [str]
2953
+ * @param {string} [flags]
2954
+ * @param {string} [description]
2955
+ * @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
2956
+ */
2957
+ version(str, flags, description) {
2958
+ if (str === void 0) return this._version;
2959
+ this._version = str;
2960
+ flags = flags || "-V, --version";
2961
+ description = description || "output the version number";
2962
+ const versionOption = this.createOption(flags, description);
2963
+ this._versionOptionName = versionOption.attributeName();
2964
+ this._registerOption(versionOption);
2965
+ this.on("option:" + versionOption.name(), () => {
2966
+ this._outputConfiguration.writeOut(`${str}
2967
+ `);
2968
+ this._exit(0, "commander.version", str);
2969
+ });
2970
+ return this;
2971
+ }
2972
+ /**
2973
+ * Set the description.
2974
+ *
2975
+ * @param {string} [str]
2976
+ * @param {object} [argsDescription]
2977
+ * @return {(string|Command)}
2978
+ */
2979
+ description(str, argsDescription) {
2980
+ if (str === void 0 && argsDescription === void 0)
2981
+ return this._description;
2982
+ this._description = str;
2983
+ if (argsDescription) {
2984
+ this._argsDescription = argsDescription;
2985
+ }
2986
+ return this;
2987
+ }
2988
+ /**
2989
+ * Set the summary. Used when listed as subcommand of parent.
2990
+ *
2991
+ * @param {string} [str]
2992
+ * @return {(string|Command)}
2993
+ */
2994
+ summary(str) {
2995
+ if (str === void 0) return this._summary;
2996
+ this._summary = str;
2997
+ return this;
2998
+ }
2999
+ /**
3000
+ * Set an alias for the command.
3001
+ *
3002
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
3003
+ *
3004
+ * @param {string} [alias]
3005
+ * @return {(string|Command)}
3006
+ */
3007
+ alias(alias) {
3008
+ if (alias === void 0) return this._aliases[0];
3009
+ let command = this;
3010
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
3011
+ command = this.commands[this.commands.length - 1];
3012
+ }
3013
+ if (alias === command._name)
3014
+ throw new Error("Command alias can't be the same as its name");
3015
+ const matchingCommand = this.parent?._findCommand(alias);
3016
+ if (matchingCommand) {
3017
+ const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
3018
+ throw new Error(
3019
+ `cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
3020
+ );
3021
+ }
3022
+ command._aliases.push(alias);
3023
+ return this;
3024
+ }
3025
+ /**
3026
+ * Set aliases for the command.
3027
+ *
3028
+ * Only the first alias is shown in the auto-generated help.
3029
+ *
3030
+ * @param {string[]} [aliases]
3031
+ * @return {(string[]|Command)}
3032
+ */
3033
+ aliases(aliases) {
3034
+ if (aliases === void 0) return this._aliases;
3035
+ aliases.forEach((alias) => this.alias(alias));
3036
+ return this;
3037
+ }
3038
+ /**
3039
+ * Set / get the command usage `str`.
3040
+ *
3041
+ * @param {string} [str]
3042
+ * @return {(string|Command)}
3043
+ */
3044
+ usage(str) {
3045
+ if (str === void 0) {
3046
+ if (this._usage) return this._usage;
3047
+ const args = this.registeredArguments.map((arg) => {
3048
+ return humanReadableArgName(arg);
3049
+ });
3050
+ return [].concat(
3051
+ this.options.length || this._helpOption !== null ? "[options]" : [],
3052
+ this.commands.length ? "[command]" : [],
3053
+ this.registeredArguments.length ? args : []
3054
+ ).join(" ");
3055
+ }
3056
+ this._usage = str;
3057
+ return this;
3058
+ }
3059
+ /**
3060
+ * Get or set the name of the command.
3061
+ *
3062
+ * @param {string} [str]
3063
+ * @return {(string|Command)}
3064
+ */
3065
+ name(str) {
3066
+ if (str === void 0) return this._name;
3067
+ this._name = str;
3068
+ return this;
3069
+ }
3070
+ /**
3071
+ * Set/get the help group heading for this subcommand in parent command's help.
3072
+ *
3073
+ * @param {string} [heading]
3074
+ * @return {Command | string}
3075
+ */
3076
+ helpGroup(heading) {
3077
+ if (heading === void 0) return this._helpGroupHeading ?? "";
3078
+ this._helpGroupHeading = heading;
3079
+ return this;
3080
+ }
3081
+ /**
3082
+ * Set/get the default help group heading for subcommands added to this command.
3083
+ * (This does not override a group set directly on the subcommand using .helpGroup().)
3084
+ *
3085
+ * @example
3086
+ * program.commandsGroup('Development Commands:);
3087
+ * program.command('watch')...
3088
+ * program.command('lint')...
3089
+ * ...
3090
+ *
3091
+ * @param {string} [heading]
3092
+ * @returns {Command | string}
3093
+ */
3094
+ commandsGroup(heading) {
3095
+ if (heading === void 0) return this._defaultCommandGroup ?? "";
3096
+ this._defaultCommandGroup = heading;
3097
+ return this;
3098
+ }
3099
+ /**
3100
+ * Set/get the default help group heading for options added to this command.
3101
+ * (This does not override a group set directly on the option using .helpGroup().)
3102
+ *
3103
+ * @example
3104
+ * program
3105
+ * .optionsGroup('Development Options:')
3106
+ * .option('-d, --debug', 'output extra debugging')
3107
+ * .option('-p, --profile', 'output profiling information')
3108
+ *
3109
+ * @param {string} [heading]
3110
+ * @returns {Command | string}
3111
+ */
3112
+ optionsGroup(heading) {
3113
+ if (heading === void 0) return this._defaultOptionGroup ?? "";
3114
+ this._defaultOptionGroup = heading;
3115
+ return this;
3116
+ }
3117
+ /**
3118
+ * @param {Option} option
3119
+ * @private
3120
+ */
3121
+ _initOptionGroup(option) {
3122
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
3123
+ option.helpGroup(this._defaultOptionGroup);
3124
+ }
3125
+ /**
3126
+ * @param {Command} cmd
3127
+ * @private
3128
+ */
3129
+ _initCommandGroup(cmd) {
3130
+ if (this._defaultCommandGroup && !cmd.helpGroup())
3131
+ cmd.helpGroup(this._defaultCommandGroup);
3132
+ }
3133
+ /**
3134
+ * Set the name of the command from script filename, such as process.argv[1],
3135
+ * or require.main.filename, or __filename.
3136
+ *
3137
+ * (Used internally and public although not documented in README.)
3138
+ *
3139
+ * @example
3140
+ * program.nameFromFilename(require.main.filename);
3141
+ *
3142
+ * @param {string} filename
3143
+ * @return {Command}
3144
+ */
3145
+ nameFromFilename(filename) {
3146
+ this._name = path.basename(filename, path.extname(filename));
3147
+ return this;
3148
+ }
3149
+ /**
3150
+ * Get or set the directory for searching for executable subcommands of this command.
3151
+ *
3152
+ * @example
3153
+ * program.executableDir(__dirname);
3154
+ * // or
3155
+ * program.executableDir('subcommands');
3156
+ *
3157
+ * @param {string} [path]
3158
+ * @return {(string|null|Command)}
3159
+ */
3160
+ executableDir(path2) {
3161
+ if (path2 === void 0) return this._executableDir;
3162
+ this._executableDir = path2;
3163
+ return this;
3164
+ }
3165
+ /**
3166
+ * Return program help documentation.
3167
+ *
3168
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
3169
+ * @return {string}
3170
+ */
3171
+ helpInformation(contextOptions) {
3172
+ const helper = this.createHelp();
3173
+ const context = this._getOutputContext(contextOptions);
3174
+ helper.prepareContext({
3175
+ error: context.error,
3176
+ helpWidth: context.helpWidth,
3177
+ outputHasColors: context.hasColors
3178
+ });
3179
+ const text = helper.formatHelp(this, helper);
3180
+ if (context.hasColors) return text;
3181
+ return this._outputConfiguration.stripColor(text);
3182
+ }
3183
+ /**
3184
+ * @typedef HelpContext
3185
+ * @type {object}
3186
+ * @property {boolean} error
3187
+ * @property {number} helpWidth
3188
+ * @property {boolean} hasColors
3189
+ * @property {function} write - includes stripColor if needed
3190
+ *
3191
+ * @returns {HelpContext}
3192
+ * @private
3193
+ */
3194
+ _getOutputContext(contextOptions) {
3195
+ contextOptions = contextOptions || {};
3196
+ const error = !!contextOptions.error;
3197
+ let baseWrite;
3198
+ let hasColors;
3199
+ let helpWidth;
3200
+ if (error) {
3201
+ baseWrite = (str) => this._outputConfiguration.writeErr(str);
3202
+ hasColors = this._outputConfiguration.getErrHasColors();
3203
+ helpWidth = this._outputConfiguration.getErrHelpWidth();
3204
+ } else {
3205
+ baseWrite = (str) => this._outputConfiguration.writeOut(str);
3206
+ hasColors = this._outputConfiguration.getOutHasColors();
3207
+ helpWidth = this._outputConfiguration.getOutHelpWidth();
3208
+ }
3209
+ const write = (str) => {
3210
+ if (!hasColors) str = this._outputConfiguration.stripColor(str);
3211
+ return baseWrite(str);
3212
+ };
3213
+ return { error, write, hasColors, helpWidth };
3214
+ }
3215
+ /**
3216
+ * Output help information for this command.
3217
+ *
3218
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
3219
+ *
3220
+ * @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
3221
+ */
3222
+ outputHelp(contextOptions) {
3223
+ let deprecatedCallback;
3224
+ if (typeof contextOptions === "function") {
3225
+ deprecatedCallback = contextOptions;
3226
+ contextOptions = void 0;
3227
+ }
3228
+ const outputContext = this._getOutputContext(contextOptions);
3229
+ const eventContext = {
3230
+ error: outputContext.error,
3231
+ write: outputContext.write,
3232
+ command: this
3233
+ };
3234
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
3235
+ this.emit("beforeHelp", eventContext);
3236
+ let helpInformation = this.helpInformation({ error: outputContext.error });
3237
+ if (deprecatedCallback) {
3238
+ helpInformation = deprecatedCallback(helpInformation);
3239
+ if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
3240
+ throw new Error("outputHelp callback must return a string or a Buffer");
3241
+ }
3242
+ }
3243
+ outputContext.write(helpInformation);
3244
+ if (this._getHelpOption()?.long) {
3245
+ this.emit(this._getHelpOption().long);
3246
+ }
3247
+ this.emit("afterHelp", eventContext);
3248
+ this._getCommandAndAncestors().forEach(
3249
+ (command) => command.emit("afterAllHelp", eventContext)
3250
+ );
3251
+ }
3252
+ /**
3253
+ * You can pass in flags and a description to customise the built-in help option.
3254
+ * Pass in false to disable the built-in help option.
3255
+ *
3256
+ * @example
3257
+ * program.helpOption('-?, --help' 'show help'); // customise
3258
+ * program.helpOption(false); // disable
3259
+ *
3260
+ * @param {(string | boolean)} flags
3261
+ * @param {string} [description]
3262
+ * @return {Command} `this` command for chaining
3263
+ */
3264
+ helpOption(flags, description) {
3265
+ if (typeof flags === "boolean") {
3266
+ if (flags) {
3267
+ if (this._helpOption === null) this._helpOption = void 0;
3268
+ if (this._defaultOptionGroup) {
3269
+ this._initOptionGroup(this._getHelpOption());
3270
+ }
3271
+ } else {
3272
+ this._helpOption = null;
3273
+ }
3274
+ return this;
3275
+ }
3276
+ this._helpOption = this.createOption(
3277
+ flags ?? "-h, --help",
3278
+ description ?? "display help for command"
3279
+ );
3280
+ if (flags || description) this._initOptionGroup(this._helpOption);
3281
+ return this;
3282
+ }
3283
+ /**
3284
+ * Lazy create help option.
3285
+ * Returns null if has been disabled with .helpOption(false).
3286
+ *
3287
+ * @returns {(Option | null)} the help option
3288
+ * @package
3289
+ */
3290
+ _getHelpOption() {
3291
+ if (this._helpOption === void 0) {
3292
+ this.helpOption(void 0, void 0);
3293
+ }
3294
+ return this._helpOption;
3295
+ }
3296
+ /**
3297
+ * Supply your own option to use for the built-in help option.
3298
+ * This is an alternative to using helpOption() to customise the flags and description etc.
3299
+ *
3300
+ * @param {Option} option
3301
+ * @return {Command} `this` command for chaining
3302
+ */
3303
+ addHelpOption(option) {
3304
+ this._helpOption = option;
3305
+ this._initOptionGroup(option);
3306
+ return this;
3307
+ }
3308
+ /**
3309
+ * Output help information and exit.
3310
+ *
3311
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
3312
+ *
3313
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
3314
+ */
3315
+ help(contextOptions) {
3316
+ this.outputHelp(contextOptions);
3317
+ let exitCode = Number(process.exitCode ?? 0);
3318
+ if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
3319
+ exitCode = 1;
3320
+ }
3321
+ this._exit(exitCode, "commander.help", "(outputHelp)");
3322
+ }
3323
+ /**
3324
+ * // Do a little typing to coordinate emit and listener for the help text events.
3325
+ * @typedef HelpTextEventContext
3326
+ * @type {object}
3327
+ * @property {boolean} error
3328
+ * @property {Command} command
3329
+ * @property {function} write
3330
+ */
3331
+ /**
3332
+ * Add additional text to be displayed with the built-in help.
3333
+ *
3334
+ * Position is 'before' or 'after' to affect just this command,
3335
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
3336
+ *
3337
+ * @param {string} position - before or after built-in help
3338
+ * @param {(string | Function)} text - string to add, or a function returning a string
3339
+ * @return {Command} `this` command for chaining
3340
+ */
3341
+ addHelpText(position, text) {
3342
+ const allowedValues = ["beforeAll", "before", "after", "afterAll"];
3343
+ if (!allowedValues.includes(position)) {
3344
+ throw new Error(`Unexpected value for position to addHelpText.
3345
+ Expecting one of '${allowedValues.join("', '")}'`);
3346
+ }
3347
+ const helpEvent = `${position}Help`;
3348
+ this.on(helpEvent, (context) => {
3349
+ let helpStr;
3350
+ if (typeof text === "function") {
3351
+ helpStr = text({ error: context.error, command: context.command });
3352
+ } else {
3353
+ helpStr = text;
3354
+ }
3355
+ if (helpStr) {
3356
+ context.write(`${helpStr}
3357
+ `);
3358
+ }
3359
+ });
3360
+ return this;
3361
+ }
3362
+ /**
3363
+ * Output help information if help flags specified
3364
+ *
3365
+ * @param {Array} args - array of options to search for help flags
3366
+ * @private
3367
+ */
3368
+ _outputHelpIfRequested(args) {
3369
+ const helpOption = this._getHelpOption();
3370
+ const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
3371
+ if (helpRequested) {
3372
+ this.outputHelp();
3373
+ this._exit(0, "commander.helpDisplayed", "(outputHelp)");
3374
+ }
3375
+ }
3376
+ };
3377
+ function incrementNodeInspectorPort(args) {
3378
+ return args.map((arg) => {
3379
+ if (!arg.startsWith("--inspect")) {
3380
+ return arg;
3381
+ }
3382
+ let debugOption;
3383
+ let debugHost = "127.0.0.1";
3384
+ let debugPort = "9229";
3385
+ let match;
3386
+ if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
3387
+ debugOption = match[1];
3388
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
3389
+ debugOption = match[1];
3390
+ if (/^\d+$/.test(match[3])) {
3391
+ debugPort = match[3];
3392
+ } else {
3393
+ debugHost = match[3];
3394
+ }
3395
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
3396
+ debugOption = match[1];
3397
+ debugHost = match[3];
3398
+ debugPort = match[4];
3399
+ }
3400
+ if (debugOption && debugPort !== "0") {
3401
+ return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
3402
+ }
3403
+ return arg;
3404
+ });
3405
+ }
3406
+ function useColor() {
3407
+ if (process.env.NO_COLOR || process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false")
3408
+ return false;
3409
+ if (process.env.FORCE_COLOR || process.env.CLICOLOR_FORCE !== void 0)
3410
+ return true;
3411
+ return void 0;
3412
+ }
3413
+ exports.Command = Command2;
3414
+ exports.useColor = useColor;
3415
+ }
3416
+ });
3417
+
3418
+ // node_modules/commander/index.js
3419
+ var require_commander = __commonJS({
3420
+ "node_modules/commander/index.js"(exports) {
3421
+ "use strict";
3422
+ var { Argument: Argument2 } = require_argument();
3423
+ var { Command: Command2 } = require_command();
3424
+ var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
3425
+ var { Help: Help2 } = require_help();
3426
+ var { Option: Option2 } = require_option();
3427
+ exports.program = new Command2();
3428
+ exports.createCommand = (name) => new Command2(name);
3429
+ exports.createOption = (flags, description) => new Option2(flags, description);
3430
+ exports.createArgument = (name, description) => new Argument2(name, description);
3431
+ exports.Command = Command2;
3432
+ exports.Option = Option2;
3433
+ exports.Argument = Argument2;
3434
+ exports.Help = Help2;
3435
+ exports.CommanderError = CommanderError2;
3436
+ exports.InvalidArgumentError = InvalidArgumentError2;
3437
+ exports.InvalidOptionArgumentError = InvalidArgumentError2;
3438
+ }
3439
+ });
3440
+
3441
+ // node_modules/commander/esm.mjs
3442
+ var import_index = __toESM(require_commander(), 1);
3443
+ var {
3444
+ program,
3445
+ createCommand,
3446
+ createArgument,
3447
+ createOption,
3448
+ CommanderError,
3449
+ InvalidArgumentError,
3450
+ InvalidOptionArgumentError,
3451
+ // deprecated old name
3452
+ Command,
3453
+ Argument,
3454
+ Option,
3455
+ Help
3456
+ } = import_index.default;
3457
+ export {
3458
+ Argument,
3459
+ Command,
3460
+ CommanderError,
3461
+ Help,
3462
+ InvalidArgumentError,
3463
+ InvalidOptionArgumentError,
3464
+ Option,
3465
+ createArgument,
3466
+ createCommand,
3467
+ createOption,
3468
+ program
3469
+ };