0sec-cli 0.15.0 → 0.18.0

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 (209) hide show
  1. package/0sec.js +327 -0
  2. package/README.md +68 -48
  3. package/attacks/data-exfiltration/pii-leakage.yaml +27 -0
  4. package/attacks/encoding-bypass/base64-encoding.yaml +24 -0
  5. package/attacks/jailbreak/dan-roleplay.yaml +27 -0
  6. package/attacks/jailbreak/hypothetical-scenario.yaml +25 -0
  7. package/attacks/jailbreak/multilingual-bypass.yaml +22 -0
  8. package/attacks/output-manipulation/harmful-content.yaml +25 -0
  9. package/attacks/prompt-injection/context-manipulation.yaml +32 -0
  10. package/attacks/prompt-injection/direct-injection.yaml +28 -0
  11. package/attacks/prompt-injection/indirect-injection.yaml +33 -0
  12. package/attacks/system-prompt-extraction/direct-ask.yaml +30 -0
  13. package/attacks/system-prompt-extraction/markdown-exfil.yaml +26 -0
  14. package/attacks/tool-misuse/ssrf-via-tools.yaml +27 -0
  15. package/chunks/adapt-loop-SMH6V4PD.js +18 -0
  16. package/chunks/adgraph-JLGA6RYI.js +54 -0
  17. package/chunks/agent/skills/frameworks/entra-id.yaml +63 -0
  18. package/chunks/agent/skills/frameworks/graphql-introspection.yaml +116 -0
  19. package/chunks/agent/skills/frameworks/nextjs.yaml +82 -0
  20. package/chunks/agent/skills/frameworks/python-web.yaml +85 -0
  21. package/chunks/agent/skills/frameworks/supabase.yaml +83 -0
  22. package/chunks/agent/skills/frameworks/wordpress-deep.yaml +122 -0
  23. package/chunks/agent/skills/techniques/ad-attack-paths.yaml +57 -0
  24. package/chunks/agent/skills/techniques/advisory-disclosure.yaml +59 -0
  25. package/chunks/agent/skills/techniques/assumption-mining.yaml +53 -0
  26. package/chunks/agent/skills/techniques/blind-exploitation.yaml +143 -0
  27. package/chunks/agent/skills/techniques/crypto-misuse.yaml +88 -0
  28. package/chunks/agent/skills/techniques/cve-poc-adaptation.yaml +82 -0
  29. package/chunks/agent/skills/techniques/entra-attack-paths.yaml +55 -0
  30. package/chunks/agent/skills/techniques/http-conformance-diff.yaml +48 -0
  31. package/chunks/agent/skills/techniques/jwt-attacks.yaml +137 -0
  32. package/chunks/agent/skills/techniques/kernel-weaponization.yaml +53 -0
  33. package/chunks/agent/skills/techniques/llm-excessive-agency.yaml +55 -0
  34. package/chunks/agent/skills/techniques/llm-insecure-output-handling.yaml +56 -0
  35. package/chunks/agent/skills/techniques/llm-prompt-injection.yaml +54 -0
  36. package/chunks/agent/skills/techniques/llm-prompt-layer-write.yaml +68 -0
  37. package/chunks/agent/skills/techniques/llm-rag-poisoning.yaml +57 -0
  38. package/chunks/agent/skills/techniques/llm-safety-eval.yaml +51 -0
  39. package/chunks/agent/skills/techniques/npm-ecosystem.yaml +51 -0
  40. package/chunks/agent/skills/techniques/poc-verification.yaml +55 -0
  41. package/chunks/agent/skills/techniques/race-condition.yaml +122 -0
  42. package/chunks/agent/skills/techniques/scoped-fix.yaml +49 -0
  43. package/chunks/agent/skills/techniques/seedless-depth-review.yaml +59 -0
  44. package/chunks/agent/skills/techniques/spec-differential.yaml +48 -0
  45. package/chunks/agent/skills/techniques/variant-hunting.yaml +55 -0
  46. package/chunks/agent/skills/vulnerabilities/cardano-eutxo-validators.yaml +72 -0
  47. package/chunks/agent/skills/vulnerabilities/command-injection.yaml +99 -0
  48. package/chunks/agent/skills/vulnerabilities/deserialization-chains.yaml +106 -0
  49. package/chunks/agent/skills/vulnerabilities/native-memory-safety.yaml +93 -0
  50. package/chunks/agent/skills/vulnerabilities/path-traversal.yaml +78 -0
  51. package/chunks/agent/skills/vulnerabilities/prototype-pollution.yaml +132 -0
  52. package/chunks/agent/skills/vulnerabilities/request-smuggling.yaml +129 -0
  53. package/chunks/agent/skills/vulnerabilities/sqli-advanced.yaml +102 -0
  54. package/chunks/agent/skills/vulnerabilities/ssrf-bypass.yaml +84 -0
  55. package/chunks/agent/skills/vulnerabilities/ssti-exploitation.yaml +112 -0
  56. package/chunks/agent/skills/vulnerabilities/structural-sqli.yaml +91 -0
  57. package/chunks/appsec-catalog-CBWHGTEL.js +24 -0
  58. package/chunks/artifact-scraper-HQ7HLP6V.js +34 -0
  59. package/chunks/assumption-mining-5SNIVVDN.js +79 -0
  60. package/chunks/chunk-242TMK6G.js +110 -0
  61. package/chunks/chunk-2JCCA2JL.js +381 -0
  62. package/chunks/chunk-2RMLOJVB.js +47 -0
  63. package/chunks/chunk-3KPWWJCI.js +1422 -0
  64. package/chunks/chunk-3MOLBTLS.js +953 -0
  65. package/chunks/chunk-53G27VPS.js +136 -0
  66. package/chunks/chunk-57ZENEX2.js +169 -0
  67. package/chunks/chunk-5G3ZXFBW.js +182 -0
  68. package/chunks/chunk-5JI7L7KV.js +74240 -0
  69. package/chunks/chunk-6L26OBWI.js +1094 -0
  70. package/chunks/chunk-6LKRLK2R.js +542 -0
  71. package/chunks/chunk-72CISA2D.js +2597 -0
  72. package/chunks/chunk-7DQEV5QI.js +287 -0
  73. package/chunks/chunk-AD7WXDH6.js +3250 -0
  74. package/chunks/chunk-ADOLI6DT.js +102 -0
  75. package/chunks/chunk-AHTBZC3E.js +596 -0
  76. package/chunks/chunk-ASUR522M.js +518 -0
  77. package/chunks/chunk-ATATQACO.js +471 -0
  78. package/chunks/chunk-BATRQBOR.js +1732 -0
  79. package/chunks/chunk-BFR2CDV5.js +5735 -0
  80. package/chunks/chunk-BFRB6HB2.js +235 -0
  81. package/chunks/chunk-BKZFDZ23.js +361 -0
  82. package/chunks/chunk-BVAZO4WA.js +193 -0
  83. package/chunks/chunk-BZNEY2ZS.js +33225 -0
  84. package/chunks/chunk-C2WXWFBB.js +1070 -0
  85. package/chunks/chunk-CMKXP5RR.js +917 -0
  86. package/chunks/chunk-DW5UWPFY.js +275 -0
  87. package/chunks/chunk-F3WBKITT.js +687 -0
  88. package/chunks/chunk-GMT2AZKM.js +2439 -0
  89. package/chunks/chunk-H2FFLZNK.js +3 -0
  90. package/chunks/chunk-IOL7D5YV.js +515 -0
  91. package/chunks/chunk-IR537GON.js +49 -0
  92. package/chunks/chunk-JQHOLLTD.js +3729 -0
  93. package/chunks/chunk-KLTNTE2Z.js +121 -0
  94. package/chunks/chunk-LP3HHYQU.js +245 -0
  95. package/chunks/chunk-MYVT64FN.js +16 -0
  96. package/chunks/chunk-N7BOUYEV.js +852 -0
  97. package/chunks/chunk-OEFNRYI2.js +150 -0
  98. package/chunks/chunk-P6WKNFWX.js +1968 -0
  99. package/chunks/chunk-QI233I24.js +333 -0
  100. package/chunks/chunk-RJWOYEOG.js +271 -0
  101. package/chunks/chunk-RRMJC3ZE.js +105 -0
  102. package/chunks/chunk-RWONANDA.js +973 -0
  103. package/chunks/chunk-SAFFWQW4.js +5921 -0
  104. package/chunks/chunk-SF4KZ4O3.js +502 -0
  105. package/chunks/chunk-SVJEDVYK.js +808 -0
  106. package/chunks/chunk-TSK2AG6J.js +5108 -0
  107. package/chunks/chunk-U5FLXGHT.js +2010 -0
  108. package/chunks/chunk-UCYRA73C.js +662 -0
  109. package/chunks/chunk-UR4ELX2Y.js +4784 -0
  110. package/chunks/chunk-VQG4FT5D.js +685 -0
  111. package/chunks/chunk-WEBMRWEG.js +9337 -0
  112. package/chunks/chunk-WU6AFRAZ.js +1167 -0
  113. package/chunks/chunk-WVTBZEQO.js +1531 -0
  114. package/chunks/chunk-WXQ6BJ6A.js +596 -0
  115. package/chunks/chunk-XM5NLHYU.js +600 -0
  116. package/chunks/chunk-YLMN3N25.js +4054 -0
  117. package/chunks/chunk-YYRBQVFE.js +2572 -0
  118. package/chunks/chunk-Z5FA2XOX.js +2798 -0
  119. package/chunks/commands-TBC2F5CE.js +16999 -0
  120. package/chunks/corpus-v1.json +403 -0
  121. package/chunks/cost-ledger-NU63MYZM.js +13 -0
  122. package/chunks/data/appsec-archetypes.json +102 -0
  123. package/chunks/data/chromium-archetypes.json +204 -0
  124. package/chunks/data/freebsd-archetypes.json +171 -0
  125. package/chunks/data/kernel-archetypes.json +611 -0
  126. package/chunks/db-KFWOAUUB.js +16 -0
  127. package/chunks/disclose-EKTWSCGW.js +132 -0
  128. package/chunks/dist-4MAW5X6L.js +74 -0
  129. package/chunks/dist-4YICS2J2.js +2776 -0
  130. package/chunks/dist-FMGSR3DW.js +159 -0
  131. package/chunks/eval-runner-7ZF472KV.js +27 -0
  132. package/chunks/example-manifest.json +95 -0
  133. package/chunks/exploit-agent-45YQOHPJ.js +98 -0
  134. package/chunks/exploit-autoclimb-UZGEMGYT.js +81 -0
  135. package/chunks/exploit-climb-SG23KB2G.js +358 -0
  136. package/chunks/fix-IG7LYXH3.js +12 -0
  137. package/chunks/github-issues-MJ6OYOOU.js +157 -0
  138. package/chunks/harness-7ODOLOWU.js +22 -0
  139. package/chunks/http-conformance-DU66MZIU.js +11 -0
  140. package/chunks/http-sender-GWH2IYEA.js +10 -0
  141. package/chunks/hunt-scan-MMKUOETU.js +38 -0
  142. package/chunks/identity-6ZAIIWOR.js +191 -0
  143. package/chunks/kernel-primitive-7U6CWHXD.js +44 -0
  144. package/chunks/kernel-vm-runner-3JAU4O6J.js +62 -0
  145. package/chunks/memsafety-scan-J7SECV5W.js +16 -0
  146. package/chunks/native-loop-RJCJPOUS.js +54 -0
  147. package/chunks/npm-detectors-KB5Y5ZFX.js +69 -0
  148. package/chunks/npm-dynamic-discovery-AHROOZDB.js +13 -0
  149. package/chunks/orchestrate-OC2VZN2X.js +62 -0
  150. package/chunks/pipeline-BZK5BLJR.js +14 -0
  151. package/chunks/pre-recon-cve-66EB6G4M.js +351 -0
  152. package/chunks/prepare-MYY743TK.js +13 -0
  153. package/chunks/process-LQRCS5OY.js +13 -0
  154. package/chunks/replay-runner-45G3VU7X.js +39 -0
  155. package/chunks/run-D56MPDKY.js +32716 -0
  156. package/chunks/runtime-G7YWIO3B.js +43 -0
  157. package/chunks/runtime-J7PLXZNM.js +12 -0
  158. package/chunks/scan-stream-FHI2FYZE.js +96 -0
  159. package/chunks/scope-BI7BF4ZY.js +18 -0
  160. package/chunks/session-store-GZ4A4KYT.js +28 -0
  161. package/chunks/source-files-PWRQR6LY.js +12 -0
  162. package/chunks/specdrift-WCLH6TTQ.js +19 -0
  163. package/chunks/variant-candidates-YERCYMPD.js +13 -0
  164. package/chunks/web-recon-prepass-JJGPEOLE.js +1148 -0
  165. package/dashboard/assets/0sec-icon-66SreztZ.gif +0 -0
  166. package/dashboard/assets/bot-yILPnRgD.js +1 -0
  167. package/dashboard/assets/chevron-down-BeDJ-Vka.js +1 -0
  168. package/dashboard/assets/circle-alert-BEnMBMT-.js +1 -0
  169. package/dashboard/assets/client-DRYsuOGl.js +9 -0
  170. package/dashboard/assets/copy-Bi5vzoF9.js +1 -0
  171. package/dashboard/assets/desktop-CXTQonNm.js +32 -0
  172. package/dashboard/assets/desktop-NOekk4QS.css +1 -0
  173. package/dashboard/assets/dist-CmX-h7a4.js +1 -0
  174. package/dashboard/assets/dist-DAwYQmf_.js +45 -0
  175. package/dashboard/assets/findings-page-CACW9nw2.js +5 -0
  176. package/dashboard/assets/format-PoISqsES.js +1 -0
  177. package/dashboard/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  178. package/dashboard/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  179. package/dashboard/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  180. package/dashboard/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  181. package/dashboard/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  182. package/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  183. package/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  184. package/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  185. package/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  186. package/dashboard/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  187. package/dashboard/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  188. package/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  189. package/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  190. package/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  191. package/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  192. package/dashboard/assets/jsx-runtime-C7oxC63R.js +1 -0
  193. package/dashboard/assets/live-page-DrgQqQK5.js +1 -0
  194. package/dashboard/assets/meta-tile-CcskIV_o.js +1 -0
  195. package/dashboard/assets/operations-BKE8T-vY.css +2 -0
  196. package/dashboard/assets/operations-D8nUP5_m.js +4 -0
  197. package/dashboard/assets/operations-app-CQQhG54n.js +2 -0
  198. package/dashboard/assets/overview-page-DTGS8dPo.js +1 -0
  199. package/dashboard/assets/page-header-MFVvEtZW.js +1 -0
  200. package/dashboard/assets/play-Dwo-9xt6.js +1 -0
  201. package/dashboard/assets/scans-page-ChVtq8Us.js +1 -0
  202. package/dashboard/assets/search-CiooTLck.js +1 -0
  203. package/dashboard/assets/siren-CCBwTSuk.js +1 -0
  204. package/dashboard/assets/table-BYS-nIVA.js +1 -0
  205. package/dashboard/assets/tabs-DivxbhQy.js +1 -0
  206. package/dashboard/desktop.html +21 -0
  207. package/dashboard/index.html +15 -0
  208. package/package.json +30 -18
  209. package/bin/0sec.cjs +0 -361
@@ -0,0 +1,3250 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __0secCreateRequire } from "node:module";
3
+ const require = __0secCreateRequire(import.meta.url);
4
+ import {
5
+ loadLayeredSettings
6
+ } from "./chunk-GMT2AZKM.js";
7
+ import {
8
+ homeStateDir
9
+ } from "./chunk-6L26OBWI.js";
10
+ import {
11
+ __commonJS,
12
+ __require,
13
+ __toESM
14
+ } from "./chunk-IR537GON.js";
15
+
16
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/error.js
17
+ var require_error = __commonJS({
18
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/error.js"(exports) {
19
+ var CommanderError2 = class extends Error {
20
+ /**
21
+ * Constructs the CommanderError class
22
+ * @param {number} exitCode suggested exit code which could be used with process.exit
23
+ * @param {string} code an id string representing the error
24
+ * @param {string} message human-readable description of the error
25
+ */
26
+ constructor(exitCode, code, message) {
27
+ super(message);
28
+ Error.captureStackTrace(this, this.constructor);
29
+ this.name = this.constructor.name;
30
+ this.code = code;
31
+ this.exitCode = exitCode;
32
+ this.nestedError = void 0;
33
+ }
34
+ };
35
+ var InvalidArgumentError2 = class extends CommanderError2 {
36
+ /**
37
+ * Constructs the InvalidArgumentError class
38
+ * @param {string} [message] explanation of why argument is invalid
39
+ */
40
+ constructor(message) {
41
+ super(1, "commander.invalidArgument", message);
42
+ Error.captureStackTrace(this, this.constructor);
43
+ this.name = this.constructor.name;
44
+ }
45
+ };
46
+ exports.CommanderError = CommanderError2;
47
+ exports.InvalidArgumentError = InvalidArgumentError2;
48
+ }
49
+ });
50
+
51
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/argument.js
52
+ var require_argument = __commonJS({
53
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/argument.js"(exports) {
54
+ var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
55
+ var Argument2 = class {
56
+ /**
57
+ * Initialize a new command argument with the given name and description.
58
+ * The default is that the argument is required, and you can explicitly
59
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
60
+ *
61
+ * @param {string} name
62
+ * @param {string} [description]
63
+ */
64
+ constructor(name, description) {
65
+ this.description = description || "";
66
+ this.variadic = false;
67
+ this.parseArg = void 0;
68
+ this.defaultValue = void 0;
69
+ this.defaultValueDescription = void 0;
70
+ this.argChoices = void 0;
71
+ switch (name[0]) {
72
+ case "<":
73
+ this.required = true;
74
+ this._name = name.slice(1, -1);
75
+ break;
76
+ case "[":
77
+ this.required = false;
78
+ this._name = name.slice(1, -1);
79
+ break;
80
+ default:
81
+ this.required = true;
82
+ this._name = name;
83
+ break;
84
+ }
85
+ if (this._name.length > 3 && this._name.slice(-3) === "...") {
86
+ this.variadic = true;
87
+ this._name = this._name.slice(0, -3);
88
+ }
89
+ }
90
+ /**
91
+ * Return argument name.
92
+ *
93
+ * @return {string}
94
+ */
95
+ name() {
96
+ return this._name;
97
+ }
98
+ /**
99
+ * @package
100
+ */
101
+ _concatValue(value, previous) {
102
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
103
+ return [value];
104
+ }
105
+ return previous.concat(value);
106
+ }
107
+ /**
108
+ * Set the default value, and optionally supply the description to be displayed in the help.
109
+ *
110
+ * @param {*} value
111
+ * @param {string} [description]
112
+ * @return {Argument}
113
+ */
114
+ default(value, description) {
115
+ this.defaultValue = value;
116
+ this.defaultValueDescription = description;
117
+ return this;
118
+ }
119
+ /**
120
+ * Set the custom handler for processing CLI command arguments into argument values.
121
+ *
122
+ * @param {Function} [fn]
123
+ * @return {Argument}
124
+ */
125
+ argParser(fn) {
126
+ this.parseArg = fn;
127
+ return this;
128
+ }
129
+ /**
130
+ * Only allow argument value to be one of choices.
131
+ *
132
+ * @param {string[]} values
133
+ * @return {Argument}
134
+ */
135
+ choices(values) {
136
+ this.argChoices = values.slice();
137
+ this.parseArg = (arg, previous) => {
138
+ if (!this.argChoices.includes(arg)) {
139
+ throw new InvalidArgumentError2(
140
+ `Allowed choices are ${this.argChoices.join(", ")}.`
141
+ );
142
+ }
143
+ if (this.variadic) {
144
+ return this._concatValue(arg, previous);
145
+ }
146
+ return arg;
147
+ };
148
+ return this;
149
+ }
150
+ /**
151
+ * Make argument required.
152
+ *
153
+ * @returns {Argument}
154
+ */
155
+ argRequired() {
156
+ this.required = true;
157
+ return this;
158
+ }
159
+ /**
160
+ * Make argument optional.
161
+ *
162
+ * @returns {Argument}
163
+ */
164
+ argOptional() {
165
+ this.required = false;
166
+ return this;
167
+ }
168
+ };
169
+ function humanReadableArgName(arg) {
170
+ const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
171
+ return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
172
+ }
173
+ exports.Argument = Argument2;
174
+ exports.humanReadableArgName = humanReadableArgName;
175
+ }
176
+ });
177
+
178
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/help.js
179
+ var require_help = __commonJS({
180
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/help.js"(exports) {
181
+ var { humanReadableArgName } = require_argument();
182
+ var Help2 = class {
183
+ constructor() {
184
+ this.helpWidth = void 0;
185
+ this.sortSubcommands = false;
186
+ this.sortOptions = false;
187
+ this.showGlobalOptions = false;
188
+ }
189
+ /**
190
+ * Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
191
+ *
192
+ * @param {Command} cmd
193
+ * @returns {Command[]}
194
+ */
195
+ visibleCommands(cmd) {
196
+ const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
197
+ const helpCommand = cmd._getHelpCommand();
198
+ if (helpCommand && !helpCommand._hidden) {
199
+ visibleCommands.push(helpCommand);
200
+ }
201
+ if (this.sortSubcommands) {
202
+ visibleCommands.sort((a, b) => {
203
+ return a.name().localeCompare(b.name());
204
+ });
205
+ }
206
+ return visibleCommands;
207
+ }
208
+ /**
209
+ * Compare options for sort.
210
+ *
211
+ * @param {Option} a
212
+ * @param {Option} b
213
+ * @returns {number}
214
+ */
215
+ compareOptions(a, b) {
216
+ const getSortKey = (option) => {
217
+ return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
218
+ };
219
+ return getSortKey(a).localeCompare(getSortKey(b));
220
+ }
221
+ /**
222
+ * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
223
+ *
224
+ * @param {Command} cmd
225
+ * @returns {Option[]}
226
+ */
227
+ visibleOptions(cmd) {
228
+ const visibleOptions = cmd.options.filter((option) => !option.hidden);
229
+ const helpOption = cmd._getHelpOption();
230
+ if (helpOption && !helpOption.hidden) {
231
+ const removeShort = helpOption.short && cmd._findOption(helpOption.short);
232
+ const removeLong = helpOption.long && cmd._findOption(helpOption.long);
233
+ if (!removeShort && !removeLong) {
234
+ visibleOptions.push(helpOption);
235
+ } else if (helpOption.long && !removeLong) {
236
+ visibleOptions.push(
237
+ cmd.createOption(helpOption.long, helpOption.description)
238
+ );
239
+ } else if (helpOption.short && !removeShort) {
240
+ visibleOptions.push(
241
+ cmd.createOption(helpOption.short, helpOption.description)
242
+ );
243
+ }
244
+ }
245
+ if (this.sortOptions) {
246
+ visibleOptions.sort(this.compareOptions);
247
+ }
248
+ return visibleOptions;
249
+ }
250
+ /**
251
+ * Get an array of the visible global options. (Not including help.)
252
+ *
253
+ * @param {Command} cmd
254
+ * @returns {Option[]}
255
+ */
256
+ visibleGlobalOptions(cmd) {
257
+ if (!this.showGlobalOptions) return [];
258
+ const globalOptions = [];
259
+ for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
260
+ const visibleOptions = ancestorCmd.options.filter(
261
+ (option) => !option.hidden
262
+ );
263
+ globalOptions.push(...visibleOptions);
264
+ }
265
+ if (this.sortOptions) {
266
+ globalOptions.sort(this.compareOptions);
267
+ }
268
+ return globalOptions;
269
+ }
270
+ /**
271
+ * Get an array of the arguments if any have a description.
272
+ *
273
+ * @param {Command} cmd
274
+ * @returns {Argument[]}
275
+ */
276
+ visibleArguments(cmd) {
277
+ if (cmd._argsDescription) {
278
+ cmd.registeredArguments.forEach((argument) => {
279
+ argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
280
+ });
281
+ }
282
+ if (cmd.registeredArguments.find((argument) => argument.description)) {
283
+ return cmd.registeredArguments;
284
+ }
285
+ return [];
286
+ }
287
+ /**
288
+ * Get the command term to show in the list of subcommands.
289
+ *
290
+ * @param {Command} cmd
291
+ * @returns {string}
292
+ */
293
+ subcommandTerm(cmd) {
294
+ const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
295
+ return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
296
+ (args ? " " + args : "");
297
+ }
298
+ /**
299
+ * Get the option term to show in the list of options.
300
+ *
301
+ * @param {Option} option
302
+ * @returns {string}
303
+ */
304
+ optionTerm(option) {
305
+ return option.flags;
306
+ }
307
+ /**
308
+ * Get the argument term to show in the list of arguments.
309
+ *
310
+ * @param {Argument} argument
311
+ * @returns {string}
312
+ */
313
+ argumentTerm(argument) {
314
+ return argument.name();
315
+ }
316
+ /**
317
+ * Get the longest command term length.
318
+ *
319
+ * @param {Command} cmd
320
+ * @param {Help} helper
321
+ * @returns {number}
322
+ */
323
+ longestSubcommandTermLength(cmd, helper) {
324
+ return helper.visibleCommands(cmd).reduce((max, command) => {
325
+ return Math.max(max, helper.subcommandTerm(command).length);
326
+ }, 0);
327
+ }
328
+ /**
329
+ * Get the longest option term length.
330
+ *
331
+ * @param {Command} cmd
332
+ * @param {Help} helper
333
+ * @returns {number}
334
+ */
335
+ longestOptionTermLength(cmd, helper) {
336
+ return helper.visibleOptions(cmd).reduce((max, option) => {
337
+ return Math.max(max, helper.optionTerm(option).length);
338
+ }, 0);
339
+ }
340
+ /**
341
+ * Get the longest global option term length.
342
+ *
343
+ * @param {Command} cmd
344
+ * @param {Help} helper
345
+ * @returns {number}
346
+ */
347
+ longestGlobalOptionTermLength(cmd, helper) {
348
+ return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
349
+ return Math.max(max, helper.optionTerm(option).length);
350
+ }, 0);
351
+ }
352
+ /**
353
+ * Get the longest argument term length.
354
+ *
355
+ * @param {Command} cmd
356
+ * @param {Help} helper
357
+ * @returns {number}
358
+ */
359
+ longestArgumentTermLength(cmd, helper) {
360
+ return helper.visibleArguments(cmd).reduce((max, argument) => {
361
+ return Math.max(max, helper.argumentTerm(argument).length);
362
+ }, 0);
363
+ }
364
+ /**
365
+ * Get the command usage to be displayed at the top of the built-in help.
366
+ *
367
+ * @param {Command} cmd
368
+ * @returns {string}
369
+ */
370
+ commandUsage(cmd) {
371
+ let cmdName = cmd._name;
372
+ if (cmd._aliases[0]) {
373
+ cmdName = cmdName + "|" + cmd._aliases[0];
374
+ }
375
+ let ancestorCmdNames = "";
376
+ for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
377
+ ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
378
+ }
379
+ return ancestorCmdNames + cmdName + " " + cmd.usage();
380
+ }
381
+ /**
382
+ * Get the description for the command.
383
+ *
384
+ * @param {Command} cmd
385
+ * @returns {string}
386
+ */
387
+ commandDescription(cmd) {
388
+ return cmd.description();
389
+ }
390
+ /**
391
+ * Get the subcommand summary to show in the list of subcommands.
392
+ * (Fallback to description for backwards compatibility.)
393
+ *
394
+ * @param {Command} cmd
395
+ * @returns {string}
396
+ */
397
+ subcommandDescription(cmd) {
398
+ return cmd.summary() || cmd.description();
399
+ }
400
+ /**
401
+ * Get the option description to show in the list of options.
402
+ *
403
+ * @param {Option} option
404
+ * @return {string}
405
+ */
406
+ optionDescription(option) {
407
+ const extraInfo = [];
408
+ if (option.argChoices) {
409
+ extraInfo.push(
410
+ // use stringify to match the display of the default value
411
+ `choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
412
+ );
413
+ }
414
+ if (option.defaultValue !== void 0) {
415
+ const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
416
+ if (showDefault) {
417
+ extraInfo.push(
418
+ `default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
419
+ );
420
+ }
421
+ }
422
+ if (option.presetArg !== void 0 && option.optional) {
423
+ extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
424
+ }
425
+ if (option.envVar !== void 0) {
426
+ extraInfo.push(`env: ${option.envVar}`);
427
+ }
428
+ if (extraInfo.length > 0) {
429
+ return `${option.description} (${extraInfo.join(", ")})`;
430
+ }
431
+ return option.description;
432
+ }
433
+ /**
434
+ * Get the argument description to show in the list of arguments.
435
+ *
436
+ * @param {Argument} argument
437
+ * @return {string}
438
+ */
439
+ argumentDescription(argument) {
440
+ const extraInfo = [];
441
+ if (argument.argChoices) {
442
+ extraInfo.push(
443
+ // use stringify to match the display of the default value
444
+ `choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
445
+ );
446
+ }
447
+ if (argument.defaultValue !== void 0) {
448
+ extraInfo.push(
449
+ `default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
450
+ );
451
+ }
452
+ if (extraInfo.length > 0) {
453
+ const extraDescripton = `(${extraInfo.join(", ")})`;
454
+ if (argument.description) {
455
+ return `${argument.description} ${extraDescripton}`;
456
+ }
457
+ return extraDescripton;
458
+ }
459
+ return argument.description;
460
+ }
461
+ /**
462
+ * Generate the built-in help text.
463
+ *
464
+ * @param {Command} cmd
465
+ * @param {Help} helper
466
+ * @returns {string}
467
+ */
468
+ formatHelp(cmd, helper) {
469
+ const termWidth = helper.padWidth(cmd, helper);
470
+ const helpWidth = helper.helpWidth || 80;
471
+ const itemIndentWidth = 2;
472
+ const itemSeparatorWidth = 2;
473
+ function formatItem(term, description) {
474
+ if (description) {
475
+ const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
476
+ return helper.wrap(
477
+ fullText,
478
+ helpWidth - itemIndentWidth,
479
+ termWidth + itemSeparatorWidth
480
+ );
481
+ }
482
+ return term;
483
+ }
484
+ function formatList(textArray) {
485
+ return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
486
+ }
487
+ let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
488
+ const commandDescription = helper.commandDescription(cmd);
489
+ if (commandDescription.length > 0) {
490
+ output = output.concat([
491
+ helper.wrap(commandDescription, helpWidth, 0),
492
+ ""
493
+ ]);
494
+ }
495
+ const argumentList = helper.visibleArguments(cmd).map((argument) => {
496
+ return formatItem(
497
+ helper.argumentTerm(argument),
498
+ helper.argumentDescription(argument)
499
+ );
500
+ });
501
+ if (argumentList.length > 0) {
502
+ output = output.concat(["Arguments:", formatList(argumentList), ""]);
503
+ }
504
+ const optionList = helper.visibleOptions(cmd).map((option) => {
505
+ return formatItem(
506
+ helper.optionTerm(option),
507
+ helper.optionDescription(option)
508
+ );
509
+ });
510
+ if (optionList.length > 0) {
511
+ output = output.concat(["Options:", formatList(optionList), ""]);
512
+ }
513
+ if (this.showGlobalOptions) {
514
+ const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
515
+ return formatItem(
516
+ helper.optionTerm(option),
517
+ helper.optionDescription(option)
518
+ );
519
+ });
520
+ if (globalOptionList.length > 0) {
521
+ output = output.concat([
522
+ "Global Options:",
523
+ formatList(globalOptionList),
524
+ ""
525
+ ]);
526
+ }
527
+ }
528
+ const commandList = helper.visibleCommands(cmd).map((cmd2) => {
529
+ return formatItem(
530
+ helper.subcommandTerm(cmd2),
531
+ helper.subcommandDescription(cmd2)
532
+ );
533
+ });
534
+ if (commandList.length > 0) {
535
+ output = output.concat(["Commands:", formatList(commandList), ""]);
536
+ }
537
+ return output.join("\n");
538
+ }
539
+ /**
540
+ * Calculate the pad width from the maximum term length.
541
+ *
542
+ * @param {Command} cmd
543
+ * @param {Help} helper
544
+ * @returns {number}
545
+ */
546
+ padWidth(cmd, helper) {
547
+ return Math.max(
548
+ helper.longestOptionTermLength(cmd, helper),
549
+ helper.longestGlobalOptionTermLength(cmd, helper),
550
+ helper.longestSubcommandTermLength(cmd, helper),
551
+ helper.longestArgumentTermLength(cmd, helper)
552
+ );
553
+ }
554
+ /**
555
+ * Wrap the given string to width characters per line, with lines after the first indented.
556
+ * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
557
+ *
558
+ * @param {string} str
559
+ * @param {number} width
560
+ * @param {number} indent
561
+ * @param {number} [minColumnWidth=40]
562
+ * @return {string}
563
+ *
564
+ */
565
+ wrap(str, width, indent, minColumnWidth = 40) {
566
+ const indents = " \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF";
567
+ const manualIndent = new RegExp(`[\\n][${indents}]+`);
568
+ if (str.match(manualIndent)) return str;
569
+ const columnWidth = width - indent;
570
+ if (columnWidth < minColumnWidth) return str;
571
+ const leadingStr = str.slice(0, indent);
572
+ const columnText = str.slice(indent).replace("\r\n", "\n");
573
+ const indentString = " ".repeat(indent);
574
+ const zeroWidthSpace = "\u200B";
575
+ const breaks = `\\s${zeroWidthSpace}`;
576
+ const regex = new RegExp(
577
+ `
578
+ |.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
579
+ "g"
580
+ );
581
+ const lines = columnText.match(regex) || [];
582
+ return leadingStr + lines.map((line, i) => {
583
+ if (line === "\n") return "";
584
+ return (i > 0 ? indentString : "") + line.trimEnd();
585
+ }).join("\n");
586
+ }
587
+ };
588
+ exports.Help = Help2;
589
+ }
590
+ });
591
+
592
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/option.js
593
+ var require_option = __commonJS({
594
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/option.js"(exports) {
595
+ var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
596
+ var Option2 = class {
597
+ /**
598
+ * Initialize a new `Option` with the given `flags` and `description`.
599
+ *
600
+ * @param {string} flags
601
+ * @param {string} [description]
602
+ */
603
+ constructor(flags, description) {
604
+ this.flags = flags;
605
+ this.description = description || "";
606
+ this.required = flags.includes("<");
607
+ this.optional = flags.includes("[");
608
+ this.variadic = /\w\.\.\.[>\]]$/.test(flags);
609
+ this.mandatory = false;
610
+ const optionFlags = splitOptionFlags(flags);
611
+ this.short = optionFlags.shortFlag;
612
+ this.long = optionFlags.longFlag;
613
+ this.negate = false;
614
+ if (this.long) {
615
+ this.negate = this.long.startsWith("--no-");
616
+ }
617
+ this.defaultValue = void 0;
618
+ this.defaultValueDescription = void 0;
619
+ this.presetArg = void 0;
620
+ this.envVar = void 0;
621
+ this.parseArg = void 0;
622
+ this.hidden = false;
623
+ this.argChoices = void 0;
624
+ this.conflictsWith = [];
625
+ this.implied = void 0;
626
+ }
627
+ /**
628
+ * Set the default value, and optionally supply the description to be displayed in the help.
629
+ *
630
+ * @param {*} value
631
+ * @param {string} [description]
632
+ * @return {Option}
633
+ */
634
+ default(value, description) {
635
+ this.defaultValue = value;
636
+ this.defaultValueDescription = description;
637
+ return this;
638
+ }
639
+ /**
640
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
641
+ * The custom processing (parseArg) is called.
642
+ *
643
+ * @example
644
+ * new Option('--color').default('GREYSCALE').preset('RGB');
645
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
646
+ *
647
+ * @param {*} arg
648
+ * @return {Option}
649
+ */
650
+ preset(arg) {
651
+ this.presetArg = arg;
652
+ return this;
653
+ }
654
+ /**
655
+ * Add option name(s) that conflict with this option.
656
+ * An error will be displayed if conflicting options are found during parsing.
657
+ *
658
+ * @example
659
+ * new Option('--rgb').conflicts('cmyk');
660
+ * new Option('--js').conflicts(['ts', 'jsx']);
661
+ *
662
+ * @param {(string | string[])} names
663
+ * @return {Option}
664
+ */
665
+ conflicts(names) {
666
+ this.conflictsWith = this.conflictsWith.concat(names);
667
+ return this;
668
+ }
669
+ /**
670
+ * Specify implied option values for when this option is set and the implied options are not.
671
+ *
672
+ * The custom processing (parseArg) is not called on the implied values.
673
+ *
674
+ * @example
675
+ * program
676
+ * .addOption(new Option('--log', 'write logging information to file'))
677
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
678
+ *
679
+ * @param {object} impliedOptionValues
680
+ * @return {Option}
681
+ */
682
+ implies(impliedOptionValues) {
683
+ let newImplied = impliedOptionValues;
684
+ if (typeof impliedOptionValues === "string") {
685
+ newImplied = { [impliedOptionValues]: true };
686
+ }
687
+ this.implied = Object.assign(this.implied || {}, newImplied);
688
+ return this;
689
+ }
690
+ /**
691
+ * Set environment variable to check for option value.
692
+ *
693
+ * An environment variable is only used if when processed the current option value is
694
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
695
+ *
696
+ * @param {string} name
697
+ * @return {Option}
698
+ */
699
+ env(name) {
700
+ this.envVar = name;
701
+ return this;
702
+ }
703
+ /**
704
+ * Set the custom handler for processing CLI option arguments into option values.
705
+ *
706
+ * @param {Function} [fn]
707
+ * @return {Option}
708
+ */
709
+ argParser(fn) {
710
+ this.parseArg = fn;
711
+ return this;
712
+ }
713
+ /**
714
+ * Whether the option is mandatory and must have a value after parsing.
715
+ *
716
+ * @param {boolean} [mandatory=true]
717
+ * @return {Option}
718
+ */
719
+ makeOptionMandatory(mandatory = true) {
720
+ this.mandatory = !!mandatory;
721
+ return this;
722
+ }
723
+ /**
724
+ * Hide option in help.
725
+ *
726
+ * @param {boolean} [hide=true]
727
+ * @return {Option}
728
+ */
729
+ hideHelp(hide = true) {
730
+ this.hidden = !!hide;
731
+ return this;
732
+ }
733
+ /**
734
+ * @package
735
+ */
736
+ _concatValue(value, previous) {
737
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
738
+ return [value];
739
+ }
740
+ return previous.concat(value);
741
+ }
742
+ /**
743
+ * Only allow option value to be one of choices.
744
+ *
745
+ * @param {string[]} values
746
+ * @return {Option}
747
+ */
748
+ choices(values) {
749
+ this.argChoices = values.slice();
750
+ this.parseArg = (arg, previous) => {
751
+ if (!this.argChoices.includes(arg)) {
752
+ throw new InvalidArgumentError2(
753
+ `Allowed choices are ${this.argChoices.join(", ")}.`
754
+ );
755
+ }
756
+ if (this.variadic) {
757
+ return this._concatValue(arg, previous);
758
+ }
759
+ return arg;
760
+ };
761
+ return this;
762
+ }
763
+ /**
764
+ * Return option name.
765
+ *
766
+ * @return {string}
767
+ */
768
+ name() {
769
+ if (this.long) {
770
+ return this.long.replace(/^--/, "");
771
+ }
772
+ return this.short.replace(/^-/, "");
773
+ }
774
+ /**
775
+ * Return option name, in a camelcase format that can be used
776
+ * as a object attribute key.
777
+ *
778
+ * @return {string}
779
+ */
780
+ attributeName() {
781
+ return camelcase(this.name().replace(/^no-/, ""));
782
+ }
783
+ /**
784
+ * Check if `arg` matches the short or long flag.
785
+ *
786
+ * @param {string} arg
787
+ * @return {boolean}
788
+ * @package
789
+ */
790
+ is(arg) {
791
+ return this.short === arg || this.long === arg;
792
+ }
793
+ /**
794
+ * Return whether a boolean option.
795
+ *
796
+ * Options are one of boolean, negated, required argument, or optional argument.
797
+ *
798
+ * @return {boolean}
799
+ * @package
800
+ */
801
+ isBoolean() {
802
+ return !this.required && !this.optional && !this.negate;
803
+ }
804
+ };
805
+ var DualOptions = class {
806
+ /**
807
+ * @param {Option[]} options
808
+ */
809
+ constructor(options) {
810
+ this.positiveOptions = /* @__PURE__ */ new Map();
811
+ this.negativeOptions = /* @__PURE__ */ new Map();
812
+ this.dualOptions = /* @__PURE__ */ new Set();
813
+ options.forEach((option) => {
814
+ if (option.negate) {
815
+ this.negativeOptions.set(option.attributeName(), option);
816
+ } else {
817
+ this.positiveOptions.set(option.attributeName(), option);
818
+ }
819
+ });
820
+ this.negativeOptions.forEach((value, key) => {
821
+ if (this.positiveOptions.has(key)) {
822
+ this.dualOptions.add(key);
823
+ }
824
+ });
825
+ }
826
+ /**
827
+ * Did the value come from the option, and not from possible matching dual option?
828
+ *
829
+ * @param {*} value
830
+ * @param {Option} option
831
+ * @returns {boolean}
832
+ */
833
+ valueFromOption(value, option) {
834
+ const optionKey = option.attributeName();
835
+ if (!this.dualOptions.has(optionKey)) return true;
836
+ const preset = this.negativeOptions.get(optionKey).presetArg;
837
+ const negativeValue = preset !== void 0 ? preset : false;
838
+ return option.negate === (negativeValue === value);
839
+ }
840
+ };
841
+ function camelcase(str) {
842
+ return str.split("-").reduce((str2, word) => {
843
+ return str2 + word[0].toUpperCase() + word.slice(1);
844
+ });
845
+ }
846
+ function splitOptionFlags(flags) {
847
+ let shortFlag;
848
+ let longFlag;
849
+ const flagParts = flags.split(/[ |,]+/);
850
+ if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
851
+ shortFlag = flagParts.shift();
852
+ longFlag = flagParts.shift();
853
+ if (!shortFlag && /^-[^-]$/.test(longFlag)) {
854
+ shortFlag = longFlag;
855
+ longFlag = void 0;
856
+ }
857
+ return { shortFlag, longFlag };
858
+ }
859
+ exports.Option = Option2;
860
+ exports.DualOptions = DualOptions;
861
+ }
862
+ });
863
+
864
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/suggestSimilar.js
865
+ var require_suggestSimilar = __commonJS({
866
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/suggestSimilar.js"(exports) {
867
+ var maxDistance = 3;
868
+ function editDistance(a, b) {
869
+ if (Math.abs(a.length - b.length) > maxDistance)
870
+ return Math.max(a.length, b.length);
871
+ const d = [];
872
+ for (let i = 0; i <= a.length; i++) {
873
+ d[i] = [i];
874
+ }
875
+ for (let j = 0; j <= b.length; j++) {
876
+ d[0][j] = j;
877
+ }
878
+ for (let j = 1; j <= b.length; j++) {
879
+ for (let i = 1; i <= a.length; i++) {
880
+ let cost = 1;
881
+ if (a[i - 1] === b[j - 1]) {
882
+ cost = 0;
883
+ } else {
884
+ cost = 1;
885
+ }
886
+ d[i][j] = Math.min(
887
+ d[i - 1][j] + 1,
888
+ // deletion
889
+ d[i][j - 1] + 1,
890
+ // insertion
891
+ d[i - 1][j - 1] + cost
892
+ // substitution
893
+ );
894
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
895
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
896
+ }
897
+ }
898
+ }
899
+ return d[a.length][b.length];
900
+ }
901
+ function suggestSimilar(word, candidates) {
902
+ if (!candidates || candidates.length === 0) return "";
903
+ candidates = Array.from(new Set(candidates));
904
+ const searchingOptions = word.startsWith("--");
905
+ if (searchingOptions) {
906
+ word = word.slice(2);
907
+ candidates = candidates.map((candidate) => candidate.slice(2));
908
+ }
909
+ let similar = [];
910
+ let bestDistance = maxDistance;
911
+ const minSimilarity = 0.4;
912
+ candidates.forEach((candidate) => {
913
+ if (candidate.length <= 1) return;
914
+ const distance = editDistance(word, candidate);
915
+ const length = Math.max(word.length, candidate.length);
916
+ const similarity = (length - distance) / length;
917
+ if (similarity > minSimilarity) {
918
+ if (distance < bestDistance) {
919
+ bestDistance = distance;
920
+ similar = [candidate];
921
+ } else if (distance === bestDistance) {
922
+ similar.push(candidate);
923
+ }
924
+ }
925
+ });
926
+ similar.sort((a, b) => a.localeCompare(b));
927
+ if (searchingOptions) {
928
+ similar = similar.map((candidate) => `--${candidate}`);
929
+ }
930
+ if (similar.length > 1) {
931
+ return `
932
+ (Did you mean one of ${similar.join(", ")}?)`;
933
+ }
934
+ if (similar.length === 1) {
935
+ return `
936
+ (Did you mean ${similar[0]}?)`;
937
+ }
938
+ return "";
939
+ }
940
+ exports.suggestSimilar = suggestSimilar;
941
+ }
942
+ });
943
+
944
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js
945
+ var require_command = __commonJS({
946
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js"(exports) {
947
+ var EventEmitter = __require("node:events").EventEmitter;
948
+ var childProcess = __require("node:child_process");
949
+ var path = __require("node:path");
950
+ var fs = __require("node:fs");
951
+ var process2 = __require("node:process");
952
+ var { Argument: Argument2, humanReadableArgName } = require_argument();
953
+ var { CommanderError: CommanderError2 } = require_error();
954
+ var { Help: Help2 } = require_help();
955
+ var { Option: Option2, DualOptions } = require_option();
956
+ var { suggestSimilar } = require_suggestSimilar();
957
+ var Command2 = class _Command extends EventEmitter {
958
+ /**
959
+ * Initialize a new `Command`.
960
+ *
961
+ * @param {string} [name]
962
+ */
963
+ constructor(name) {
964
+ super();
965
+ this.commands = [];
966
+ this.options = [];
967
+ this.parent = null;
968
+ this._allowUnknownOption = false;
969
+ this._allowExcessArguments = true;
970
+ this.registeredArguments = [];
971
+ this._args = this.registeredArguments;
972
+ this.args = [];
973
+ this.rawArgs = [];
974
+ this.processedArgs = [];
975
+ this._scriptPath = null;
976
+ this._name = name || "";
977
+ this._optionValues = {};
978
+ this._optionValueSources = {};
979
+ this._storeOptionsAsProperties = false;
980
+ this._actionHandler = null;
981
+ this._executableHandler = false;
982
+ this._executableFile = null;
983
+ this._executableDir = null;
984
+ this._defaultCommandName = null;
985
+ this._exitCallback = null;
986
+ this._aliases = [];
987
+ this._combineFlagAndOptionalValue = true;
988
+ this._description = "";
989
+ this._summary = "";
990
+ this._argsDescription = void 0;
991
+ this._enablePositionalOptions = false;
992
+ this._passThroughOptions = false;
993
+ this._lifeCycleHooks = {};
994
+ this._showHelpAfterError = false;
995
+ this._showSuggestionAfterError = true;
996
+ this._outputConfiguration = {
997
+ writeOut: (str) => process2.stdout.write(str),
998
+ writeErr: (str) => process2.stderr.write(str),
999
+ getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : void 0,
1000
+ getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : void 0,
1001
+ outputError: (str, write) => write(str)
1002
+ };
1003
+ this._hidden = false;
1004
+ this._helpOption = void 0;
1005
+ this._addImplicitHelpCommand = void 0;
1006
+ this._helpCommand = void 0;
1007
+ this._helpConfiguration = {};
1008
+ }
1009
+ /**
1010
+ * Copy settings that are useful to have in common across root command and subcommands.
1011
+ *
1012
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
1013
+ *
1014
+ * @param {Command} sourceCommand
1015
+ * @return {Command} `this` command for chaining
1016
+ */
1017
+ copyInheritedSettings(sourceCommand) {
1018
+ this._outputConfiguration = sourceCommand._outputConfiguration;
1019
+ this._helpOption = sourceCommand._helpOption;
1020
+ this._helpCommand = sourceCommand._helpCommand;
1021
+ this._helpConfiguration = sourceCommand._helpConfiguration;
1022
+ this._exitCallback = sourceCommand._exitCallback;
1023
+ this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
1024
+ this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
1025
+ this._allowExcessArguments = sourceCommand._allowExcessArguments;
1026
+ this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
1027
+ this._showHelpAfterError = sourceCommand._showHelpAfterError;
1028
+ this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
1029
+ return this;
1030
+ }
1031
+ /**
1032
+ * @returns {Command[]}
1033
+ * @private
1034
+ */
1035
+ _getCommandAndAncestors() {
1036
+ const result = [];
1037
+ for (let command = this; command; command = command.parent) {
1038
+ result.push(command);
1039
+ }
1040
+ return result;
1041
+ }
1042
+ /**
1043
+ * Define a command.
1044
+ *
1045
+ * There are two styles of command: pay attention to where to put the description.
1046
+ *
1047
+ * @example
1048
+ * // Command implemented using action handler (description is supplied separately to `.command`)
1049
+ * program
1050
+ * .command('clone <source> [destination]')
1051
+ * .description('clone a repository into a newly created directory')
1052
+ * .action((source, destination) => {
1053
+ * console.log('clone command called');
1054
+ * });
1055
+ *
1056
+ * // Command implemented using separate executable file (description is second parameter to `.command`)
1057
+ * program
1058
+ * .command('start <service>', 'start named service')
1059
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
1060
+ *
1061
+ * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
1062
+ * @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
1063
+ * @param {object} [execOpts] - configuration options (for executable)
1064
+ * @return {Command} returns new command for action handler, or `this` for executable command
1065
+ */
1066
+ command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
1067
+ let desc = actionOptsOrExecDesc;
1068
+ let opts = execOpts;
1069
+ if (typeof desc === "object" && desc !== null) {
1070
+ opts = desc;
1071
+ desc = null;
1072
+ }
1073
+ opts = opts || {};
1074
+ const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
1075
+ const cmd = this.createCommand(name);
1076
+ if (desc) {
1077
+ cmd.description(desc);
1078
+ cmd._executableHandler = true;
1079
+ }
1080
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
1081
+ cmd._hidden = !!(opts.noHelp || opts.hidden);
1082
+ cmd._executableFile = opts.executableFile || null;
1083
+ if (args) cmd.arguments(args);
1084
+ this._registerCommand(cmd);
1085
+ cmd.parent = this;
1086
+ cmd.copyInheritedSettings(this);
1087
+ if (desc) return this;
1088
+ return cmd;
1089
+ }
1090
+ /**
1091
+ * Factory routine to create a new unattached command.
1092
+ *
1093
+ * See .command() for creating an attached subcommand, which uses this routine to
1094
+ * create the command. You can override createCommand to customise subcommands.
1095
+ *
1096
+ * @param {string} [name]
1097
+ * @return {Command} new command
1098
+ */
1099
+ createCommand(name) {
1100
+ return new _Command(name);
1101
+ }
1102
+ /**
1103
+ * You can customise the help with a subclass of Help by overriding createHelp,
1104
+ * or by overriding Help properties using configureHelp().
1105
+ *
1106
+ * @return {Help}
1107
+ */
1108
+ createHelp() {
1109
+ return Object.assign(new Help2(), this.configureHelp());
1110
+ }
1111
+ /**
1112
+ * You can customise the help by overriding Help properties using configureHelp(),
1113
+ * or with a subclass of Help by overriding createHelp().
1114
+ *
1115
+ * @param {object} [configuration] - configuration options
1116
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
1117
+ */
1118
+ configureHelp(configuration) {
1119
+ if (configuration === void 0) return this._helpConfiguration;
1120
+ this._helpConfiguration = configuration;
1121
+ return this;
1122
+ }
1123
+ /**
1124
+ * The default output goes to stdout and stderr. You can customise this for special
1125
+ * applications. You can also customise the display of errors by overriding outputError.
1126
+ *
1127
+ * The configuration properties are all functions:
1128
+ *
1129
+ * // functions to change where being written, stdout and stderr
1130
+ * writeOut(str)
1131
+ * writeErr(str)
1132
+ * // matching functions to specify width for wrapping help
1133
+ * getOutHelpWidth()
1134
+ * getErrHelpWidth()
1135
+ * // functions based on what is being written out
1136
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
1137
+ *
1138
+ * @param {object} [configuration] - configuration options
1139
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
1140
+ */
1141
+ configureOutput(configuration) {
1142
+ if (configuration === void 0) return this._outputConfiguration;
1143
+ Object.assign(this._outputConfiguration, configuration);
1144
+ return this;
1145
+ }
1146
+ /**
1147
+ * Display the help or a custom message after an error occurs.
1148
+ *
1149
+ * @param {(boolean|string)} [displayHelp]
1150
+ * @return {Command} `this` command for chaining
1151
+ */
1152
+ showHelpAfterError(displayHelp = true) {
1153
+ if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
1154
+ this._showHelpAfterError = displayHelp;
1155
+ return this;
1156
+ }
1157
+ /**
1158
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
1159
+ *
1160
+ * @param {boolean} [displaySuggestion]
1161
+ * @return {Command} `this` command for chaining
1162
+ */
1163
+ showSuggestionAfterError(displaySuggestion = true) {
1164
+ this._showSuggestionAfterError = !!displaySuggestion;
1165
+ return this;
1166
+ }
1167
+ /**
1168
+ * Add a prepared subcommand.
1169
+ *
1170
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
1171
+ *
1172
+ * @param {Command} cmd - new subcommand
1173
+ * @param {object} [opts] - configuration options
1174
+ * @return {Command} `this` command for chaining
1175
+ */
1176
+ addCommand(cmd, opts) {
1177
+ if (!cmd._name) {
1178
+ throw new Error(`Command passed to .addCommand() must have a name
1179
+ - specify the name in Command constructor or using .name()`);
1180
+ }
1181
+ opts = opts || {};
1182
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
1183
+ if (opts.noHelp || opts.hidden) cmd._hidden = true;
1184
+ this._registerCommand(cmd);
1185
+ cmd.parent = this;
1186
+ cmd._checkForBrokenPassThrough();
1187
+ return this;
1188
+ }
1189
+ /**
1190
+ * Factory routine to create a new unattached argument.
1191
+ *
1192
+ * See .argument() for creating an attached argument, which uses this routine to
1193
+ * create the argument. You can override createArgument to return a custom argument.
1194
+ *
1195
+ * @param {string} name
1196
+ * @param {string} [description]
1197
+ * @return {Argument} new argument
1198
+ */
1199
+ createArgument(name, description) {
1200
+ return new Argument2(name, description);
1201
+ }
1202
+ /**
1203
+ * Define argument syntax for command.
1204
+ *
1205
+ * The default is that the argument is required, and you can explicitly
1206
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
1207
+ *
1208
+ * @example
1209
+ * program.argument('<input-file>');
1210
+ * program.argument('[output-file]');
1211
+ *
1212
+ * @param {string} name
1213
+ * @param {string} [description]
1214
+ * @param {(Function|*)} [fn] - custom argument processing function
1215
+ * @param {*} [defaultValue]
1216
+ * @return {Command} `this` command for chaining
1217
+ */
1218
+ argument(name, description, fn, defaultValue) {
1219
+ const argument = this.createArgument(name, description);
1220
+ if (typeof fn === "function") {
1221
+ argument.default(defaultValue).argParser(fn);
1222
+ } else {
1223
+ argument.default(fn);
1224
+ }
1225
+ this.addArgument(argument);
1226
+ return this;
1227
+ }
1228
+ /**
1229
+ * Define argument syntax for command, adding multiple at once (without descriptions).
1230
+ *
1231
+ * See also .argument().
1232
+ *
1233
+ * @example
1234
+ * program.arguments('<cmd> [env]');
1235
+ *
1236
+ * @param {string} names
1237
+ * @return {Command} `this` command for chaining
1238
+ */
1239
+ arguments(names) {
1240
+ names.trim().split(/ +/).forEach((detail) => {
1241
+ this.argument(detail);
1242
+ });
1243
+ return this;
1244
+ }
1245
+ /**
1246
+ * Define argument syntax for command, adding a prepared argument.
1247
+ *
1248
+ * @param {Argument} argument
1249
+ * @return {Command} `this` command for chaining
1250
+ */
1251
+ addArgument(argument) {
1252
+ const previousArgument = this.registeredArguments.slice(-1)[0];
1253
+ if (previousArgument && previousArgument.variadic) {
1254
+ throw new Error(
1255
+ `only the last argument can be variadic '${previousArgument.name()}'`
1256
+ );
1257
+ }
1258
+ if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
1259
+ throw new Error(
1260
+ `a default value for a required argument is never used: '${argument.name()}'`
1261
+ );
1262
+ }
1263
+ this.registeredArguments.push(argument);
1264
+ return this;
1265
+ }
1266
+ /**
1267
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
1268
+ *
1269
+ * @example
1270
+ * program.helpCommand('help [cmd]');
1271
+ * program.helpCommand('help [cmd]', 'show help');
1272
+ * program.helpCommand(false); // suppress default help command
1273
+ * program.helpCommand(true); // add help command even if no subcommands
1274
+ *
1275
+ * @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
1276
+ * @param {string} [description] - custom description
1277
+ * @return {Command} `this` command for chaining
1278
+ */
1279
+ helpCommand(enableOrNameAndArgs, description) {
1280
+ if (typeof enableOrNameAndArgs === "boolean") {
1281
+ this._addImplicitHelpCommand = enableOrNameAndArgs;
1282
+ return this;
1283
+ }
1284
+ enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
1285
+ const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
1286
+ const helpDescription = description ?? "display help for command";
1287
+ const helpCommand = this.createCommand(helpName);
1288
+ helpCommand.helpOption(false);
1289
+ if (helpArgs) helpCommand.arguments(helpArgs);
1290
+ if (helpDescription) helpCommand.description(helpDescription);
1291
+ this._addImplicitHelpCommand = true;
1292
+ this._helpCommand = helpCommand;
1293
+ return this;
1294
+ }
1295
+ /**
1296
+ * Add prepared custom help command.
1297
+ *
1298
+ * @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
1299
+ * @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
1300
+ * @return {Command} `this` command for chaining
1301
+ */
1302
+ addHelpCommand(helpCommand, deprecatedDescription) {
1303
+ if (typeof helpCommand !== "object") {
1304
+ this.helpCommand(helpCommand, deprecatedDescription);
1305
+ return this;
1306
+ }
1307
+ this._addImplicitHelpCommand = true;
1308
+ this._helpCommand = helpCommand;
1309
+ return this;
1310
+ }
1311
+ /**
1312
+ * Lazy create help command.
1313
+ *
1314
+ * @return {(Command|null)}
1315
+ * @package
1316
+ */
1317
+ _getHelpCommand() {
1318
+ const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
1319
+ if (hasImplicitHelpCommand) {
1320
+ if (this._helpCommand === void 0) {
1321
+ this.helpCommand(void 0, void 0);
1322
+ }
1323
+ return this._helpCommand;
1324
+ }
1325
+ return null;
1326
+ }
1327
+ /**
1328
+ * Add hook for life cycle event.
1329
+ *
1330
+ * @param {string} event
1331
+ * @param {Function} listener
1332
+ * @return {Command} `this` command for chaining
1333
+ */
1334
+ hook(event, listener) {
1335
+ const allowedValues = ["preSubcommand", "preAction", "postAction"];
1336
+ if (!allowedValues.includes(event)) {
1337
+ throw new Error(`Unexpected value for event passed to hook : '${event}'.
1338
+ Expecting one of '${allowedValues.join("', '")}'`);
1339
+ }
1340
+ if (this._lifeCycleHooks[event]) {
1341
+ this._lifeCycleHooks[event].push(listener);
1342
+ } else {
1343
+ this._lifeCycleHooks[event] = [listener];
1344
+ }
1345
+ return this;
1346
+ }
1347
+ /**
1348
+ * Register callback to use as replacement for calling process.exit.
1349
+ *
1350
+ * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
1351
+ * @return {Command} `this` command for chaining
1352
+ */
1353
+ exitOverride(fn) {
1354
+ if (fn) {
1355
+ this._exitCallback = fn;
1356
+ } else {
1357
+ this._exitCallback = (err) => {
1358
+ if (err.code !== "commander.executeSubCommandAsync") {
1359
+ throw err;
1360
+ } else {
1361
+ }
1362
+ };
1363
+ }
1364
+ return this;
1365
+ }
1366
+ /**
1367
+ * Call process.exit, and _exitCallback if defined.
1368
+ *
1369
+ * @param {number} exitCode exit code for using with process.exit
1370
+ * @param {string} code an id string representing the error
1371
+ * @param {string} message human-readable description of the error
1372
+ * @return never
1373
+ * @private
1374
+ */
1375
+ _exit(exitCode, code, message) {
1376
+ if (this._exitCallback) {
1377
+ this._exitCallback(new CommanderError2(exitCode, code, message));
1378
+ }
1379
+ process2.exit(exitCode);
1380
+ }
1381
+ /**
1382
+ * Register callback `fn` for the command.
1383
+ *
1384
+ * @example
1385
+ * program
1386
+ * .command('serve')
1387
+ * .description('start service')
1388
+ * .action(function() {
1389
+ * // do work here
1390
+ * });
1391
+ *
1392
+ * @param {Function} fn
1393
+ * @return {Command} `this` command for chaining
1394
+ */
1395
+ action(fn) {
1396
+ const listener = (args) => {
1397
+ const expectedArgsCount = this.registeredArguments.length;
1398
+ const actionArgs = args.slice(0, expectedArgsCount);
1399
+ if (this._storeOptionsAsProperties) {
1400
+ actionArgs[expectedArgsCount] = this;
1401
+ } else {
1402
+ actionArgs[expectedArgsCount] = this.opts();
1403
+ }
1404
+ actionArgs.push(this);
1405
+ return fn.apply(this, actionArgs);
1406
+ };
1407
+ this._actionHandler = listener;
1408
+ return this;
1409
+ }
1410
+ /**
1411
+ * Factory routine to create a new unattached option.
1412
+ *
1413
+ * See .option() for creating an attached option, which uses this routine to
1414
+ * create the option. You can override createOption to return a custom option.
1415
+ *
1416
+ * @param {string} flags
1417
+ * @param {string} [description]
1418
+ * @return {Option} new option
1419
+ */
1420
+ createOption(flags, description) {
1421
+ return new Option2(flags, description);
1422
+ }
1423
+ /**
1424
+ * Wrap parseArgs to catch 'commander.invalidArgument'.
1425
+ *
1426
+ * @param {(Option | Argument)} target
1427
+ * @param {string} value
1428
+ * @param {*} previous
1429
+ * @param {string} invalidArgumentMessage
1430
+ * @private
1431
+ */
1432
+ _callParseArg(target, value, previous, invalidArgumentMessage) {
1433
+ try {
1434
+ return target.parseArg(value, previous);
1435
+ } catch (err) {
1436
+ if (err.code === "commander.invalidArgument") {
1437
+ const message = `${invalidArgumentMessage} ${err.message}`;
1438
+ this.error(message, { exitCode: err.exitCode, code: err.code });
1439
+ }
1440
+ throw err;
1441
+ }
1442
+ }
1443
+ /**
1444
+ * Check for option flag conflicts.
1445
+ * Register option if no conflicts found, or throw on conflict.
1446
+ *
1447
+ * @param {Option} option
1448
+ * @private
1449
+ */
1450
+ _registerOption(option) {
1451
+ const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
1452
+ if (matchingOption) {
1453
+ const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
1454
+ throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1455
+ - already used by option '${matchingOption.flags}'`);
1456
+ }
1457
+ this.options.push(option);
1458
+ }
1459
+ /**
1460
+ * Check for command name and alias conflicts with existing commands.
1461
+ * Register command if no conflicts found, or throw on conflict.
1462
+ *
1463
+ * @param {Command} command
1464
+ * @private
1465
+ */
1466
+ _registerCommand(command) {
1467
+ const knownBy = (cmd) => {
1468
+ return [cmd.name()].concat(cmd.aliases());
1469
+ };
1470
+ const alreadyUsed = knownBy(command).find(
1471
+ (name) => this._findCommand(name)
1472
+ );
1473
+ if (alreadyUsed) {
1474
+ const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
1475
+ const newCmd = knownBy(command).join("|");
1476
+ throw new Error(
1477
+ `cannot add command '${newCmd}' as already have command '${existingCmd}'`
1478
+ );
1479
+ }
1480
+ this.commands.push(command);
1481
+ }
1482
+ /**
1483
+ * Add an option.
1484
+ *
1485
+ * @param {Option} option
1486
+ * @return {Command} `this` command for chaining
1487
+ */
1488
+ addOption(option) {
1489
+ this._registerOption(option);
1490
+ const oname = option.name();
1491
+ const name = option.attributeName();
1492
+ if (option.negate) {
1493
+ const positiveLongFlag = option.long.replace(/^--no-/, "--");
1494
+ if (!this._findOption(positiveLongFlag)) {
1495
+ this.setOptionValueWithSource(
1496
+ name,
1497
+ option.defaultValue === void 0 ? true : option.defaultValue,
1498
+ "default"
1499
+ );
1500
+ }
1501
+ } else if (option.defaultValue !== void 0) {
1502
+ this.setOptionValueWithSource(name, option.defaultValue, "default");
1503
+ }
1504
+ const handleOptionValue = (val, invalidValueMessage, valueSource) => {
1505
+ if (val == null && option.presetArg !== void 0) {
1506
+ val = option.presetArg;
1507
+ }
1508
+ const oldValue = this.getOptionValue(name);
1509
+ if (val !== null && option.parseArg) {
1510
+ val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1511
+ } else if (val !== null && option.variadic) {
1512
+ val = option._concatValue(val, oldValue);
1513
+ }
1514
+ if (val == null) {
1515
+ if (option.negate) {
1516
+ val = false;
1517
+ } else if (option.isBoolean() || option.optional) {
1518
+ val = true;
1519
+ } else {
1520
+ val = "";
1521
+ }
1522
+ }
1523
+ this.setOptionValueWithSource(name, val, valueSource);
1524
+ };
1525
+ this.on("option:" + oname, (val) => {
1526
+ const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
1527
+ handleOptionValue(val, invalidValueMessage, "cli");
1528
+ });
1529
+ if (option.envVar) {
1530
+ this.on("optionEnv:" + oname, (val) => {
1531
+ const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
1532
+ handleOptionValue(val, invalidValueMessage, "env");
1533
+ });
1534
+ }
1535
+ return this;
1536
+ }
1537
+ /**
1538
+ * Internal implementation shared by .option() and .requiredOption()
1539
+ *
1540
+ * @return {Command} `this` command for chaining
1541
+ * @private
1542
+ */
1543
+ _optionEx(config, flags, description, fn, defaultValue) {
1544
+ if (typeof flags === "object" && flags instanceof Option2) {
1545
+ throw new Error(
1546
+ "To add an Option object use addOption() instead of option() or requiredOption()"
1547
+ );
1548
+ }
1549
+ const option = this.createOption(flags, description);
1550
+ option.makeOptionMandatory(!!config.mandatory);
1551
+ if (typeof fn === "function") {
1552
+ option.default(defaultValue).argParser(fn);
1553
+ } else if (fn instanceof RegExp) {
1554
+ const regex = fn;
1555
+ fn = (val, def) => {
1556
+ const m = regex.exec(val);
1557
+ return m ? m[0] : def;
1558
+ };
1559
+ option.default(defaultValue).argParser(fn);
1560
+ } else {
1561
+ option.default(fn);
1562
+ }
1563
+ return this.addOption(option);
1564
+ }
1565
+ /**
1566
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
1567
+ *
1568
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
1569
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
1570
+ *
1571
+ * See the README for more details, and see also addOption() and requiredOption().
1572
+ *
1573
+ * @example
1574
+ * program
1575
+ * .option('-p, --pepper', 'add pepper')
1576
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
1577
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
1578
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
1579
+ *
1580
+ * @param {string} flags
1581
+ * @param {string} [description]
1582
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1583
+ * @param {*} [defaultValue]
1584
+ * @return {Command} `this` command for chaining
1585
+ */
1586
+ option(flags, description, parseArg, defaultValue) {
1587
+ return this._optionEx({}, flags, description, parseArg, defaultValue);
1588
+ }
1589
+ /**
1590
+ * Add a required option which must have a value after parsing. This usually means
1591
+ * the option must be specified on the command line. (Otherwise the same as .option().)
1592
+ *
1593
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1594
+ *
1595
+ * @param {string} flags
1596
+ * @param {string} [description]
1597
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1598
+ * @param {*} [defaultValue]
1599
+ * @return {Command} `this` command for chaining
1600
+ */
1601
+ requiredOption(flags, description, parseArg, defaultValue) {
1602
+ return this._optionEx(
1603
+ { mandatory: true },
1604
+ flags,
1605
+ description,
1606
+ parseArg,
1607
+ defaultValue
1608
+ );
1609
+ }
1610
+ /**
1611
+ * Alter parsing of short flags with optional values.
1612
+ *
1613
+ * @example
1614
+ * // for `.option('-f,--flag [value]'):
1615
+ * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
1616
+ * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
1617
+ *
1618
+ * @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
1619
+ * @return {Command} `this` command for chaining
1620
+ */
1621
+ combineFlagAndOptionalValue(combine = true) {
1622
+ this._combineFlagAndOptionalValue = !!combine;
1623
+ return this;
1624
+ }
1625
+ /**
1626
+ * Allow unknown options on the command line.
1627
+ *
1628
+ * @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
1629
+ * @return {Command} `this` command for chaining
1630
+ */
1631
+ allowUnknownOption(allowUnknown = true) {
1632
+ this._allowUnknownOption = !!allowUnknown;
1633
+ return this;
1634
+ }
1635
+ /**
1636
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1637
+ *
1638
+ * @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
1639
+ * @return {Command} `this` command for chaining
1640
+ */
1641
+ allowExcessArguments(allowExcess = true) {
1642
+ this._allowExcessArguments = !!allowExcess;
1643
+ return this;
1644
+ }
1645
+ /**
1646
+ * Enable positional options. Positional means global options are specified before subcommands which lets
1647
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1648
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
1649
+ *
1650
+ * @param {boolean} [positional]
1651
+ * @return {Command} `this` command for chaining
1652
+ */
1653
+ enablePositionalOptions(positional = true) {
1654
+ this._enablePositionalOptions = !!positional;
1655
+ return this;
1656
+ }
1657
+ /**
1658
+ * Pass through options that come after command-arguments rather than treat them as command-options,
1659
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
1660
+ * positional options to have been enabled on the program (parent commands).
1661
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
1662
+ *
1663
+ * @param {boolean} [passThrough] for unknown options.
1664
+ * @return {Command} `this` command for chaining
1665
+ */
1666
+ passThroughOptions(passThrough = true) {
1667
+ this._passThroughOptions = !!passThrough;
1668
+ this._checkForBrokenPassThrough();
1669
+ return this;
1670
+ }
1671
+ /**
1672
+ * @private
1673
+ */
1674
+ _checkForBrokenPassThrough() {
1675
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1676
+ throw new Error(
1677
+ `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
1678
+ );
1679
+ }
1680
+ }
1681
+ /**
1682
+ * Whether to store option values as properties on command object,
1683
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
1684
+ *
1685
+ * @param {boolean} [storeAsProperties=true]
1686
+ * @return {Command} `this` command for chaining
1687
+ */
1688
+ storeOptionsAsProperties(storeAsProperties = true) {
1689
+ if (this.options.length) {
1690
+ throw new Error("call .storeOptionsAsProperties() before adding options");
1691
+ }
1692
+ if (Object.keys(this._optionValues).length) {
1693
+ throw new Error(
1694
+ "call .storeOptionsAsProperties() before setting option values"
1695
+ );
1696
+ }
1697
+ this._storeOptionsAsProperties = !!storeAsProperties;
1698
+ return this;
1699
+ }
1700
+ /**
1701
+ * Retrieve option value.
1702
+ *
1703
+ * @param {string} key
1704
+ * @return {object} value
1705
+ */
1706
+ getOptionValue(key) {
1707
+ if (this._storeOptionsAsProperties) {
1708
+ return this[key];
1709
+ }
1710
+ return this._optionValues[key];
1711
+ }
1712
+ /**
1713
+ * Store option value.
1714
+ *
1715
+ * @param {string} key
1716
+ * @param {object} value
1717
+ * @return {Command} `this` command for chaining
1718
+ */
1719
+ setOptionValue(key, value) {
1720
+ return this.setOptionValueWithSource(key, value, void 0);
1721
+ }
1722
+ /**
1723
+ * Store option value and where the value came from.
1724
+ *
1725
+ * @param {string} key
1726
+ * @param {object} value
1727
+ * @param {string} source - expected values are default/config/env/cli/implied
1728
+ * @return {Command} `this` command for chaining
1729
+ */
1730
+ setOptionValueWithSource(key, value, source) {
1731
+ if (this._storeOptionsAsProperties) {
1732
+ this[key] = value;
1733
+ } else {
1734
+ this._optionValues[key] = value;
1735
+ }
1736
+ this._optionValueSources[key] = source;
1737
+ return this;
1738
+ }
1739
+ /**
1740
+ * Get source of option value.
1741
+ * Expected values are default | config | env | cli | implied
1742
+ *
1743
+ * @param {string} key
1744
+ * @return {string}
1745
+ */
1746
+ getOptionValueSource(key) {
1747
+ return this._optionValueSources[key];
1748
+ }
1749
+ /**
1750
+ * Get source of option value. See also .optsWithGlobals().
1751
+ * Expected values are default | config | env | cli | implied
1752
+ *
1753
+ * @param {string} key
1754
+ * @return {string}
1755
+ */
1756
+ getOptionValueSourceWithGlobals(key) {
1757
+ let source;
1758
+ this._getCommandAndAncestors().forEach((cmd) => {
1759
+ if (cmd.getOptionValueSource(key) !== void 0) {
1760
+ source = cmd.getOptionValueSource(key);
1761
+ }
1762
+ });
1763
+ return source;
1764
+ }
1765
+ /**
1766
+ * Get user arguments from implied or explicit arguments.
1767
+ * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
1768
+ *
1769
+ * @private
1770
+ */
1771
+ _prepareUserArgs(argv, parseOptions) {
1772
+ if (argv !== void 0 && !Array.isArray(argv)) {
1773
+ throw new Error("first parameter to parse must be array or undefined");
1774
+ }
1775
+ parseOptions = parseOptions || {};
1776
+ if (argv === void 0 && parseOptions.from === void 0) {
1777
+ if (process2.versions?.electron) {
1778
+ parseOptions.from = "electron";
1779
+ }
1780
+ const execArgv = process2.execArgv ?? [];
1781
+ if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
1782
+ parseOptions.from = "eval";
1783
+ }
1784
+ }
1785
+ if (argv === void 0) {
1786
+ argv = process2.argv;
1787
+ }
1788
+ this.rawArgs = argv.slice();
1789
+ let userArgs;
1790
+ switch (parseOptions.from) {
1791
+ case void 0:
1792
+ case "node":
1793
+ this._scriptPath = argv[1];
1794
+ userArgs = argv.slice(2);
1795
+ break;
1796
+ case "electron":
1797
+ if (process2.defaultApp) {
1798
+ this._scriptPath = argv[1];
1799
+ userArgs = argv.slice(2);
1800
+ } else {
1801
+ userArgs = argv.slice(1);
1802
+ }
1803
+ break;
1804
+ case "user":
1805
+ userArgs = argv.slice(0);
1806
+ break;
1807
+ case "eval":
1808
+ userArgs = argv.slice(1);
1809
+ break;
1810
+ default:
1811
+ throw new Error(
1812
+ `unexpected parse option { from: '${parseOptions.from}' }`
1813
+ );
1814
+ }
1815
+ if (!this._name && this._scriptPath)
1816
+ this.nameFromFilename(this._scriptPath);
1817
+ this._name = this._name || "program";
1818
+ return userArgs;
1819
+ }
1820
+ /**
1821
+ * Parse `argv`, setting options and invoking commands when defined.
1822
+ *
1823
+ * Use parseAsync instead of parse if any of your action handlers are async.
1824
+ *
1825
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
1826
+ *
1827
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
1828
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
1829
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
1830
+ * - `'user'`: just user arguments
1831
+ *
1832
+ * @example
1833
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
1834
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
1835
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1836
+ *
1837
+ * @param {string[]} [argv] - optional, defaults to process.argv
1838
+ * @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
1839
+ * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
1840
+ * @return {Command} `this` command for chaining
1841
+ */
1842
+ parse(argv, parseOptions) {
1843
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1844
+ this._parseCommand([], userArgs);
1845
+ return this;
1846
+ }
1847
+ /**
1848
+ * Parse `argv`, setting options and invoking commands when defined.
1849
+ *
1850
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
1851
+ *
1852
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
1853
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
1854
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
1855
+ * - `'user'`: just user arguments
1856
+ *
1857
+ * @example
1858
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
1859
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
1860
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1861
+ *
1862
+ * @param {string[]} [argv]
1863
+ * @param {object} [parseOptions]
1864
+ * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
1865
+ * @return {Promise}
1866
+ */
1867
+ async parseAsync(argv, parseOptions) {
1868
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1869
+ await this._parseCommand([], userArgs);
1870
+ return this;
1871
+ }
1872
+ /**
1873
+ * Execute a sub-command executable.
1874
+ *
1875
+ * @private
1876
+ */
1877
+ _executeSubCommand(subcommand, args) {
1878
+ args = args.slice();
1879
+ let launchWithNode = false;
1880
+ const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1881
+ function findFile(baseDir, baseName) {
1882
+ const localBin = path.resolve(baseDir, baseName);
1883
+ if (fs.existsSync(localBin)) return localBin;
1884
+ if (sourceExt.includes(path.extname(baseName))) return void 0;
1885
+ const foundExt = sourceExt.find(
1886
+ (ext) => fs.existsSync(`${localBin}${ext}`)
1887
+ );
1888
+ if (foundExt) return `${localBin}${foundExt}`;
1889
+ return void 0;
1890
+ }
1891
+ this._checkForMissingMandatoryOptions();
1892
+ this._checkForConflictingOptions();
1893
+ let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1894
+ let executableDir = this._executableDir || "";
1895
+ if (this._scriptPath) {
1896
+ let resolvedScriptPath;
1897
+ try {
1898
+ resolvedScriptPath = fs.realpathSync(this._scriptPath);
1899
+ } catch (err) {
1900
+ resolvedScriptPath = this._scriptPath;
1901
+ }
1902
+ executableDir = path.resolve(
1903
+ path.dirname(resolvedScriptPath),
1904
+ executableDir
1905
+ );
1906
+ }
1907
+ if (executableDir) {
1908
+ let localFile = findFile(executableDir, executableFile);
1909
+ if (!localFile && !subcommand._executableFile && this._scriptPath) {
1910
+ const legacyName = path.basename(
1911
+ this._scriptPath,
1912
+ path.extname(this._scriptPath)
1913
+ );
1914
+ if (legacyName !== this._name) {
1915
+ localFile = findFile(
1916
+ executableDir,
1917
+ `${legacyName}-${subcommand._name}`
1918
+ );
1919
+ }
1920
+ }
1921
+ executableFile = localFile || executableFile;
1922
+ }
1923
+ launchWithNode = sourceExt.includes(path.extname(executableFile));
1924
+ let proc;
1925
+ if (process2.platform !== "win32") {
1926
+ if (launchWithNode) {
1927
+ args.unshift(executableFile);
1928
+ args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1929
+ proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
1930
+ } else {
1931
+ proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1932
+ }
1933
+ } else {
1934
+ args.unshift(executableFile);
1935
+ args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1936
+ proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
1937
+ }
1938
+ if (!proc.killed) {
1939
+ const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
1940
+ signals.forEach((signal) => {
1941
+ process2.on(signal, () => {
1942
+ if (proc.killed === false && proc.exitCode === null) {
1943
+ proc.kill(signal);
1944
+ }
1945
+ });
1946
+ });
1947
+ }
1948
+ const exitCallback = this._exitCallback;
1949
+ proc.on("close", (code) => {
1950
+ code = code ?? 1;
1951
+ if (!exitCallback) {
1952
+ process2.exit(code);
1953
+ } else {
1954
+ exitCallback(
1955
+ new CommanderError2(
1956
+ code,
1957
+ "commander.executeSubCommandAsync",
1958
+ "(close)"
1959
+ )
1960
+ );
1961
+ }
1962
+ });
1963
+ proc.on("error", (err) => {
1964
+ if (err.code === "ENOENT") {
1965
+ 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";
1966
+ const executableMissing = `'${executableFile}' does not exist
1967
+ - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1968
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1969
+ - ${executableDirMessage}`;
1970
+ throw new Error(executableMissing);
1971
+ } else if (err.code === "EACCES") {
1972
+ throw new Error(`'${executableFile}' not executable`);
1973
+ }
1974
+ if (!exitCallback) {
1975
+ process2.exit(1);
1976
+ } else {
1977
+ const wrappedError = new CommanderError2(
1978
+ 1,
1979
+ "commander.executeSubCommandAsync",
1980
+ "(error)"
1981
+ );
1982
+ wrappedError.nestedError = err;
1983
+ exitCallback(wrappedError);
1984
+ }
1985
+ });
1986
+ this.runningCommand = proc;
1987
+ }
1988
+ /**
1989
+ * @private
1990
+ */
1991
+ _dispatchSubcommand(commandName, operands, unknown) {
1992
+ const subCommand = this._findCommand(commandName);
1993
+ if (!subCommand) this.help({ error: true });
1994
+ let promiseChain;
1995
+ promiseChain = this._chainOrCallSubCommandHook(
1996
+ promiseChain,
1997
+ subCommand,
1998
+ "preSubcommand"
1999
+ );
2000
+ promiseChain = this._chainOrCall(promiseChain, () => {
2001
+ if (subCommand._executableHandler) {
2002
+ this._executeSubCommand(subCommand, operands.concat(unknown));
2003
+ } else {
2004
+ return subCommand._parseCommand(operands, unknown);
2005
+ }
2006
+ });
2007
+ return promiseChain;
2008
+ }
2009
+ /**
2010
+ * Invoke help directly if possible, or dispatch if necessary.
2011
+ * e.g. help foo
2012
+ *
2013
+ * @private
2014
+ */
2015
+ _dispatchHelpCommand(subcommandName) {
2016
+ if (!subcommandName) {
2017
+ this.help();
2018
+ }
2019
+ const subCommand = this._findCommand(subcommandName);
2020
+ if (subCommand && !subCommand._executableHandler) {
2021
+ subCommand.help();
2022
+ }
2023
+ return this._dispatchSubcommand(
2024
+ subcommandName,
2025
+ [],
2026
+ [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
2027
+ );
2028
+ }
2029
+ /**
2030
+ * Check this.args against expected this.registeredArguments.
2031
+ *
2032
+ * @private
2033
+ */
2034
+ _checkNumberOfArguments() {
2035
+ this.registeredArguments.forEach((arg, i) => {
2036
+ if (arg.required && this.args[i] == null) {
2037
+ this.missingArgument(arg.name());
2038
+ }
2039
+ });
2040
+ if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
2041
+ return;
2042
+ }
2043
+ if (this.args.length > this.registeredArguments.length) {
2044
+ this._excessArguments(this.args);
2045
+ }
2046
+ }
2047
+ /**
2048
+ * Process this.args using this.registeredArguments and save as this.processedArgs!
2049
+ *
2050
+ * @private
2051
+ */
2052
+ _processArguments() {
2053
+ const myParseArg = (argument, value, previous) => {
2054
+ let parsedValue = value;
2055
+ if (value !== null && argument.parseArg) {
2056
+ const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
2057
+ parsedValue = this._callParseArg(
2058
+ argument,
2059
+ value,
2060
+ previous,
2061
+ invalidValueMessage
2062
+ );
2063
+ }
2064
+ return parsedValue;
2065
+ };
2066
+ this._checkNumberOfArguments();
2067
+ const processedArgs = [];
2068
+ this.registeredArguments.forEach((declaredArg, index) => {
2069
+ let value = declaredArg.defaultValue;
2070
+ if (declaredArg.variadic) {
2071
+ if (index < this.args.length) {
2072
+ value = this.args.slice(index);
2073
+ if (declaredArg.parseArg) {
2074
+ value = value.reduce((processed, v) => {
2075
+ return myParseArg(declaredArg, v, processed);
2076
+ }, declaredArg.defaultValue);
2077
+ }
2078
+ } else if (value === void 0) {
2079
+ value = [];
2080
+ }
2081
+ } else if (index < this.args.length) {
2082
+ value = this.args[index];
2083
+ if (declaredArg.parseArg) {
2084
+ value = myParseArg(declaredArg, value, declaredArg.defaultValue);
2085
+ }
2086
+ }
2087
+ processedArgs[index] = value;
2088
+ });
2089
+ this.processedArgs = processedArgs;
2090
+ }
2091
+ /**
2092
+ * Once we have a promise we chain, but call synchronously until then.
2093
+ *
2094
+ * @param {(Promise|undefined)} promise
2095
+ * @param {Function} fn
2096
+ * @return {(Promise|undefined)}
2097
+ * @private
2098
+ */
2099
+ _chainOrCall(promise, fn) {
2100
+ if (promise && promise.then && typeof promise.then === "function") {
2101
+ return promise.then(() => fn());
2102
+ }
2103
+ return fn();
2104
+ }
2105
+ /**
2106
+ *
2107
+ * @param {(Promise|undefined)} promise
2108
+ * @param {string} event
2109
+ * @return {(Promise|undefined)}
2110
+ * @private
2111
+ */
2112
+ _chainOrCallHooks(promise, event) {
2113
+ let result = promise;
2114
+ const hooks = [];
2115
+ this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
2116
+ hookedCommand._lifeCycleHooks[event].forEach((callback) => {
2117
+ hooks.push({ hookedCommand, callback });
2118
+ });
2119
+ });
2120
+ if (event === "postAction") {
2121
+ hooks.reverse();
2122
+ }
2123
+ hooks.forEach((hookDetail) => {
2124
+ result = this._chainOrCall(result, () => {
2125
+ return hookDetail.callback(hookDetail.hookedCommand, this);
2126
+ });
2127
+ });
2128
+ return result;
2129
+ }
2130
+ /**
2131
+ *
2132
+ * @param {(Promise|undefined)} promise
2133
+ * @param {Command} subCommand
2134
+ * @param {string} event
2135
+ * @return {(Promise|undefined)}
2136
+ * @private
2137
+ */
2138
+ _chainOrCallSubCommandHook(promise, subCommand, event) {
2139
+ let result = promise;
2140
+ if (this._lifeCycleHooks[event] !== void 0) {
2141
+ this._lifeCycleHooks[event].forEach((hook) => {
2142
+ result = this._chainOrCall(result, () => {
2143
+ return hook(this, subCommand);
2144
+ });
2145
+ });
2146
+ }
2147
+ return result;
2148
+ }
2149
+ /**
2150
+ * Process arguments in context of this command.
2151
+ * Returns action result, in case it is a promise.
2152
+ *
2153
+ * @private
2154
+ */
2155
+ _parseCommand(operands, unknown) {
2156
+ const parsed = this.parseOptions(unknown);
2157
+ this._parseOptionsEnv();
2158
+ this._parseOptionsImplied();
2159
+ operands = operands.concat(parsed.operands);
2160
+ unknown = parsed.unknown;
2161
+ this.args = operands.concat(unknown);
2162
+ if (operands && this._findCommand(operands[0])) {
2163
+ return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
2164
+ }
2165
+ if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
2166
+ return this._dispatchHelpCommand(operands[1]);
2167
+ }
2168
+ if (this._defaultCommandName) {
2169
+ this._outputHelpIfRequested(unknown);
2170
+ return this._dispatchSubcommand(
2171
+ this._defaultCommandName,
2172
+ operands,
2173
+ unknown
2174
+ );
2175
+ }
2176
+ if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
2177
+ this.help({ error: true });
2178
+ }
2179
+ this._outputHelpIfRequested(parsed.unknown);
2180
+ this._checkForMissingMandatoryOptions();
2181
+ this._checkForConflictingOptions();
2182
+ const checkForUnknownOptions = () => {
2183
+ if (parsed.unknown.length > 0) {
2184
+ this.unknownOption(parsed.unknown[0]);
2185
+ }
2186
+ };
2187
+ const commandEvent = `command:${this.name()}`;
2188
+ if (this._actionHandler) {
2189
+ checkForUnknownOptions();
2190
+ this._processArguments();
2191
+ let promiseChain;
2192
+ promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
2193
+ promiseChain = this._chainOrCall(
2194
+ promiseChain,
2195
+ () => this._actionHandler(this.processedArgs)
2196
+ );
2197
+ if (this.parent) {
2198
+ promiseChain = this._chainOrCall(promiseChain, () => {
2199
+ this.parent.emit(commandEvent, operands, unknown);
2200
+ });
2201
+ }
2202
+ promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
2203
+ return promiseChain;
2204
+ }
2205
+ if (this.parent && this.parent.listenerCount(commandEvent)) {
2206
+ checkForUnknownOptions();
2207
+ this._processArguments();
2208
+ this.parent.emit(commandEvent, operands, unknown);
2209
+ } else if (operands.length) {
2210
+ if (this._findCommand("*")) {
2211
+ return this._dispatchSubcommand("*", operands, unknown);
2212
+ }
2213
+ if (this.listenerCount("command:*")) {
2214
+ this.emit("command:*", operands, unknown);
2215
+ } else if (this.commands.length) {
2216
+ this.unknownCommand();
2217
+ } else {
2218
+ checkForUnknownOptions();
2219
+ this._processArguments();
2220
+ }
2221
+ } else if (this.commands.length) {
2222
+ checkForUnknownOptions();
2223
+ this.help({ error: true });
2224
+ } else {
2225
+ checkForUnknownOptions();
2226
+ this._processArguments();
2227
+ }
2228
+ }
2229
+ /**
2230
+ * Find matching command.
2231
+ *
2232
+ * @private
2233
+ * @return {Command | undefined}
2234
+ */
2235
+ _findCommand(name) {
2236
+ if (!name) return void 0;
2237
+ return this.commands.find(
2238
+ (cmd) => cmd._name === name || cmd._aliases.includes(name)
2239
+ );
2240
+ }
2241
+ /**
2242
+ * Return an option matching `arg` if any.
2243
+ *
2244
+ * @param {string} arg
2245
+ * @return {Option}
2246
+ * @package
2247
+ */
2248
+ _findOption(arg) {
2249
+ return this.options.find((option) => option.is(arg));
2250
+ }
2251
+ /**
2252
+ * Display an error message if a mandatory option does not have a value.
2253
+ * Called after checking for help flags in leaf subcommand.
2254
+ *
2255
+ * @private
2256
+ */
2257
+ _checkForMissingMandatoryOptions() {
2258
+ this._getCommandAndAncestors().forEach((cmd) => {
2259
+ cmd.options.forEach((anOption) => {
2260
+ if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
2261
+ cmd.missingMandatoryOptionValue(anOption);
2262
+ }
2263
+ });
2264
+ });
2265
+ }
2266
+ /**
2267
+ * Display an error message if conflicting options are used together in this.
2268
+ *
2269
+ * @private
2270
+ */
2271
+ _checkForConflictingLocalOptions() {
2272
+ const definedNonDefaultOptions = this.options.filter((option) => {
2273
+ const optionKey = option.attributeName();
2274
+ if (this.getOptionValue(optionKey) === void 0) {
2275
+ return false;
2276
+ }
2277
+ return this.getOptionValueSource(optionKey) !== "default";
2278
+ });
2279
+ const optionsWithConflicting = definedNonDefaultOptions.filter(
2280
+ (option) => option.conflictsWith.length > 0
2281
+ );
2282
+ optionsWithConflicting.forEach((option) => {
2283
+ const conflictingAndDefined = definedNonDefaultOptions.find(
2284
+ (defined) => option.conflictsWith.includes(defined.attributeName())
2285
+ );
2286
+ if (conflictingAndDefined) {
2287
+ this._conflictingOption(option, conflictingAndDefined);
2288
+ }
2289
+ });
2290
+ }
2291
+ /**
2292
+ * Display an error message if conflicting options are used together.
2293
+ * Called after checking for help flags in leaf subcommand.
2294
+ *
2295
+ * @private
2296
+ */
2297
+ _checkForConflictingOptions() {
2298
+ this._getCommandAndAncestors().forEach((cmd) => {
2299
+ cmd._checkForConflictingLocalOptions();
2300
+ });
2301
+ }
2302
+ /**
2303
+ * Parse options from `argv` removing known options,
2304
+ * and return argv split into operands and unknown arguments.
2305
+ *
2306
+ * Examples:
2307
+ *
2308
+ * argv => operands, unknown
2309
+ * --known kkk op => [op], []
2310
+ * op --known kkk => [op], []
2311
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
2312
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
2313
+ *
2314
+ * @param {string[]} argv
2315
+ * @return {{operands: string[], unknown: string[]}}
2316
+ */
2317
+ parseOptions(argv) {
2318
+ const operands = [];
2319
+ const unknown = [];
2320
+ let dest = operands;
2321
+ const args = argv.slice();
2322
+ function maybeOption(arg) {
2323
+ return arg.length > 1 && arg[0] === "-";
2324
+ }
2325
+ let activeVariadicOption = null;
2326
+ while (args.length) {
2327
+ const arg = args.shift();
2328
+ if (arg === "--") {
2329
+ if (dest === unknown) dest.push(arg);
2330
+ dest.push(...args);
2331
+ break;
2332
+ }
2333
+ if (activeVariadicOption && !maybeOption(arg)) {
2334
+ this.emit(`option:${activeVariadicOption.name()}`, arg);
2335
+ continue;
2336
+ }
2337
+ activeVariadicOption = null;
2338
+ if (maybeOption(arg)) {
2339
+ const option = this._findOption(arg);
2340
+ if (option) {
2341
+ if (option.required) {
2342
+ const value = args.shift();
2343
+ if (value === void 0) this.optionMissingArgument(option);
2344
+ this.emit(`option:${option.name()}`, value);
2345
+ } else if (option.optional) {
2346
+ let value = null;
2347
+ if (args.length > 0 && !maybeOption(args[0])) {
2348
+ value = args.shift();
2349
+ }
2350
+ this.emit(`option:${option.name()}`, value);
2351
+ } else {
2352
+ this.emit(`option:${option.name()}`);
2353
+ }
2354
+ activeVariadicOption = option.variadic ? option : null;
2355
+ continue;
2356
+ }
2357
+ }
2358
+ if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
2359
+ const option = this._findOption(`-${arg[1]}`);
2360
+ if (option) {
2361
+ if (option.required || option.optional && this._combineFlagAndOptionalValue) {
2362
+ this.emit(`option:${option.name()}`, arg.slice(2));
2363
+ } else {
2364
+ this.emit(`option:${option.name()}`);
2365
+ args.unshift(`-${arg.slice(2)}`);
2366
+ }
2367
+ continue;
2368
+ }
2369
+ }
2370
+ if (/^--[^=]+=/.test(arg)) {
2371
+ const index = arg.indexOf("=");
2372
+ const option = this._findOption(arg.slice(0, index));
2373
+ if (option && (option.required || option.optional)) {
2374
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
2375
+ continue;
2376
+ }
2377
+ }
2378
+ if (maybeOption(arg)) {
2379
+ dest = unknown;
2380
+ }
2381
+ if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
2382
+ if (this._findCommand(arg)) {
2383
+ operands.push(arg);
2384
+ if (args.length > 0) unknown.push(...args);
2385
+ break;
2386
+ } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
2387
+ operands.push(arg);
2388
+ if (args.length > 0) operands.push(...args);
2389
+ break;
2390
+ } else if (this._defaultCommandName) {
2391
+ unknown.push(arg);
2392
+ if (args.length > 0) unknown.push(...args);
2393
+ break;
2394
+ }
2395
+ }
2396
+ if (this._passThroughOptions) {
2397
+ dest.push(arg);
2398
+ if (args.length > 0) dest.push(...args);
2399
+ break;
2400
+ }
2401
+ dest.push(arg);
2402
+ }
2403
+ return { operands, unknown };
2404
+ }
2405
+ /**
2406
+ * Return an object containing local option values as key-value pairs.
2407
+ *
2408
+ * @return {object}
2409
+ */
2410
+ opts() {
2411
+ if (this._storeOptionsAsProperties) {
2412
+ const result = {};
2413
+ const len = this.options.length;
2414
+ for (let i = 0; i < len; i++) {
2415
+ const key = this.options[i].attributeName();
2416
+ result[key] = key === this._versionOptionName ? this._version : this[key];
2417
+ }
2418
+ return result;
2419
+ }
2420
+ return this._optionValues;
2421
+ }
2422
+ /**
2423
+ * Return an object containing merged local and global option values as key-value pairs.
2424
+ *
2425
+ * @return {object}
2426
+ */
2427
+ optsWithGlobals() {
2428
+ return this._getCommandAndAncestors().reduce(
2429
+ (combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
2430
+ {}
2431
+ );
2432
+ }
2433
+ /**
2434
+ * Display error message and exit (or call exitOverride).
2435
+ *
2436
+ * @param {string} message
2437
+ * @param {object} [errorOptions]
2438
+ * @param {string} [errorOptions.code] - an id string representing the error
2439
+ * @param {number} [errorOptions.exitCode] - used with process.exit
2440
+ */
2441
+ error(message, errorOptions) {
2442
+ this._outputConfiguration.outputError(
2443
+ `${message}
2444
+ `,
2445
+ this._outputConfiguration.writeErr
2446
+ );
2447
+ if (typeof this._showHelpAfterError === "string") {
2448
+ this._outputConfiguration.writeErr(`${this._showHelpAfterError}
2449
+ `);
2450
+ } else if (this._showHelpAfterError) {
2451
+ this._outputConfiguration.writeErr("\n");
2452
+ this.outputHelp({ error: true });
2453
+ }
2454
+ const config = errorOptions || {};
2455
+ const exitCode = config.exitCode || 1;
2456
+ const code = config.code || "commander.error";
2457
+ this._exit(exitCode, code, message);
2458
+ }
2459
+ /**
2460
+ * Apply any option related environment variables, if option does
2461
+ * not have a value from cli or client code.
2462
+ *
2463
+ * @private
2464
+ */
2465
+ _parseOptionsEnv() {
2466
+ this.options.forEach((option) => {
2467
+ if (option.envVar && option.envVar in process2.env) {
2468
+ const optionKey = option.attributeName();
2469
+ if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
2470
+ this.getOptionValueSource(optionKey)
2471
+ )) {
2472
+ if (option.required || option.optional) {
2473
+ this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
2474
+ } else {
2475
+ this.emit(`optionEnv:${option.name()}`);
2476
+ }
2477
+ }
2478
+ }
2479
+ });
2480
+ }
2481
+ /**
2482
+ * Apply any implied option values, if option is undefined or default value.
2483
+ *
2484
+ * @private
2485
+ */
2486
+ _parseOptionsImplied() {
2487
+ const dualHelper = new DualOptions(this.options);
2488
+ const hasCustomOptionValue = (optionKey) => {
2489
+ return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
2490
+ };
2491
+ this.options.filter(
2492
+ (option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
2493
+ this.getOptionValue(option.attributeName()),
2494
+ option
2495
+ )
2496
+ ).forEach((option) => {
2497
+ Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
2498
+ this.setOptionValueWithSource(
2499
+ impliedKey,
2500
+ option.implied[impliedKey],
2501
+ "implied"
2502
+ );
2503
+ });
2504
+ });
2505
+ }
2506
+ /**
2507
+ * Argument `name` is missing.
2508
+ *
2509
+ * @param {string} name
2510
+ * @private
2511
+ */
2512
+ missingArgument(name) {
2513
+ const message = `error: missing required argument '${name}'`;
2514
+ this.error(message, { code: "commander.missingArgument" });
2515
+ }
2516
+ /**
2517
+ * `Option` is missing an argument.
2518
+ *
2519
+ * @param {Option} option
2520
+ * @private
2521
+ */
2522
+ optionMissingArgument(option) {
2523
+ const message = `error: option '${option.flags}' argument missing`;
2524
+ this.error(message, { code: "commander.optionMissingArgument" });
2525
+ }
2526
+ /**
2527
+ * `Option` does not have a value, and is a mandatory option.
2528
+ *
2529
+ * @param {Option} option
2530
+ * @private
2531
+ */
2532
+ missingMandatoryOptionValue(option) {
2533
+ const message = `error: required option '${option.flags}' not specified`;
2534
+ this.error(message, { code: "commander.missingMandatoryOptionValue" });
2535
+ }
2536
+ /**
2537
+ * `Option` conflicts with another option.
2538
+ *
2539
+ * @param {Option} option
2540
+ * @param {Option} conflictingOption
2541
+ * @private
2542
+ */
2543
+ _conflictingOption(option, conflictingOption) {
2544
+ const findBestOptionFromValue = (option2) => {
2545
+ const optionKey = option2.attributeName();
2546
+ const optionValue = this.getOptionValue(optionKey);
2547
+ const negativeOption = this.options.find(
2548
+ (target) => target.negate && optionKey === target.attributeName()
2549
+ );
2550
+ const positiveOption = this.options.find(
2551
+ (target) => !target.negate && optionKey === target.attributeName()
2552
+ );
2553
+ if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
2554
+ return negativeOption;
2555
+ }
2556
+ return positiveOption || option2;
2557
+ };
2558
+ const getErrorMessage = (option2) => {
2559
+ const bestOption = findBestOptionFromValue(option2);
2560
+ const optionKey = bestOption.attributeName();
2561
+ const source = this.getOptionValueSource(optionKey);
2562
+ if (source === "env") {
2563
+ return `environment variable '${bestOption.envVar}'`;
2564
+ }
2565
+ return `option '${bestOption.flags}'`;
2566
+ };
2567
+ const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
2568
+ this.error(message, { code: "commander.conflictingOption" });
2569
+ }
2570
+ /**
2571
+ * Unknown option `flag`.
2572
+ *
2573
+ * @param {string} flag
2574
+ * @private
2575
+ */
2576
+ unknownOption(flag) {
2577
+ if (this._allowUnknownOption) return;
2578
+ let suggestion = "";
2579
+ if (flag.startsWith("--") && this._showSuggestionAfterError) {
2580
+ let candidateFlags = [];
2581
+ let command = this;
2582
+ do {
2583
+ const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
2584
+ candidateFlags = candidateFlags.concat(moreFlags);
2585
+ command = command.parent;
2586
+ } while (command && !command._enablePositionalOptions);
2587
+ suggestion = suggestSimilar(flag, candidateFlags);
2588
+ }
2589
+ const message = `error: unknown option '${flag}'${suggestion}`;
2590
+ this.error(message, { code: "commander.unknownOption" });
2591
+ }
2592
+ /**
2593
+ * Excess arguments, more than expected.
2594
+ *
2595
+ * @param {string[]} receivedArgs
2596
+ * @private
2597
+ */
2598
+ _excessArguments(receivedArgs) {
2599
+ if (this._allowExcessArguments) return;
2600
+ const expected = this.registeredArguments.length;
2601
+ const s = expected === 1 ? "" : "s";
2602
+ const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
2603
+ const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
2604
+ this.error(message, { code: "commander.excessArguments" });
2605
+ }
2606
+ /**
2607
+ * Unknown command.
2608
+ *
2609
+ * @private
2610
+ */
2611
+ unknownCommand() {
2612
+ const unknownName = this.args[0];
2613
+ let suggestion = "";
2614
+ if (this._showSuggestionAfterError) {
2615
+ const candidateNames = [];
2616
+ this.createHelp().visibleCommands(this).forEach((command) => {
2617
+ candidateNames.push(command.name());
2618
+ if (command.alias()) candidateNames.push(command.alias());
2619
+ });
2620
+ suggestion = suggestSimilar(unknownName, candidateNames);
2621
+ }
2622
+ const message = `error: unknown command '${unknownName}'${suggestion}`;
2623
+ this.error(message, { code: "commander.unknownCommand" });
2624
+ }
2625
+ /**
2626
+ * Get or set the program version.
2627
+ *
2628
+ * This method auto-registers the "-V, --version" option which will print the version number.
2629
+ *
2630
+ * You can optionally supply the flags and description to override the defaults.
2631
+ *
2632
+ * @param {string} [str]
2633
+ * @param {string} [flags]
2634
+ * @param {string} [description]
2635
+ * @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
2636
+ */
2637
+ version(str, flags, description) {
2638
+ if (str === void 0) return this._version;
2639
+ this._version = str;
2640
+ flags = flags || "-V, --version";
2641
+ description = description || "output the version number";
2642
+ const versionOption = this.createOption(flags, description);
2643
+ this._versionOptionName = versionOption.attributeName();
2644
+ this._registerOption(versionOption);
2645
+ this.on("option:" + versionOption.name(), () => {
2646
+ this._outputConfiguration.writeOut(`${str}
2647
+ `);
2648
+ this._exit(0, "commander.version", str);
2649
+ });
2650
+ return this;
2651
+ }
2652
+ /**
2653
+ * Set the description.
2654
+ *
2655
+ * @param {string} [str]
2656
+ * @param {object} [argsDescription]
2657
+ * @return {(string|Command)}
2658
+ */
2659
+ description(str, argsDescription) {
2660
+ if (str === void 0 && argsDescription === void 0)
2661
+ return this._description;
2662
+ this._description = str;
2663
+ if (argsDescription) {
2664
+ this._argsDescription = argsDescription;
2665
+ }
2666
+ return this;
2667
+ }
2668
+ /**
2669
+ * Set the summary. Used when listed as subcommand of parent.
2670
+ *
2671
+ * @param {string} [str]
2672
+ * @return {(string|Command)}
2673
+ */
2674
+ summary(str) {
2675
+ if (str === void 0) return this._summary;
2676
+ this._summary = str;
2677
+ return this;
2678
+ }
2679
+ /**
2680
+ * Set an alias for the command.
2681
+ *
2682
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
2683
+ *
2684
+ * @param {string} [alias]
2685
+ * @return {(string|Command)}
2686
+ */
2687
+ alias(alias) {
2688
+ if (alias === void 0) return this._aliases[0];
2689
+ let command = this;
2690
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
2691
+ command = this.commands[this.commands.length - 1];
2692
+ }
2693
+ if (alias === command._name)
2694
+ throw new Error("Command alias can't be the same as its name");
2695
+ const matchingCommand = this.parent?._findCommand(alias);
2696
+ if (matchingCommand) {
2697
+ const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
2698
+ throw new Error(
2699
+ `cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
2700
+ );
2701
+ }
2702
+ command._aliases.push(alias);
2703
+ return this;
2704
+ }
2705
+ /**
2706
+ * Set aliases for the command.
2707
+ *
2708
+ * Only the first alias is shown in the auto-generated help.
2709
+ *
2710
+ * @param {string[]} [aliases]
2711
+ * @return {(string[]|Command)}
2712
+ */
2713
+ aliases(aliases) {
2714
+ if (aliases === void 0) return this._aliases;
2715
+ aliases.forEach((alias) => this.alias(alias));
2716
+ return this;
2717
+ }
2718
+ /**
2719
+ * Set / get the command usage `str`.
2720
+ *
2721
+ * @param {string} [str]
2722
+ * @return {(string|Command)}
2723
+ */
2724
+ usage(str) {
2725
+ if (str === void 0) {
2726
+ if (this._usage) return this._usage;
2727
+ const args = this.registeredArguments.map((arg) => {
2728
+ return humanReadableArgName(arg);
2729
+ });
2730
+ return [].concat(
2731
+ this.options.length || this._helpOption !== null ? "[options]" : [],
2732
+ this.commands.length ? "[command]" : [],
2733
+ this.registeredArguments.length ? args : []
2734
+ ).join(" ");
2735
+ }
2736
+ this._usage = str;
2737
+ return this;
2738
+ }
2739
+ /**
2740
+ * Get or set the name of the command.
2741
+ *
2742
+ * @param {string} [str]
2743
+ * @return {(string|Command)}
2744
+ */
2745
+ name(str) {
2746
+ if (str === void 0) return this._name;
2747
+ this._name = str;
2748
+ return this;
2749
+ }
2750
+ /**
2751
+ * Set the name of the command from script filename, such as process.argv[1],
2752
+ * or require.main.filename, or __filename.
2753
+ *
2754
+ * (Used internally and public although not documented in README.)
2755
+ *
2756
+ * @example
2757
+ * program.nameFromFilename(require.main.filename);
2758
+ *
2759
+ * @param {string} filename
2760
+ * @return {Command}
2761
+ */
2762
+ nameFromFilename(filename) {
2763
+ this._name = path.basename(filename, path.extname(filename));
2764
+ return this;
2765
+ }
2766
+ /**
2767
+ * Get or set the directory for searching for executable subcommands of this command.
2768
+ *
2769
+ * @example
2770
+ * program.executableDir(__dirname);
2771
+ * // or
2772
+ * program.executableDir('subcommands');
2773
+ *
2774
+ * @param {string} [path]
2775
+ * @return {(string|null|Command)}
2776
+ */
2777
+ executableDir(path2) {
2778
+ if (path2 === void 0) return this._executableDir;
2779
+ this._executableDir = path2;
2780
+ return this;
2781
+ }
2782
+ /**
2783
+ * Return program help documentation.
2784
+ *
2785
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
2786
+ * @return {string}
2787
+ */
2788
+ helpInformation(contextOptions) {
2789
+ const helper = this.createHelp();
2790
+ if (helper.helpWidth === void 0) {
2791
+ helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
2792
+ }
2793
+ return helper.formatHelp(this, helper);
2794
+ }
2795
+ /**
2796
+ * @private
2797
+ */
2798
+ _getHelpContext(contextOptions) {
2799
+ contextOptions = contextOptions || {};
2800
+ const context = { error: !!contextOptions.error };
2801
+ let write;
2802
+ if (context.error) {
2803
+ write = (arg) => this._outputConfiguration.writeErr(arg);
2804
+ } else {
2805
+ write = (arg) => this._outputConfiguration.writeOut(arg);
2806
+ }
2807
+ context.write = contextOptions.write || write;
2808
+ context.command = this;
2809
+ return context;
2810
+ }
2811
+ /**
2812
+ * Output help information for this command.
2813
+ *
2814
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2815
+ *
2816
+ * @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2817
+ */
2818
+ outputHelp(contextOptions) {
2819
+ let deprecatedCallback;
2820
+ if (typeof contextOptions === "function") {
2821
+ deprecatedCallback = contextOptions;
2822
+ contextOptions = void 0;
2823
+ }
2824
+ const context = this._getHelpContext(contextOptions);
2825
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
2826
+ this.emit("beforeHelp", context);
2827
+ let helpInformation = this.helpInformation(context);
2828
+ if (deprecatedCallback) {
2829
+ helpInformation = deprecatedCallback(helpInformation);
2830
+ if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
2831
+ throw new Error("outputHelp callback must return a string or a Buffer");
2832
+ }
2833
+ }
2834
+ context.write(helpInformation);
2835
+ if (this._getHelpOption()?.long) {
2836
+ this.emit(this._getHelpOption().long);
2837
+ }
2838
+ this.emit("afterHelp", context);
2839
+ this._getCommandAndAncestors().forEach(
2840
+ (command) => command.emit("afterAllHelp", context)
2841
+ );
2842
+ }
2843
+ /**
2844
+ * You can pass in flags and a description to customise the built-in help option.
2845
+ * Pass in false to disable the built-in help option.
2846
+ *
2847
+ * @example
2848
+ * program.helpOption('-?, --help' 'show help'); // customise
2849
+ * program.helpOption(false); // disable
2850
+ *
2851
+ * @param {(string | boolean)} flags
2852
+ * @param {string} [description]
2853
+ * @return {Command} `this` command for chaining
2854
+ */
2855
+ helpOption(flags, description) {
2856
+ if (typeof flags === "boolean") {
2857
+ if (flags) {
2858
+ this._helpOption = this._helpOption ?? void 0;
2859
+ } else {
2860
+ this._helpOption = null;
2861
+ }
2862
+ return this;
2863
+ }
2864
+ flags = flags ?? "-h, --help";
2865
+ description = description ?? "display help for command";
2866
+ this._helpOption = this.createOption(flags, description);
2867
+ return this;
2868
+ }
2869
+ /**
2870
+ * Lazy create help option.
2871
+ * Returns null if has been disabled with .helpOption(false).
2872
+ *
2873
+ * @returns {(Option | null)} the help option
2874
+ * @package
2875
+ */
2876
+ _getHelpOption() {
2877
+ if (this._helpOption === void 0) {
2878
+ this.helpOption(void 0, void 0);
2879
+ }
2880
+ return this._helpOption;
2881
+ }
2882
+ /**
2883
+ * Supply your own option to use for the built-in help option.
2884
+ * This is an alternative to using helpOption() to customise the flags and description etc.
2885
+ *
2886
+ * @param {Option} option
2887
+ * @return {Command} `this` command for chaining
2888
+ */
2889
+ addHelpOption(option) {
2890
+ this._helpOption = option;
2891
+ return this;
2892
+ }
2893
+ /**
2894
+ * Output help information and exit.
2895
+ *
2896
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2897
+ *
2898
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2899
+ */
2900
+ help(contextOptions) {
2901
+ this.outputHelp(contextOptions);
2902
+ let exitCode = process2.exitCode || 0;
2903
+ if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
2904
+ exitCode = 1;
2905
+ }
2906
+ this._exit(exitCode, "commander.help", "(outputHelp)");
2907
+ }
2908
+ /**
2909
+ * Add additional text to be displayed with the built-in help.
2910
+ *
2911
+ * Position is 'before' or 'after' to affect just this command,
2912
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
2913
+ *
2914
+ * @param {string} position - before or after built-in help
2915
+ * @param {(string | Function)} text - string to add, or a function returning a string
2916
+ * @return {Command} `this` command for chaining
2917
+ */
2918
+ addHelpText(position, text) {
2919
+ const allowedValues = ["beforeAll", "before", "after", "afterAll"];
2920
+ if (!allowedValues.includes(position)) {
2921
+ throw new Error(`Unexpected value for position to addHelpText.
2922
+ Expecting one of '${allowedValues.join("', '")}'`);
2923
+ }
2924
+ const helpEvent = `${position}Help`;
2925
+ this.on(helpEvent, (context) => {
2926
+ let helpStr;
2927
+ if (typeof text === "function") {
2928
+ helpStr = text({ error: context.error, command: context.command });
2929
+ } else {
2930
+ helpStr = text;
2931
+ }
2932
+ if (helpStr) {
2933
+ context.write(`${helpStr}
2934
+ `);
2935
+ }
2936
+ });
2937
+ return this;
2938
+ }
2939
+ /**
2940
+ * Output help information if help flags specified
2941
+ *
2942
+ * @param {Array} args - array of options to search for help flags
2943
+ * @private
2944
+ */
2945
+ _outputHelpIfRequested(args) {
2946
+ const helpOption = this._getHelpOption();
2947
+ const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
2948
+ if (helpRequested) {
2949
+ this.outputHelp();
2950
+ this._exit(0, "commander.helpDisplayed", "(outputHelp)");
2951
+ }
2952
+ }
2953
+ };
2954
+ function incrementNodeInspectorPort(args) {
2955
+ return args.map((arg) => {
2956
+ if (!arg.startsWith("--inspect")) {
2957
+ return arg;
2958
+ }
2959
+ let debugOption;
2960
+ let debugHost = "127.0.0.1";
2961
+ let debugPort = "9229";
2962
+ let match;
2963
+ if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
2964
+ debugOption = match[1];
2965
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2966
+ debugOption = match[1];
2967
+ if (/^\d+$/.test(match[3])) {
2968
+ debugPort = match[3];
2969
+ } else {
2970
+ debugHost = match[3];
2971
+ }
2972
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2973
+ debugOption = match[1];
2974
+ debugHost = match[3];
2975
+ debugPort = match[4];
2976
+ }
2977
+ if (debugOption && debugPort !== "0") {
2978
+ return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
2979
+ }
2980
+ return arg;
2981
+ });
2982
+ }
2983
+ exports.Command = Command2;
2984
+ }
2985
+ });
2986
+
2987
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/index.js
2988
+ var require_commander = __commonJS({
2989
+ "node_modules/.pnpm/commander@12.1.0/node_modules/commander/index.js"(exports) {
2990
+ var { Argument: Argument2 } = require_argument();
2991
+ var { Command: Command2 } = require_command();
2992
+ var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
2993
+ var { Help: Help2 } = require_help();
2994
+ var { Option: Option2 } = require_option();
2995
+ exports.program = new Command2();
2996
+ exports.createCommand = (name) => new Command2(name);
2997
+ exports.createOption = (flags, description) => new Option2(flags, description);
2998
+ exports.createArgument = (name, description) => new Argument2(name, description);
2999
+ exports.Command = Command2;
3000
+ exports.Option = Option2;
3001
+ exports.Argument = Argument2;
3002
+ exports.Help = Help2;
3003
+ exports.CommanderError = CommanderError2;
3004
+ exports.InvalidArgumentError = InvalidArgumentError2;
3005
+ exports.InvalidOptionArgumentError = InvalidArgumentError2;
3006
+ }
3007
+ });
3008
+
3009
+ // node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
3010
+ var import_index = __toESM(require_commander(), 1);
3011
+ var {
3012
+ program,
3013
+ createCommand,
3014
+ createArgument,
3015
+ createOption,
3016
+ CommanderError,
3017
+ InvalidArgumentError,
3018
+ InvalidOptionArgumentError,
3019
+ // deprecated old name
3020
+ Command,
3021
+ Argument,
3022
+ Option,
3023
+ Help
3024
+ } = import_index.default;
3025
+
3026
+ // packages/cli/src/utils/update-check.ts
3027
+ import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
3028
+ import { join } from "node:path";
3029
+ import { spawn } from "node:child_process";
3030
+ var REPO = "0sec-labs/0sec";
3031
+ var INSTALL_URL = `https://raw.githubusercontent.com/${REPO}/main/install.sh`;
3032
+ var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
3033
+ var FETCH_TIMEOUT_MS = 4e3;
3034
+ var INSTALL_TIMEOUT_MS = 12e4;
3035
+ function parseVersion(value) {
3036
+ if (value.length > 128) return null;
3037
+ const match = /^v?(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(value);
3038
+ if (!match) return null;
3039
+ const parts = [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)];
3040
+ if (!parts.every(Number.isSafeInteger)) return null;
3041
+ const prerelease = match[4]?.split(".") ?? [];
3042
+ if (prerelease.some((part) => /^\d+$/.test(part) && part.length > 1 && part.startsWith("0"))) return null;
3043
+ return { parts, prerelease, complete: match[3] !== void 0 };
3044
+ }
3045
+ function compareVersions(a, b) {
3046
+ const left = parseVersion(a);
3047
+ const right = parseVersion(b);
3048
+ if (!left || !right) return 0;
3049
+ for (let i = 0; i < 3; i++) {
3050
+ if (left.parts[i] !== right.parts[i]) return left.parts[i] < right.parts[i] ? -1 : 1;
3051
+ }
3052
+ if (!left.prerelease.length || !right.prerelease.length) {
3053
+ return left.prerelease.length ? -1 : right.prerelease.length ? 1 : 0;
3054
+ }
3055
+ for (let i = 0; i < Math.max(left.prerelease.length, right.prerelease.length); i++) {
3056
+ const l = left.prerelease[i];
3057
+ const r = right.prerelease[i];
3058
+ if (l === void 0) return -1;
3059
+ if (r === void 0) return 1;
3060
+ if (l === r) continue;
3061
+ const ln = /^\d+$/.test(l);
3062
+ const rn = /^\d+$/.test(r);
3063
+ if (ln !== rn) return ln ? -1 : 1;
3064
+ if (ln && l.length !== r.length) return l.length < r.length ? -1 : 1;
3065
+ return l < r ? -1 : 1;
3066
+ }
3067
+ return 0;
3068
+ }
3069
+ function disabled(value) {
3070
+ return value !== void 0 && value !== "" && value !== "0" && value.toLowerCase() !== "false";
3071
+ }
3072
+ function shouldRunCheck(env = process.env, isTty = Boolean(process.stdout.isTTY), policy) {
3073
+ if (!isTty || disabled(env.CI) || disabled(env["0SEC_OFFLINE"]) || disabled(env["0SEC_NO_UPDATE_CHECK"])) return false;
3074
+ if (policy !== void 0) return policy !== "off";
3075
+ return env["0SEC_UPDATE_CHECK"] === "1";
3076
+ }
3077
+ function recent(timestamp, now) {
3078
+ const age = now - Date.parse(timestamp ?? "");
3079
+ return Number.isFinite(age) && age >= 0 && age < CHECK_INTERVAL_MS;
3080
+ }
3081
+ function readCache() {
3082
+ try {
3083
+ const raw = JSON.parse(readFileSync(join(homeStateDir(), "last-update-check"), "utf8"));
3084
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
3085
+ const value = raw;
3086
+ if (typeof value.lastCheckedAt !== "string") return null;
3087
+ return {
3088
+ lastCheckedAt: value.lastCheckedAt,
3089
+ latestVersion: typeof value.latestVersion === "string" ? value.latestVersion : void 0,
3090
+ lastInstallAttemptAt: typeof value.lastInstallAttemptAt === "string" ? value.lastInstallAttemptAt : void 0,
3091
+ lastInstallTag: typeof value.lastInstallTag === "string" ? value.lastInstallTag : void 0
3092
+ };
3093
+ } catch {
3094
+ return null;
3095
+ }
3096
+ }
3097
+ function writeCache(cache) {
3098
+ try {
3099
+ mkdirSync(homeStateDir(), { recursive: true });
3100
+ writeFileSync(join(homeStateDir(), "last-update-check"), JSON.stringify(cache));
3101
+ } catch {
3102
+ }
3103
+ }
3104
+ async function fetchLatestTag() {
3105
+ const controller = new AbortController();
3106
+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
3107
+ try {
3108
+ const response = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`, {
3109
+ headers: { Accept: "application/vnd.github+json", "User-Agent": "0sec-cli/update-check" },
3110
+ signal: controller.signal
3111
+ });
3112
+ if (!response.ok) return null;
3113
+ const data = await response.json();
3114
+ if (typeof data.tag_name !== "string" || data.prerelease === true || data.draft === true) return null;
3115
+ const version = parseVersion(data.tag_name);
3116
+ return version?.complete && version.prerelease.length === 0 ? data.tag_name : null;
3117
+ } catch {
3118
+ return null;
3119
+ } finally {
3120
+ clearTimeout(timer);
3121
+ }
3122
+ }
3123
+ var installInProgress = false;
3124
+ var attemptedAutomaticTags = /* @__PURE__ */ new Set();
3125
+ async function performAutoUpdate(options = {}) {
3126
+ if (process.platform === "win32") return { success: false, installed: false, error: "Automatic installation is unavailable on Windows; download a release from https://github.com/0sec-labs/0sec/releases/latest." };
3127
+ if (disabled(process.env["0SEC_OFFLINE"]) || disabled(process.env["0SEC_NO_UPDATE_CHECK"])) {
3128
+ return { success: false, installed: false, error: "Updates are disabled by the current offline/update policy." };
3129
+ }
3130
+ if (installInProgress) return { success: false, installed: false, error: "An update is already in progress." };
3131
+ installInProgress = true;
3132
+ try {
3133
+ const tag = options.version ?? await fetchLatestTag();
3134
+ const version = tag ? parseVersion(tag) : null;
3135
+ if (!tag || !version?.complete) return { success: false, installed: false, error: "Could not resolve a valid release tag." };
3136
+ const normalizedTag = tag.startsWith("v") ? tag : `v${tag}`;
3137
+ const env = { ...process.env, RELEASE_BASE_URL: `https://github.com/${REPO}/releases/download/${normalizedTag}` };
3138
+ const installDir = options.installDir ?? process.env["0SEC_INSTALL_DIR"];
3139
+ if (installDir !== void 0) env.INSTALL_DIR = installDir;
3140
+ const timeoutMs = Number.isFinite(options.timeoutMs) && options.timeoutMs > 0 ? Math.min(options.timeoutMs, INSTALL_TIMEOUT_MS) : INSTALL_TIMEOUT_MS;
3141
+ return await new Promise((resolve) => {
3142
+ const child = spawn("bash", ["-o", "pipefail", "-c", `curl -fsSL --connect-timeout 10 --max-time 30 "${INSTALL_URL}" | bash`], {
3143
+ stdio: "inherit",
3144
+ env,
3145
+ detached: true
3146
+ });
3147
+ let timedOut = false;
3148
+ let settled = false;
3149
+ let parentSignal;
3150
+ let killTimer;
3151
+ const finish = (result) => {
3152
+ if (settled) return;
3153
+ settled = true;
3154
+ clearTimeout(timer);
3155
+ clearTimeout(killTimer);
3156
+ process.removeListener("SIGINT", onInterrupt);
3157
+ process.removeListener("SIGTERM", onTerminate);
3158
+ resolve(result);
3159
+ };
3160
+ const terminate = (signal) => {
3161
+ if (child.pid === void 0) return;
3162
+ try {
3163
+ process.kill(-child.pid, signal);
3164
+ } catch {
3165
+ }
3166
+ };
3167
+ const interrupt = (signal) => {
3168
+ if (parentSignal || settled) return;
3169
+ parentSignal = signal;
3170
+ clearTimeout(timer);
3171
+ terminate(signal);
3172
+ clearTimeout(killTimer);
3173
+ killTimer = setTimeout(() => {
3174
+ terminate("SIGKILL");
3175
+ finish({ success: false, installed: false, signal, error: `Installer stopped by ${signal}.` });
3176
+ }, 1e3);
3177
+ };
3178
+ const onInterrupt = () => interrupt("SIGINT");
3179
+ const onTerminate = () => interrupt("SIGTERM");
3180
+ const timer = setTimeout(() => {
3181
+ timedOut = true;
3182
+ terminate("SIGTERM");
3183
+ killTimer = setTimeout(() => {
3184
+ terminate("SIGKILL");
3185
+ finish({ success: false, installed: false, exitCode: 1, error: `Installer exceeded its ${timeoutMs}ms deadline.` });
3186
+ }, 1e3);
3187
+ }, timeoutMs);
3188
+ process.on("SIGINT", onInterrupt);
3189
+ process.on("SIGTERM", onTerminate);
3190
+ child.once("error", (error) => finish({ success: false, installed: false, exitCode: 1, error: `Could not start the installer: ${error.message}. Ensure bash and curl are available.` }));
3191
+ child.once("close", (code, signal) => {
3192
+ if (timedOut || parentSignal) return;
3193
+ if (signal) finish({ success: false, installed: false, signal, error: `Installer stopped by ${signal}.` });
3194
+ else if (code === 0) finish({ success: true, installed: true, installedVersion: normalizedTag, exitCode: 0 });
3195
+ else finish({ success: false, installed: false, exitCode: code ?? 1, error: `Installer exited with code ${code ?? 1}.` });
3196
+ });
3197
+ });
3198
+ } catch (error) {
3199
+ return { success: false, installed: false, exitCode: 1, error: error instanceof Error ? error.message : "Update failed." };
3200
+ } finally {
3201
+ installInProgress = false;
3202
+ }
3203
+ }
3204
+ async function maybeNotifyUpdate(currentVersion, options = {}) {
3205
+ const policy = options.policy;
3206
+ if (!shouldRunCheck(process.env, Boolean(process.stdout.isTTY), policy) || !parseVersion(currentVersion)) return;
3207
+ const now = Date.now();
3208
+ let cache = readCache();
3209
+ if (!cache || !recent(cache.lastCheckedAt, now)) {
3210
+ const tag2 = await fetchLatestTag();
3211
+ cache = { ...cache, lastCheckedAt: new Date(now).toISOString(), latestVersion: tag2 ?? cache?.latestVersion };
3212
+ writeCache(cache);
3213
+ }
3214
+ const tag = cache.latestVersion;
3215
+ const candidate = tag ? parseVersion(tag) : null;
3216
+ if (!tag || !candidate?.complete || candidate.prerelease.length > 0 || compareVersions(tag, currentVersion) <= 0) return;
3217
+ if (policy !== "automatic") {
3218
+ process.stderr.write(`[0sec] Update available: ${currentVersion} \u2192 ${tag}. Run 0sec upgrade.
3219
+ `);
3220
+ return;
3221
+ }
3222
+ if (attemptedAutomaticTags.has(tag) || cache.lastInstallTag === tag && recent(cache.lastInstallAttemptAt, now)) return;
3223
+ attemptedAutomaticTags.add(tag);
3224
+ writeCache({ ...cache, lastInstallTag: tag, lastInstallAttemptAt: new Date(now).toISOString() });
3225
+ process.stderr.write(`[0sec] Updating to ${tag} before starting the console\u2026
3226
+ `);
3227
+ const result = await performAutoUpdate({ version: tag });
3228
+ if (result.signal) {
3229
+ process.kill(process.pid, result.signal);
3230
+ return;
3231
+ }
3232
+ process.stderr.write(result.success ? `[0sec] Installed ${result.installedVersion}. This process is still ${currentVersion}; restart to use the update.
3233
+ ` : `[0sec] Update not installed: ${result.error ?? "unknown error"} Continuing with ${currentVersion}.
3234
+ `);
3235
+ }
3236
+ async function runStartupUpdate(version) {
3237
+ if (!shouldRunCheck(process.env, Boolean(process.stdout.isTTY), "notify")) return;
3238
+ const { settings, sources } = loadLayeredSettings();
3239
+ const policy = sources.updatePolicy === "global" ? settings.updatePolicy : void 0;
3240
+ if (policy === "automatic") await maybeNotifyUpdate(version, { policy });
3241
+ else if (policy !== "off") void maybeNotifyUpdate(version, { policy });
3242
+ }
3243
+
3244
+ export {
3245
+ InvalidArgumentError,
3246
+ Command,
3247
+ Option,
3248
+ performAutoUpdate,
3249
+ runStartupUpdate
3250
+ };