@betty-blocks/cli 26.0.0-beta.9 → 26.0.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 (255) hide show
  1. package/assets/app-functions/wasm-template/.wasm-functions +0 -0
  2. package/assets/app-functions/wasm-template/functions/say-hello/1.0/Cargo.lock +449 -0
  3. package/assets/app-functions/wasm-template/functions/say-hello/1.0/Cargo.toml +10 -0
  4. package/assets/app-functions/wasm-template/functions/say-hello/1.0/Justfile +12 -0
  5. package/assets/app-functions/wasm-template/functions/say-hello/1.0/function.json +35 -0
  6. package/assets/app-functions/wasm-template/functions/say-hello/1.0/src/lib.rs +19 -0
  7. package/assets/app-functions/wasm-template/functions/say-hello/1.0/wit/world.wit +13 -0
  8. package/build/bb-blocks-new.d.ts +1 -0
  9. package/build/bb-blocks-new.js +26 -0
  10. package/build/bb-blocks-new.js.map +1 -0
  11. package/build/bb-blocks-publish.d.ts +1 -0
  12. package/build/bb-blocks-publish.js +98 -0
  13. package/build/bb-blocks-publish.js.map +1 -0
  14. package/build/bb-blocks-release.d.ts +1 -0
  15. package/build/bb-blocks-release.js +18 -0
  16. package/build/bb-blocks-release.js.map +1 -0
  17. package/build/bb-blocks.d.ts +1 -0
  18. package/build/bb-blocks.js +17 -0
  19. package/build/bb-blocks.js.map +1 -0
  20. package/build/bb-bundle-init.d.ts +1 -0
  21. package/build/bb-bundle-init.js +33 -0
  22. package/build/bb-bundle-init.js.map +1 -0
  23. package/build/bb-bundle.d.ts +1 -0
  24. package/build/bb-bundle.js +17 -0
  25. package/build/bb-bundle.js.map +1 -0
  26. package/build/bb-components-build.d.ts +1 -0
  27. package/build/bb-components-build.js +416 -0
  28. package/build/bb-components-build.js.map +1 -0
  29. package/build/bb-components-create.d.ts +1 -0
  30. package/build/bb-components-create.js +41 -0
  31. package/build/bb-components-create.js.map +1 -0
  32. package/build/bb-components-generate.d.ts +1 -0
  33. package/build/bb-components-generate.js +168 -0
  34. package/build/bb-components-generate.js.map +1 -0
  35. package/build/bb-components-publish-bundle.d.ts +1 -0
  36. package/build/bb-components-publish-bundle.js +50 -0
  37. package/build/bb-components-publish-bundle.js.map +1 -0
  38. package/build/bb-components-publish.d.ts +1 -0
  39. package/build/bb-components-publish.js +57 -0
  40. package/build/bb-components-publish.js.map +1 -0
  41. package/build/bb-components-serve.d.ts +1 -0
  42. package/build/bb-components-serve.js +35 -0
  43. package/build/bb-components-serve.js.map +1 -0
  44. package/build/bb-components.d.ts +1 -0
  45. package/build/bb-components.js +29 -0
  46. package/build/bb-components.js.map +1 -0
  47. package/build/bb-functions-bump.d.ts +1 -0
  48. package/build/bb-functions-bump.js +37 -0
  49. package/build/bb-functions-bump.js.map +1 -0
  50. package/build/bb-functions-init.d.ts +1 -0
  51. package/build/bb-functions-init.js +31 -0
  52. package/build/bb-functions-init.js.map +1 -0
  53. package/build/bb-functions-login.d.ts +1 -0
  54. package/build/bb-functions-login.js +17 -0
  55. package/build/bb-functions-login.js.map +1 -0
  56. package/build/bb-functions-logout.d.ts +1 -0
  57. package/build/bb-functions-logout.js +10 -0
  58. package/build/bb-functions-logout.js.map +1 -0
  59. package/build/bb-functions-new.d.ts +1 -0
  60. package/build/bb-functions-new.js +25 -0
  61. package/build/bb-functions-new.js.map +1 -0
  62. package/build/bb-functions-publish.d.ts +1 -0
  63. package/build/bb-functions-publish.js +52 -0
  64. package/build/bb-functions-publish.js.map +1 -0
  65. package/build/bb-functions-validate.d.ts +1 -0
  66. package/build/bb-functions-validate.js +17 -0
  67. package/build/bb-functions-validate.js.map +1 -0
  68. package/build/bb-functions.d.ts +1 -0
  69. package/build/bb-functions.js +29 -0
  70. package/build/bb-functions.js.map +1 -0
  71. package/build/bb.d.ts +2 -0
  72. package/build/bb.js +27 -0
  73. package/build/bb.js.map +1 -0
  74. package/build/blocks/blockDefinitions.d.ts +10 -0
  75. package/build/blocks/blockDefinitions.js +62 -0
  76. package/build/blocks/blockDefinitions.js.map +1 -0
  77. package/build/blocks/publishBlocks.d.ts +2 -0
  78. package/build/blocks/publishBlocks.js +54 -0
  79. package/build/blocks/publishBlocks.js.map +1 -0
  80. package/build/blocks/releaseBlocks.d.ts +5 -0
  81. package/build/blocks/releaseBlocks.js +78 -0
  82. package/build/blocks/releaseBlocks.js.map +1 -0
  83. package/build/components/bb-components-functions.d.ts +10 -0
  84. package/build/components/bb-components-functions.js +40 -0
  85. package/build/components/bb-components-functions.js.map +1 -0
  86. package/build/components/comments.d.ts +3 -0
  87. package/build/components/comments.js +78 -0
  88. package/build/components/comments.js.map +1 -0
  89. package/build/components/compatibility.d.ts +7 -0
  90. package/build/components/compatibility.js +60 -0
  91. package/build/components/compatibility.js.map +1 -0
  92. package/build/components/transformers/index.d.ts +3 -0
  93. package/build/components/transformers/index.js +36 -0
  94. package/build/components/transformers/index.js.map +1 -0
  95. package/build/components-build/index.d.ts +2 -0
  96. package/build/components-build/index.js +3 -0
  97. package/build/components-build/index.js.map +1 -0
  98. package/build/components-build/reportDiagnostics.d.ts +2 -0
  99. package/build/components-build/reportDiagnostics.js +13 -0
  100. package/build/components-build/reportDiagnostics.js.map +1 -0
  101. package/build/components-build/styles.d.ts +4 -0
  102. package/build/components-build/styles.js +87 -0
  103. package/build/components-build/styles.js.map +1 -0
  104. package/build/functions/config.d.ts +67 -0
  105. package/build/functions/config.js +190 -0
  106. package/build/functions/config.js.map +1 -0
  107. package/build/functions/createWasmDefinitionFiles.d.ts +4 -0
  108. package/build/functions/createWasmDefinitionFiles.js +61 -0
  109. package/build/functions/createWasmDefinitionFiles.js.map +1 -0
  110. package/build/functions/functionDefinitions.d.ts +23 -0
  111. package/build/functions/functionDefinitions.js +229 -0
  112. package/build/functions/functionDefinitions.js.map +1 -0
  113. package/build/functions/functionVersionBump.d.ts +19 -0
  114. package/build/functions/functionVersionBump.js +62 -0
  115. package/build/functions/functionVersionBump.js.map +1 -0
  116. package/build/functions/publishAppFunctions.d.ts +13 -0
  117. package/build/functions/publishAppFunctions.js +90 -0
  118. package/build/functions/publishAppFunctions.js.map +1 -0
  119. package/build/functions/publishWasmBlockStoreFunctions.d.ts +1 -0
  120. package/build/functions/publishWasmBlockStoreFunctions.js +100 -0
  121. package/build/functions/publishWasmBlockStoreFunctions.js.map +1 -0
  122. package/build/functions/utils.d.ts +2 -0
  123. package/build/functions/utils.js +20 -0
  124. package/build/functions/utils.js.map +1 -0
  125. package/build/functions/validateFunctions.d.ts +3 -0
  126. package/build/functions/validateFunctions.js +23 -0
  127. package/build/functions/validateFunctions.js.map +1 -0
  128. package/build/functions/validations.d.ts +31 -0
  129. package/build/functions/validations.js +140 -0
  130. package/build/functions/validations.js.map +1 -0
  131. package/build/interactions/compatibility.d.ts +3 -0
  132. package/build/interactions/compatibility.js +84 -0
  133. package/build/interactions/compatibility.js.map +1 -0
  134. package/build/interactions/diagnostics.d.ts +2 -0
  135. package/build/interactions/diagnostics.js +23 -0
  136. package/build/interactions/diagnostics.js.map +1 -0
  137. package/build/types.d.ts +377 -0
  138. package/build/types.js +40 -0
  139. package/build/types.js.map +1 -0
  140. package/build/utils/arguments.d.ts +2 -0
  141. package/build/utils/arguments.js +6 -0
  142. package/build/utils/arguments.js.map +1 -0
  143. package/build/utils/checkPackageVersion.d.ts +1 -0
  144. package/build/utils/checkPackageVersion.js +10 -0
  145. package/build/utils/checkPackageVersion.js.map +1 -0
  146. package/build/utils/checkUpdateAvailable.d.ts +1 -0
  147. package/build/utils/checkUpdateAvailable.js +65 -0
  148. package/build/utils/checkUpdateAvailable.js.map +1 -0
  149. package/build/utils/fusionAuth.d.ts +21 -0
  150. package/build/utils/fusionAuth.js +108 -0
  151. package/build/utils/fusionAuth.js.map +1 -0
  152. package/build/utils/hash.d.ts +2 -0
  153. package/build/utils/hash.js +3 -0
  154. package/build/utils/hash.js.map +1 -0
  155. package/build/utils/login.d.ts +15 -0
  156. package/build/utils/login.js +116 -0
  157. package/build/utils/login.js.map +1 -0
  158. package/build/utils/pick.d.ts +7 -0
  159. package/build/utils/pick.js +16 -0
  160. package/build/utils/pick.js.map +1 -0
  161. package/build/utils/readFilesByType.d.ts +2 -0
  162. package/build/utils/readFilesByType.js +23 -0
  163. package/build/utils/readFilesByType.js.map +1 -0
  164. package/build/utils/rootDir.d.ts +2 -0
  165. package/build/utils/rootDir.js +4 -0
  166. package/build/utils/rootDir.js.map +1 -0
  167. package/build/utils/serveComponentSet.d.ts +3 -0
  168. package/build/utils/serveComponentSet.js +52 -0
  169. package/build/utils/serveComponentSet.js.map +1 -0
  170. package/build/utils/transpile.d.ts +2 -0
  171. package/build/utils/transpile.js +25 -0
  172. package/build/utils/transpile.js.map +1 -0
  173. package/build/utils/uploadBlob.d.ts +24 -0
  174. package/build/utils/uploadBlob.js +56 -0
  175. package/build/utils/uploadBlob.js.map +1 -0
  176. package/build/utils/validation.d.ts +4 -0
  177. package/build/utils/validation.js +74 -0
  178. package/build/utils/validation.js.map +1 -0
  179. package/build/validations/component.d.ts +3 -0
  180. package/build/validations/component.js +56 -0
  181. package/build/validations/component.js.map +1 -0
  182. package/build/validations/constants.d.ts +16 -0
  183. package/build/validations/constants.js +208 -0
  184. package/build/validations/constants.js.map +1 -0
  185. package/build/validations/function-block-validations/index.d.ts +22 -0
  186. package/build/validations/function-block-validations/index.js +72 -0
  187. package/build/validations/function-block-validations/index.js.map +1 -0
  188. package/build/validations/interaction.d.ts +3 -0
  189. package/build/validations/interaction.js +22 -0
  190. package/build/validations/interaction.js.map +1 -0
  191. package/build/validations/prefab/action.d.ts +2 -0
  192. package/build/validations/prefab/action.js +99 -0
  193. package/build/validations/prefab/action.js.map +1 -0
  194. package/build/validations/prefab/component.d.ts +10 -0
  195. package/build/validations/prefab/component.js +290 -0
  196. package/build/validations/prefab/component.js.map +1 -0
  197. package/build/validations/prefab/componentOption.d.ts +3 -0
  198. package/build/validations/prefab/componentOption.js +176 -0
  199. package/build/validations/prefab/componentOption.js.map +1 -0
  200. package/build/validations/prefab/interaction.d.ts +2 -0
  201. package/build/validations/prefab/interaction.js +38 -0
  202. package/build/validations/prefab/interaction.js.map +1 -0
  203. package/build/validations/prefab/linkedOption.d.ts +3 -0
  204. package/build/validations/prefab/linkedOption.js +39 -0
  205. package/build/validations/prefab/linkedOption.js.map +1 -0
  206. package/build/validations/prefab/linkedPartial.d.ts +3 -0
  207. package/build/validations/prefab/linkedPartial.js +30 -0
  208. package/build/validations/prefab/linkedPartial.js.map +1 -0
  209. package/build/validations/prefab/variable.d.ts +3 -0
  210. package/build/validations/prefab/variable.js +36 -0
  211. package/build/validations/prefab/variable.js.map +1 -0
  212. package/build/validations/prefab.d.ts +17 -0
  213. package/build/validations/prefab.js +66 -0
  214. package/build/validations/prefab.js.map +1 -0
  215. package/build/validations/styles.d.ts +6 -0
  216. package/build/validations/styles.js +103 -0
  217. package/build/validations/styles.js.map +1 -0
  218. package/package.json +38 -40
  219. package/assets/app-functions/templates/test/helpers.js +0 -3
  220. package/assets/app-functions/templates/test/say-hello.test.js +0 -4
  221. package/assets/functions/packer/package.json +0 -9
  222. package/assets/functions/packer/webpack.config.js +0 -12
  223. package/assets/functions/templates/functions.json +0 -14
  224. package/assets/functions/templates/package.json +0 -11
  225. package/assets/functions/templates/src/all-users.js +0 -14
  226. package/assets/functions/templates/src/get-json.js +0 -9
  227. package/assets/functions/templates/src/index.js +0 -5
  228. package/assets/functions/templates/src/say-hello.js +0 -13
  229. package/build/src/bb-blocks-new.js +0 -6789
  230. package/build/src/bb-blocks-publish.js +0 -32641
  231. package/build/src/bb-blocks-release.js +0 -15528
  232. package/build/src/bb-blocks.js +0 -2149
  233. package/build/src/bb-bundle-init.js +0 -6034
  234. package/build/src/bb-bundle.js +0 -2636
  235. package/build/src/bb-components-build.js +0 -240546
  236. package/build/src/bb-components-create.js +0 -6045
  237. package/build/src/bb-components-generate.js +0 -6173
  238. package/build/src/bb-components-publish-bundle.js +0 -43346
  239. package/build/src/bb-components-publish.js +0 -43353
  240. package/build/src/bb-components-serve.js +0 -15326
  241. package/build/src/bb-components.js +0 -2157
  242. package/build/src/bb-functions-build.js +0 -4284
  243. package/build/src/bb-functions-bump.js +0 -14582
  244. package/build/src/bb-functions-init.js +0 -4749
  245. package/build/src/bb-functions-login.js +0 -15440
  246. package/build/src/bb-functions-logout.js +0 -15434
  247. package/build/src/bb-functions-new.js +0 -9144
  248. package/build/src/bb-functions-publish.js +0 -86693
  249. package/build/src/bb-functions-validate.js +0 -22160
  250. package/build/src/bb-functions.js +0 -2159
  251. package/build/src/bb.js +0 -2740
  252. /package/assets/app-functions/{templates → js-template}/.app-functions +0 -0
  253. /package/assets/app-functions/{templates → js-template}/functions/say-hello/1.0/function.json +0 -0
  254. /package/assets/app-functions/{templates → js-template}/functions/say-hello/1.0/index.js +0 -0
  255. /package/assets/app-functions/{templates → js-template}/package.json +0 -0
@@ -1,2636 +0,0 @@
1
- import { createRequire } from "node:module";
2
- var __create = Object.create;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
- var __export = (target, all) => {
20
- for (var name in all)
21
- __defProp(target, name, {
22
- get: all[name],
23
- enumerable: true,
24
- configurable: true,
25
- set: (newValue) => all[name] = () => newValue
26
- });
27
- };
28
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
-
31
- // node_modules/commander/lib/error.js
32
- var require_error = __commonJS((exports) => {
33
- class CommanderError extends Error {
34
- constructor(exitCode, code, message) {
35
- super(message);
36
- Error.captureStackTrace(this, this.constructor);
37
- this.name = this.constructor.name;
38
- this.code = code;
39
- this.exitCode = exitCode;
40
- this.nestedError = undefined;
41
- }
42
- }
43
-
44
- class InvalidArgumentError extends CommanderError {
45
- constructor(message) {
46
- super(1, "commander.invalidArgument", message);
47
- Error.captureStackTrace(this, this.constructor);
48
- this.name = this.constructor.name;
49
- }
50
- }
51
- exports.CommanderError = CommanderError;
52
- exports.InvalidArgumentError = InvalidArgumentError;
53
- });
54
-
55
- // node_modules/commander/lib/argument.js
56
- var require_argument = __commonJS((exports) => {
57
- var { InvalidArgumentError } = require_error();
58
-
59
- class Argument {
60
- constructor(name, description) {
61
- this.description = description || "";
62
- this.variadic = false;
63
- this.parseArg = undefined;
64
- this.defaultValue = undefined;
65
- this.defaultValueDescription = undefined;
66
- this.argChoices = undefined;
67
- switch (name[0]) {
68
- case "<":
69
- this.required = true;
70
- this._name = name.slice(1, -1);
71
- break;
72
- case "[":
73
- this.required = false;
74
- this._name = name.slice(1, -1);
75
- break;
76
- default:
77
- this.required = true;
78
- this._name = name;
79
- break;
80
- }
81
- if (this._name.length > 3 && this._name.slice(-3) === "...") {
82
- this.variadic = true;
83
- this._name = this._name.slice(0, -3);
84
- }
85
- }
86
- name() {
87
- return this._name;
88
- }
89
- _concatValue(value, previous) {
90
- if (previous === this.defaultValue || !Array.isArray(previous)) {
91
- return [value];
92
- }
93
- return previous.concat(value);
94
- }
95
- default(value, description) {
96
- this.defaultValue = value;
97
- this.defaultValueDescription = description;
98
- return this;
99
- }
100
- argParser(fn) {
101
- this.parseArg = fn;
102
- return this;
103
- }
104
- choices(values) {
105
- this.argChoices = values.slice();
106
- this.parseArg = (arg, previous) => {
107
- if (!this.argChoices.includes(arg)) {
108
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
109
- }
110
- if (this.variadic) {
111
- return this._concatValue(arg, previous);
112
- }
113
- return arg;
114
- };
115
- return this;
116
- }
117
- argRequired() {
118
- this.required = true;
119
- return this;
120
- }
121
- argOptional() {
122
- this.required = false;
123
- return this;
124
- }
125
- }
126
- function humanReadableArgName(arg) {
127
- const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
128
- return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
129
- }
130
- exports.Argument = Argument;
131
- exports.humanReadableArgName = humanReadableArgName;
132
- });
133
-
134
- // node_modules/commander/lib/help.js
135
- var require_help = __commonJS((exports) => {
136
- var { humanReadableArgName } = require_argument();
137
-
138
- class Help {
139
- constructor() {
140
- this.helpWidth = undefined;
141
- this.minWidthToWrap = 40;
142
- this.sortSubcommands = false;
143
- this.sortOptions = false;
144
- this.showGlobalOptions = false;
145
- }
146
- prepareContext(contextOptions) {
147
- this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
148
- }
149
- visibleCommands(cmd) {
150
- const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
151
- const helpCommand = cmd._getHelpCommand();
152
- if (helpCommand && !helpCommand._hidden) {
153
- visibleCommands.push(helpCommand);
154
- }
155
- if (this.sortSubcommands) {
156
- visibleCommands.sort((a, b) => {
157
- return a.name().localeCompare(b.name());
158
- });
159
- }
160
- return visibleCommands;
161
- }
162
- compareOptions(a, b) {
163
- const getSortKey = (option) => {
164
- return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
165
- };
166
- return getSortKey(a).localeCompare(getSortKey(b));
167
- }
168
- visibleOptions(cmd) {
169
- const visibleOptions = cmd.options.filter((option) => !option.hidden);
170
- const helpOption = cmd._getHelpOption();
171
- if (helpOption && !helpOption.hidden) {
172
- const removeShort = helpOption.short && cmd._findOption(helpOption.short);
173
- const removeLong = helpOption.long && cmd._findOption(helpOption.long);
174
- if (!removeShort && !removeLong) {
175
- visibleOptions.push(helpOption);
176
- } else if (helpOption.long && !removeLong) {
177
- visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
178
- } else if (helpOption.short && !removeShort) {
179
- visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
180
- }
181
- }
182
- if (this.sortOptions) {
183
- visibleOptions.sort(this.compareOptions);
184
- }
185
- return visibleOptions;
186
- }
187
- visibleGlobalOptions(cmd) {
188
- if (!this.showGlobalOptions)
189
- return [];
190
- const globalOptions = [];
191
- for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
192
- const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
193
- globalOptions.push(...visibleOptions);
194
- }
195
- if (this.sortOptions) {
196
- globalOptions.sort(this.compareOptions);
197
- }
198
- return globalOptions;
199
- }
200
- visibleArguments(cmd) {
201
- if (cmd._argsDescription) {
202
- cmd.registeredArguments.forEach((argument) => {
203
- argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
204
- });
205
- }
206
- if (cmd.registeredArguments.find((argument) => argument.description)) {
207
- return cmd.registeredArguments;
208
- }
209
- return [];
210
- }
211
- subcommandTerm(cmd) {
212
- const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
213
- return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
214
- }
215
- optionTerm(option) {
216
- return option.flags;
217
- }
218
- argumentTerm(argument) {
219
- return argument.name();
220
- }
221
- longestSubcommandTermLength(cmd, helper) {
222
- return helper.visibleCommands(cmd).reduce((max, command) => {
223
- return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
224
- }, 0);
225
- }
226
- longestOptionTermLength(cmd, helper) {
227
- return helper.visibleOptions(cmd).reduce((max, option) => {
228
- return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
229
- }, 0);
230
- }
231
- longestGlobalOptionTermLength(cmd, helper) {
232
- return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
233
- return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
234
- }, 0);
235
- }
236
- longestArgumentTermLength(cmd, helper) {
237
- return helper.visibleArguments(cmd).reduce((max, argument) => {
238
- return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
239
- }, 0);
240
- }
241
- commandUsage(cmd) {
242
- let cmdName = cmd._name;
243
- if (cmd._aliases[0]) {
244
- cmdName = cmdName + "|" + cmd._aliases[0];
245
- }
246
- let ancestorCmdNames = "";
247
- for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
248
- ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
249
- }
250
- return ancestorCmdNames + cmdName + " " + cmd.usage();
251
- }
252
- commandDescription(cmd) {
253
- return cmd.description();
254
- }
255
- subcommandDescription(cmd) {
256
- return cmd.summary() || cmd.description();
257
- }
258
- optionDescription(option) {
259
- const extraInfo = [];
260
- if (option.argChoices) {
261
- extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
262
- }
263
- if (option.defaultValue !== undefined) {
264
- const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
265
- if (showDefault) {
266
- extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
267
- }
268
- }
269
- if (option.presetArg !== undefined && option.optional) {
270
- extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
271
- }
272
- if (option.envVar !== undefined) {
273
- extraInfo.push(`env: ${option.envVar}`);
274
- }
275
- if (extraInfo.length > 0) {
276
- const extraDescription = `(${extraInfo.join(", ")})`;
277
- if (option.description) {
278
- return `${option.description} ${extraDescription}`;
279
- }
280
- return extraDescription;
281
- }
282
- return option.description;
283
- }
284
- argumentDescription(argument) {
285
- const extraInfo = [];
286
- if (argument.argChoices) {
287
- extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
288
- }
289
- if (argument.defaultValue !== undefined) {
290
- extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
291
- }
292
- if (extraInfo.length > 0) {
293
- const extraDescription = `(${extraInfo.join(", ")})`;
294
- if (argument.description) {
295
- return `${argument.description} ${extraDescription}`;
296
- }
297
- return extraDescription;
298
- }
299
- return argument.description;
300
- }
301
- formatItemList(heading, items, helper) {
302
- if (items.length === 0)
303
- return [];
304
- return [helper.styleTitle(heading), ...items, ""];
305
- }
306
- groupItems(unsortedItems, visibleItems, getGroup) {
307
- const result = new Map;
308
- unsortedItems.forEach((item) => {
309
- const group = getGroup(item);
310
- if (!result.has(group))
311
- result.set(group, []);
312
- });
313
- visibleItems.forEach((item) => {
314
- const group = getGroup(item);
315
- if (!result.has(group)) {
316
- result.set(group, []);
317
- }
318
- result.get(group).push(item);
319
- });
320
- return result;
321
- }
322
- formatHelp(cmd, helper) {
323
- const termWidth = helper.padWidth(cmd, helper);
324
- const helpWidth = helper.helpWidth ?? 80;
325
- function callFormatItem(term, description) {
326
- return helper.formatItem(term, termWidth, description, helper);
327
- }
328
- let output = [
329
- `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
330
- ""
331
- ];
332
- const commandDescription = helper.commandDescription(cmd);
333
- if (commandDescription.length > 0) {
334
- output = output.concat([
335
- helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
336
- ""
337
- ]);
338
- }
339
- const argumentList = helper.visibleArguments(cmd).map((argument) => {
340
- return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
341
- });
342
- output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
343
- const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
344
- optionGroups.forEach((options, group) => {
345
- const optionList = options.map((option) => {
346
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
347
- });
348
- output = output.concat(this.formatItemList(group, optionList, helper));
349
- });
350
- if (helper.showGlobalOptions) {
351
- const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
352
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
353
- });
354
- output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
355
- }
356
- const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
357
- commandGroups.forEach((commands, group) => {
358
- const commandList = commands.map((sub) => {
359
- return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
360
- });
361
- output = output.concat(this.formatItemList(group, commandList, helper));
362
- });
363
- return output.join(`
364
- `);
365
- }
366
- displayWidth(str) {
367
- return stripColor(str).length;
368
- }
369
- styleTitle(str) {
370
- return str;
371
- }
372
- styleUsage(str) {
373
- return str.split(" ").map((word) => {
374
- if (word === "[options]")
375
- return this.styleOptionText(word);
376
- if (word === "[command]")
377
- return this.styleSubcommandText(word);
378
- if (word[0] === "[" || word[0] === "<")
379
- return this.styleArgumentText(word);
380
- return this.styleCommandText(word);
381
- }).join(" ");
382
- }
383
- styleCommandDescription(str) {
384
- return this.styleDescriptionText(str);
385
- }
386
- styleOptionDescription(str) {
387
- return this.styleDescriptionText(str);
388
- }
389
- styleSubcommandDescription(str) {
390
- return this.styleDescriptionText(str);
391
- }
392
- styleArgumentDescription(str) {
393
- return this.styleDescriptionText(str);
394
- }
395
- styleDescriptionText(str) {
396
- return str;
397
- }
398
- styleOptionTerm(str) {
399
- return this.styleOptionText(str);
400
- }
401
- styleSubcommandTerm(str) {
402
- return str.split(" ").map((word) => {
403
- if (word === "[options]")
404
- return this.styleOptionText(word);
405
- if (word[0] === "[" || word[0] === "<")
406
- return this.styleArgumentText(word);
407
- return this.styleSubcommandText(word);
408
- }).join(" ");
409
- }
410
- styleArgumentTerm(str) {
411
- return this.styleArgumentText(str);
412
- }
413
- styleOptionText(str) {
414
- return str;
415
- }
416
- styleArgumentText(str) {
417
- return str;
418
- }
419
- styleSubcommandText(str) {
420
- return str;
421
- }
422
- styleCommandText(str) {
423
- return str;
424
- }
425
- padWidth(cmd, helper) {
426
- return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
427
- }
428
- preformatted(str) {
429
- return /\n[^\S\r\n]/.test(str);
430
- }
431
- formatItem(term, termWidth, description, helper) {
432
- const itemIndent = 2;
433
- const itemIndentStr = " ".repeat(itemIndent);
434
- if (!description)
435
- return itemIndentStr + term;
436
- const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
437
- const spacerWidth = 2;
438
- const helpWidth = this.helpWidth ?? 80;
439
- const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
440
- let formattedDescription;
441
- if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
442
- formattedDescription = description;
443
- } else {
444
- const wrappedDescription = helper.boxWrap(description, remainingWidth);
445
- formattedDescription = wrappedDescription.replace(/\n/g, `
446
- ` + " ".repeat(termWidth + spacerWidth));
447
- }
448
- return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
449
- ${itemIndentStr}`);
450
- }
451
- boxWrap(str, width) {
452
- if (width < this.minWidthToWrap)
453
- return str;
454
- const rawLines = str.split(/\r\n|\n/);
455
- const chunkPattern = /[\s]*[^\s]+/g;
456
- const wrappedLines = [];
457
- rawLines.forEach((line) => {
458
- const chunks = line.match(chunkPattern);
459
- if (chunks === null) {
460
- wrappedLines.push("");
461
- return;
462
- }
463
- let sumChunks = [chunks.shift()];
464
- let sumWidth = this.displayWidth(sumChunks[0]);
465
- chunks.forEach((chunk) => {
466
- const visibleWidth = this.displayWidth(chunk);
467
- if (sumWidth + visibleWidth <= width) {
468
- sumChunks.push(chunk);
469
- sumWidth += visibleWidth;
470
- return;
471
- }
472
- wrappedLines.push(sumChunks.join(""));
473
- const nextChunk = chunk.trimStart();
474
- sumChunks = [nextChunk];
475
- sumWidth = this.displayWidth(nextChunk);
476
- });
477
- wrappedLines.push(sumChunks.join(""));
478
- });
479
- return wrappedLines.join(`
480
- `);
481
- }
482
- }
483
- function stripColor(str) {
484
- const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
485
- return str.replace(sgrPattern, "");
486
- }
487
- exports.Help = Help;
488
- exports.stripColor = stripColor;
489
- });
490
-
491
- // node_modules/commander/lib/option.js
492
- var require_option = __commonJS((exports) => {
493
- var { InvalidArgumentError } = require_error();
494
-
495
- class Option {
496
- constructor(flags, description) {
497
- this.flags = flags;
498
- this.description = description || "";
499
- this.required = flags.includes("<");
500
- this.optional = flags.includes("[");
501
- this.variadic = /\w\.\.\.[>\]]$/.test(flags);
502
- this.mandatory = false;
503
- const optionFlags = splitOptionFlags(flags);
504
- this.short = optionFlags.shortFlag;
505
- this.long = optionFlags.longFlag;
506
- this.negate = false;
507
- if (this.long) {
508
- this.negate = this.long.startsWith("--no-");
509
- }
510
- this.defaultValue = undefined;
511
- this.defaultValueDescription = undefined;
512
- this.presetArg = undefined;
513
- this.envVar = undefined;
514
- this.parseArg = undefined;
515
- this.hidden = false;
516
- this.argChoices = undefined;
517
- this.conflictsWith = [];
518
- this.implied = undefined;
519
- this.helpGroupHeading = undefined;
520
- }
521
- default(value, description) {
522
- this.defaultValue = value;
523
- this.defaultValueDescription = description;
524
- return this;
525
- }
526
- preset(arg) {
527
- this.presetArg = arg;
528
- return this;
529
- }
530
- conflicts(names) {
531
- this.conflictsWith = this.conflictsWith.concat(names);
532
- return this;
533
- }
534
- implies(impliedOptionValues) {
535
- let newImplied = impliedOptionValues;
536
- if (typeof impliedOptionValues === "string") {
537
- newImplied = { [impliedOptionValues]: true };
538
- }
539
- this.implied = Object.assign(this.implied || {}, newImplied);
540
- return this;
541
- }
542
- env(name) {
543
- this.envVar = name;
544
- return this;
545
- }
546
- argParser(fn) {
547
- this.parseArg = fn;
548
- return this;
549
- }
550
- makeOptionMandatory(mandatory = true) {
551
- this.mandatory = !!mandatory;
552
- return this;
553
- }
554
- hideHelp(hide = true) {
555
- this.hidden = !!hide;
556
- return this;
557
- }
558
- _concatValue(value, previous) {
559
- if (previous === this.defaultValue || !Array.isArray(previous)) {
560
- return [value];
561
- }
562
- return previous.concat(value);
563
- }
564
- choices(values) {
565
- this.argChoices = values.slice();
566
- this.parseArg = (arg, previous) => {
567
- if (!this.argChoices.includes(arg)) {
568
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
569
- }
570
- if (this.variadic) {
571
- return this._concatValue(arg, previous);
572
- }
573
- return arg;
574
- };
575
- return this;
576
- }
577
- name() {
578
- if (this.long) {
579
- return this.long.replace(/^--/, "");
580
- }
581
- return this.short.replace(/^-/, "");
582
- }
583
- attributeName() {
584
- if (this.negate) {
585
- return camelcase(this.name().replace(/^no-/, ""));
586
- }
587
- return camelcase(this.name());
588
- }
589
- helpGroup(heading) {
590
- this.helpGroupHeading = heading;
591
- return this;
592
- }
593
- is(arg) {
594
- return this.short === arg || this.long === arg;
595
- }
596
- isBoolean() {
597
- return !this.required && !this.optional && !this.negate;
598
- }
599
- }
600
-
601
- class DualOptions {
602
- constructor(options) {
603
- this.positiveOptions = new Map;
604
- this.negativeOptions = new Map;
605
- this.dualOptions = new Set;
606
- options.forEach((option) => {
607
- if (option.negate) {
608
- this.negativeOptions.set(option.attributeName(), option);
609
- } else {
610
- this.positiveOptions.set(option.attributeName(), option);
611
- }
612
- });
613
- this.negativeOptions.forEach((value, key) => {
614
- if (this.positiveOptions.has(key)) {
615
- this.dualOptions.add(key);
616
- }
617
- });
618
- }
619
- valueFromOption(value, option) {
620
- const optionKey = option.attributeName();
621
- if (!this.dualOptions.has(optionKey))
622
- return true;
623
- const preset = this.negativeOptions.get(optionKey).presetArg;
624
- const negativeValue = preset !== undefined ? preset : false;
625
- return option.negate === (negativeValue === value);
626
- }
627
- }
628
- function camelcase(str) {
629
- return str.split("-").reduce((str2, word) => {
630
- return str2 + word[0].toUpperCase() + word.slice(1);
631
- });
632
- }
633
- function splitOptionFlags(flags) {
634
- let shortFlag;
635
- let longFlag;
636
- const shortFlagExp = /^-[^-]$/;
637
- const longFlagExp = /^--[^-]/;
638
- const flagParts = flags.split(/[ |,]+/).concat("guard");
639
- if (shortFlagExp.test(flagParts[0]))
640
- shortFlag = flagParts.shift();
641
- if (longFlagExp.test(flagParts[0]))
642
- longFlag = flagParts.shift();
643
- if (!shortFlag && shortFlagExp.test(flagParts[0]))
644
- shortFlag = flagParts.shift();
645
- if (!shortFlag && longFlagExp.test(flagParts[0])) {
646
- shortFlag = longFlag;
647
- longFlag = flagParts.shift();
648
- }
649
- if (flagParts[0].startsWith("-")) {
650
- const unsupportedFlag = flagParts[0];
651
- const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
652
- if (/^-[^-][^-]/.test(unsupportedFlag))
653
- throw new Error(`${baseError}
654
- - a short flag is a single dash and a single character
655
- - either use a single dash and a single character (for a short flag)
656
- - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
657
- if (shortFlagExp.test(unsupportedFlag))
658
- throw new Error(`${baseError}
659
- - too many short flags`);
660
- if (longFlagExp.test(unsupportedFlag))
661
- throw new Error(`${baseError}
662
- - too many long flags`);
663
- throw new Error(`${baseError}
664
- - unrecognised flag format`);
665
- }
666
- if (shortFlag === undefined && longFlag === undefined)
667
- throw new Error(`option creation failed due to no flags found in '${flags}'.`);
668
- return { shortFlag, longFlag };
669
- }
670
- exports.Option = Option;
671
- exports.DualOptions = DualOptions;
672
- });
673
-
674
- // node_modules/commander/lib/suggestSimilar.js
675
- var require_suggestSimilar = __commonJS((exports) => {
676
- var maxDistance = 3;
677
- function editDistance(a, b) {
678
- if (Math.abs(a.length - b.length) > maxDistance)
679
- return Math.max(a.length, b.length);
680
- const d = [];
681
- for (let i = 0;i <= a.length; i++) {
682
- d[i] = [i];
683
- }
684
- for (let j = 0;j <= b.length; j++) {
685
- d[0][j] = j;
686
- }
687
- for (let j = 1;j <= b.length; j++) {
688
- for (let i = 1;i <= a.length; i++) {
689
- let cost = 1;
690
- if (a[i - 1] === b[j - 1]) {
691
- cost = 0;
692
- } else {
693
- cost = 1;
694
- }
695
- d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
696
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
697
- d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
698
- }
699
- }
700
- }
701
- return d[a.length][b.length];
702
- }
703
- function suggestSimilar(word, candidates) {
704
- if (!candidates || candidates.length === 0)
705
- return "";
706
- candidates = Array.from(new Set(candidates));
707
- const searchingOptions = word.startsWith("--");
708
- if (searchingOptions) {
709
- word = word.slice(2);
710
- candidates = candidates.map((candidate) => candidate.slice(2));
711
- }
712
- let similar = [];
713
- let bestDistance = maxDistance;
714
- const minSimilarity = 0.4;
715
- candidates.forEach((candidate) => {
716
- if (candidate.length <= 1)
717
- return;
718
- const distance = editDistance(word, candidate);
719
- const length = Math.max(word.length, candidate.length);
720
- const similarity = (length - distance) / length;
721
- if (similarity > minSimilarity) {
722
- if (distance < bestDistance) {
723
- bestDistance = distance;
724
- similar = [candidate];
725
- } else if (distance === bestDistance) {
726
- similar.push(candidate);
727
- }
728
- }
729
- });
730
- similar.sort((a, b) => a.localeCompare(b));
731
- if (searchingOptions) {
732
- similar = similar.map((candidate) => `--${candidate}`);
733
- }
734
- if (similar.length > 1) {
735
- return `
736
- (Did you mean one of ${similar.join(", ")}?)`;
737
- }
738
- if (similar.length === 1) {
739
- return `
740
- (Did you mean ${similar[0]}?)`;
741
- }
742
- return "";
743
- }
744
- exports.suggestSimilar = suggestSimilar;
745
- });
746
-
747
- // node_modules/commander/lib/command.js
748
- var require_command = __commonJS((exports) => {
749
- var EventEmitter = __require("node:events").EventEmitter;
750
- var childProcess = __require("node:child_process");
751
- var path = __require("node:path");
752
- var fs = __require("node:fs");
753
- var process3 = __require("node:process");
754
- var { Argument, humanReadableArgName } = require_argument();
755
- var { CommanderError } = require_error();
756
- var { Help, stripColor } = require_help();
757
- var { Option, DualOptions } = require_option();
758
- var { suggestSimilar } = require_suggestSimilar();
759
-
760
- class Command extends EventEmitter {
761
- constructor(name) {
762
- super();
763
- this.commands = [];
764
- this.options = [];
765
- this.parent = null;
766
- this._allowUnknownOption = false;
767
- this._allowExcessArguments = false;
768
- this.registeredArguments = [];
769
- this._args = this.registeredArguments;
770
- this.args = [];
771
- this.rawArgs = [];
772
- this.processedArgs = [];
773
- this._scriptPath = null;
774
- this._name = name || "";
775
- this._optionValues = {};
776
- this._optionValueSources = {};
777
- this._storeOptionsAsProperties = false;
778
- this._actionHandler = null;
779
- this._executableHandler = false;
780
- this._executableFile = null;
781
- this._executableDir = null;
782
- this._defaultCommandName = null;
783
- this._exitCallback = null;
784
- this._aliases = [];
785
- this._combineFlagAndOptionalValue = true;
786
- this._description = "";
787
- this._summary = "";
788
- this._argsDescription = undefined;
789
- this._enablePositionalOptions = false;
790
- this._passThroughOptions = false;
791
- this._lifeCycleHooks = {};
792
- this._showHelpAfterError = false;
793
- this._showSuggestionAfterError = true;
794
- this._savedState = null;
795
- this._outputConfiguration = {
796
- writeOut: (str) => process3.stdout.write(str),
797
- writeErr: (str) => process3.stderr.write(str),
798
- outputError: (str, write) => write(str),
799
- getOutHelpWidth: () => process3.stdout.isTTY ? process3.stdout.columns : undefined,
800
- getErrHelpWidth: () => process3.stderr.isTTY ? process3.stderr.columns : undefined,
801
- getOutHasColors: () => useColor() ?? (process3.stdout.isTTY && process3.stdout.hasColors?.()),
802
- getErrHasColors: () => useColor() ?? (process3.stderr.isTTY && process3.stderr.hasColors?.()),
803
- stripColor: (str) => stripColor(str)
804
- };
805
- this._hidden = false;
806
- this._helpOption = undefined;
807
- this._addImplicitHelpCommand = undefined;
808
- this._helpCommand = undefined;
809
- this._helpConfiguration = {};
810
- this._helpGroupHeading = undefined;
811
- this._defaultCommandGroup = undefined;
812
- this._defaultOptionGroup = undefined;
813
- }
814
- copyInheritedSettings(sourceCommand) {
815
- this._outputConfiguration = sourceCommand._outputConfiguration;
816
- this._helpOption = sourceCommand._helpOption;
817
- this._helpCommand = sourceCommand._helpCommand;
818
- this._helpConfiguration = sourceCommand._helpConfiguration;
819
- this._exitCallback = sourceCommand._exitCallback;
820
- this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
821
- this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
822
- this._allowExcessArguments = sourceCommand._allowExcessArguments;
823
- this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
824
- this._showHelpAfterError = sourceCommand._showHelpAfterError;
825
- this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
826
- return this;
827
- }
828
- _getCommandAndAncestors() {
829
- const result = [];
830
- for (let command = this;command; command = command.parent) {
831
- result.push(command);
832
- }
833
- return result;
834
- }
835
- command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
836
- let desc = actionOptsOrExecDesc;
837
- let opts = execOpts;
838
- if (typeof desc === "object" && desc !== null) {
839
- opts = desc;
840
- desc = null;
841
- }
842
- opts = opts || {};
843
- const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
844
- const cmd = this.createCommand(name);
845
- if (desc) {
846
- cmd.description(desc);
847
- cmd._executableHandler = true;
848
- }
849
- if (opts.isDefault)
850
- this._defaultCommandName = cmd._name;
851
- cmd._hidden = !!(opts.noHelp || opts.hidden);
852
- cmd._executableFile = opts.executableFile || null;
853
- if (args)
854
- cmd.arguments(args);
855
- this._registerCommand(cmd);
856
- cmd.parent = this;
857
- cmd.copyInheritedSettings(this);
858
- if (desc)
859
- return this;
860
- return cmd;
861
- }
862
- createCommand(name) {
863
- return new Command(name);
864
- }
865
- createHelp() {
866
- return Object.assign(new Help, this.configureHelp());
867
- }
868
- configureHelp(configuration) {
869
- if (configuration === undefined)
870
- return this._helpConfiguration;
871
- this._helpConfiguration = configuration;
872
- return this;
873
- }
874
- configureOutput(configuration) {
875
- if (configuration === undefined)
876
- return this._outputConfiguration;
877
- this._outputConfiguration = Object.assign({}, this._outputConfiguration, configuration);
878
- return this;
879
- }
880
- showHelpAfterError(displayHelp = true) {
881
- if (typeof displayHelp !== "string")
882
- displayHelp = !!displayHelp;
883
- this._showHelpAfterError = displayHelp;
884
- return this;
885
- }
886
- showSuggestionAfterError(displaySuggestion = true) {
887
- this._showSuggestionAfterError = !!displaySuggestion;
888
- return this;
889
- }
890
- addCommand(cmd, opts) {
891
- if (!cmd._name) {
892
- throw new Error(`Command passed to .addCommand() must have a name
893
- - specify the name in Command constructor or using .name()`);
894
- }
895
- opts = opts || {};
896
- if (opts.isDefault)
897
- this._defaultCommandName = cmd._name;
898
- if (opts.noHelp || opts.hidden)
899
- cmd._hidden = true;
900
- this._registerCommand(cmd);
901
- cmd.parent = this;
902
- cmd._checkForBrokenPassThrough();
903
- return this;
904
- }
905
- createArgument(name, description) {
906
- return new Argument(name, description);
907
- }
908
- argument(name, description, parseArg, defaultValue) {
909
- const argument = this.createArgument(name, description);
910
- if (typeof parseArg === "function") {
911
- argument.default(defaultValue).argParser(parseArg);
912
- } else {
913
- argument.default(parseArg);
914
- }
915
- this.addArgument(argument);
916
- return this;
917
- }
918
- arguments(names) {
919
- names.trim().split(/ +/).forEach((detail) => {
920
- this.argument(detail);
921
- });
922
- return this;
923
- }
924
- addArgument(argument) {
925
- const previousArgument = this.registeredArguments.slice(-1)[0];
926
- if (previousArgument && previousArgument.variadic) {
927
- throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
928
- }
929
- if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
930
- throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
931
- }
932
- this.registeredArguments.push(argument);
933
- return this;
934
- }
935
- helpCommand(enableOrNameAndArgs, description) {
936
- if (typeof enableOrNameAndArgs === "boolean") {
937
- this._addImplicitHelpCommand = enableOrNameAndArgs;
938
- if (enableOrNameAndArgs && this._defaultCommandGroup) {
939
- this._initCommandGroup(this._getHelpCommand());
940
- }
941
- return this;
942
- }
943
- const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
944
- const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
945
- const helpDescription = description ?? "display help for command";
946
- const helpCommand = this.createCommand(helpName);
947
- helpCommand.helpOption(false);
948
- if (helpArgs)
949
- helpCommand.arguments(helpArgs);
950
- if (helpDescription)
951
- helpCommand.description(helpDescription);
952
- this._addImplicitHelpCommand = true;
953
- this._helpCommand = helpCommand;
954
- if (enableOrNameAndArgs || description)
955
- this._initCommandGroup(helpCommand);
956
- return this;
957
- }
958
- addHelpCommand(helpCommand, deprecatedDescription) {
959
- if (typeof helpCommand !== "object") {
960
- this.helpCommand(helpCommand, deprecatedDescription);
961
- return this;
962
- }
963
- this._addImplicitHelpCommand = true;
964
- this._helpCommand = helpCommand;
965
- this._initCommandGroup(helpCommand);
966
- return this;
967
- }
968
- _getHelpCommand() {
969
- const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
970
- if (hasImplicitHelpCommand) {
971
- if (this._helpCommand === undefined) {
972
- this.helpCommand(undefined, undefined);
973
- }
974
- return this._helpCommand;
975
- }
976
- return null;
977
- }
978
- hook(event, listener) {
979
- const allowedValues = ["preSubcommand", "preAction", "postAction"];
980
- if (!allowedValues.includes(event)) {
981
- throw new Error(`Unexpected value for event passed to hook : '${event}'.
982
- Expecting one of '${allowedValues.join("', '")}'`);
983
- }
984
- if (this._lifeCycleHooks[event]) {
985
- this._lifeCycleHooks[event].push(listener);
986
- } else {
987
- this._lifeCycleHooks[event] = [listener];
988
- }
989
- return this;
990
- }
991
- exitOverride(fn) {
992
- if (fn) {
993
- this._exitCallback = fn;
994
- } else {
995
- this._exitCallback = (err) => {
996
- if (err.code !== "commander.executeSubCommandAsync") {
997
- throw err;
998
- } else {}
999
- };
1000
- }
1001
- return this;
1002
- }
1003
- _exit(exitCode, code, message) {
1004
- if (this._exitCallback) {
1005
- this._exitCallback(new CommanderError(exitCode, code, message));
1006
- }
1007
- process3.exit(exitCode);
1008
- }
1009
- action(fn) {
1010
- const listener = (args) => {
1011
- const expectedArgsCount = this.registeredArguments.length;
1012
- const actionArgs = args.slice(0, expectedArgsCount);
1013
- if (this._storeOptionsAsProperties) {
1014
- actionArgs[expectedArgsCount] = this;
1015
- } else {
1016
- actionArgs[expectedArgsCount] = this.opts();
1017
- }
1018
- actionArgs.push(this);
1019
- return fn.apply(this, actionArgs);
1020
- };
1021
- this._actionHandler = listener;
1022
- return this;
1023
- }
1024
- createOption(flags, description) {
1025
- return new Option(flags, description);
1026
- }
1027
- _callParseArg(target, value, previous, invalidArgumentMessage) {
1028
- try {
1029
- return target.parseArg(value, previous);
1030
- } catch (err) {
1031
- if (err.code === "commander.invalidArgument") {
1032
- const message = `${invalidArgumentMessage} ${err.message}`;
1033
- this.error(message, { exitCode: err.exitCode, code: err.code });
1034
- }
1035
- throw err;
1036
- }
1037
- }
1038
- _registerOption(option) {
1039
- const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
1040
- if (matchingOption) {
1041
- const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
1042
- throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1043
- - already used by option '${matchingOption.flags}'`);
1044
- }
1045
- this._initOptionGroup(option);
1046
- this.options.push(option);
1047
- }
1048
- _registerCommand(command) {
1049
- const knownBy = (cmd) => {
1050
- return [cmd.name()].concat(cmd.aliases());
1051
- };
1052
- const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
1053
- if (alreadyUsed) {
1054
- const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
1055
- const newCmd = knownBy(command).join("|");
1056
- throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
1057
- }
1058
- this._initCommandGroup(command);
1059
- this.commands.push(command);
1060
- }
1061
- addOption(option) {
1062
- this._registerOption(option);
1063
- const oname = option.name();
1064
- const name = option.attributeName();
1065
- if (option.negate) {
1066
- const positiveLongFlag = option.long.replace(/^--no-/, "--");
1067
- if (!this._findOption(positiveLongFlag)) {
1068
- this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
1069
- }
1070
- } else if (option.defaultValue !== undefined) {
1071
- this.setOptionValueWithSource(name, option.defaultValue, "default");
1072
- }
1073
- const handleOptionValue = (val, invalidValueMessage, valueSource) => {
1074
- if (val == null && option.presetArg !== undefined) {
1075
- val = option.presetArg;
1076
- }
1077
- const oldValue = this.getOptionValue(name);
1078
- if (val !== null && option.parseArg) {
1079
- val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1080
- } else if (val !== null && option.variadic) {
1081
- val = option._concatValue(val, oldValue);
1082
- }
1083
- if (val == null) {
1084
- if (option.negate) {
1085
- val = false;
1086
- } else if (option.isBoolean() || option.optional) {
1087
- val = true;
1088
- } else {
1089
- val = "";
1090
- }
1091
- }
1092
- this.setOptionValueWithSource(name, val, valueSource);
1093
- };
1094
- this.on("option:" + oname, (val) => {
1095
- const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
1096
- handleOptionValue(val, invalidValueMessage, "cli");
1097
- });
1098
- if (option.envVar) {
1099
- this.on("optionEnv:" + oname, (val) => {
1100
- const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
1101
- handleOptionValue(val, invalidValueMessage, "env");
1102
- });
1103
- }
1104
- return this;
1105
- }
1106
- _optionEx(config, flags, description, fn, defaultValue) {
1107
- if (typeof flags === "object" && flags instanceof Option) {
1108
- throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
1109
- }
1110
- const option = this.createOption(flags, description);
1111
- option.makeOptionMandatory(!!config.mandatory);
1112
- if (typeof fn === "function") {
1113
- option.default(defaultValue).argParser(fn);
1114
- } else if (fn instanceof RegExp) {
1115
- const regex = fn;
1116
- fn = (val, def) => {
1117
- const m = regex.exec(val);
1118
- return m ? m[0] : def;
1119
- };
1120
- option.default(defaultValue).argParser(fn);
1121
- } else {
1122
- option.default(fn);
1123
- }
1124
- return this.addOption(option);
1125
- }
1126
- option(flags, description, parseArg, defaultValue) {
1127
- return this._optionEx({}, flags, description, parseArg, defaultValue);
1128
- }
1129
- requiredOption(flags, description, parseArg, defaultValue) {
1130
- return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
1131
- }
1132
- combineFlagAndOptionalValue(combine = true) {
1133
- this._combineFlagAndOptionalValue = !!combine;
1134
- return this;
1135
- }
1136
- allowUnknownOption(allowUnknown = true) {
1137
- this._allowUnknownOption = !!allowUnknown;
1138
- return this;
1139
- }
1140
- allowExcessArguments(allowExcess = true) {
1141
- this._allowExcessArguments = !!allowExcess;
1142
- return this;
1143
- }
1144
- enablePositionalOptions(positional = true) {
1145
- this._enablePositionalOptions = !!positional;
1146
- return this;
1147
- }
1148
- passThroughOptions(passThrough = true) {
1149
- this._passThroughOptions = !!passThrough;
1150
- this._checkForBrokenPassThrough();
1151
- return this;
1152
- }
1153
- _checkForBrokenPassThrough() {
1154
- if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1155
- throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
1156
- }
1157
- }
1158
- storeOptionsAsProperties(storeAsProperties = true) {
1159
- if (this.options.length) {
1160
- throw new Error("call .storeOptionsAsProperties() before adding options");
1161
- }
1162
- if (Object.keys(this._optionValues).length) {
1163
- throw new Error("call .storeOptionsAsProperties() before setting option values");
1164
- }
1165
- this._storeOptionsAsProperties = !!storeAsProperties;
1166
- return this;
1167
- }
1168
- getOptionValue(key) {
1169
- if (this._storeOptionsAsProperties) {
1170
- return this[key];
1171
- }
1172
- return this._optionValues[key];
1173
- }
1174
- setOptionValue(key, value) {
1175
- return this.setOptionValueWithSource(key, value, undefined);
1176
- }
1177
- setOptionValueWithSource(key, value, source) {
1178
- if (this._storeOptionsAsProperties) {
1179
- this[key] = value;
1180
- } else {
1181
- this._optionValues[key] = value;
1182
- }
1183
- this._optionValueSources[key] = source;
1184
- return this;
1185
- }
1186
- getOptionValueSource(key) {
1187
- return this._optionValueSources[key];
1188
- }
1189
- getOptionValueSourceWithGlobals(key) {
1190
- let source;
1191
- this._getCommandAndAncestors().forEach((cmd) => {
1192
- if (cmd.getOptionValueSource(key) !== undefined) {
1193
- source = cmd.getOptionValueSource(key);
1194
- }
1195
- });
1196
- return source;
1197
- }
1198
- _prepareUserArgs(argv, parseOptions) {
1199
- if (argv !== undefined && !Array.isArray(argv)) {
1200
- throw new Error("first parameter to parse must be array or undefined");
1201
- }
1202
- parseOptions = parseOptions || {};
1203
- if (argv === undefined && parseOptions.from === undefined) {
1204
- if (process3.versions?.electron) {
1205
- parseOptions.from = "electron";
1206
- }
1207
- const execArgv = process3.execArgv ?? [];
1208
- if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
1209
- parseOptions.from = "eval";
1210
- }
1211
- }
1212
- if (argv === undefined) {
1213
- argv = process3.argv;
1214
- }
1215
- this.rawArgs = argv.slice();
1216
- let userArgs;
1217
- switch (parseOptions.from) {
1218
- case undefined:
1219
- case "node":
1220
- this._scriptPath = argv[1];
1221
- userArgs = argv.slice(2);
1222
- break;
1223
- case "electron":
1224
- if (process3.defaultApp) {
1225
- this._scriptPath = argv[1];
1226
- userArgs = argv.slice(2);
1227
- } else {
1228
- userArgs = argv.slice(1);
1229
- }
1230
- break;
1231
- case "user":
1232
- userArgs = argv.slice(0);
1233
- break;
1234
- case "eval":
1235
- userArgs = argv.slice(1);
1236
- break;
1237
- default:
1238
- throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
1239
- }
1240
- if (!this._name && this._scriptPath)
1241
- this.nameFromFilename(this._scriptPath);
1242
- this._name = this._name || "program";
1243
- return userArgs;
1244
- }
1245
- parse(argv, parseOptions) {
1246
- this._prepareForParse();
1247
- const userArgs = this._prepareUserArgs(argv, parseOptions);
1248
- this._parseCommand([], userArgs);
1249
- return this;
1250
- }
1251
- async parseAsync(argv, parseOptions) {
1252
- this._prepareForParse();
1253
- const userArgs = this._prepareUserArgs(argv, parseOptions);
1254
- await this._parseCommand([], userArgs);
1255
- return this;
1256
- }
1257
- _prepareForParse() {
1258
- if (this._savedState === null) {
1259
- this.saveStateBeforeParse();
1260
- } else {
1261
- this.restoreStateBeforeParse();
1262
- }
1263
- }
1264
- saveStateBeforeParse() {
1265
- this._savedState = {
1266
- _name: this._name,
1267
- _optionValues: { ...this._optionValues },
1268
- _optionValueSources: { ...this._optionValueSources }
1269
- };
1270
- }
1271
- restoreStateBeforeParse() {
1272
- if (this._storeOptionsAsProperties)
1273
- throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
1274
- - either make a new Command for each call to parse, or stop storing options as properties`);
1275
- this._name = this._savedState._name;
1276
- this._scriptPath = null;
1277
- this.rawArgs = [];
1278
- this._optionValues = { ...this._savedState._optionValues };
1279
- this._optionValueSources = { ...this._savedState._optionValueSources };
1280
- this.args = [];
1281
- this.processedArgs = [];
1282
- }
1283
- _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
1284
- if (fs.existsSync(executableFile))
1285
- return;
1286
- 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";
1287
- const executableMissing = `'${executableFile}' does not exist
1288
- - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1289
- - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1290
- - ${executableDirMessage}`;
1291
- throw new Error(executableMissing);
1292
- }
1293
- _executeSubCommand(subcommand, args) {
1294
- args = args.slice();
1295
- let launchWithNode = false;
1296
- const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1297
- function findFile(baseDir, baseName) {
1298
- const localBin = path.resolve(baseDir, baseName);
1299
- if (fs.existsSync(localBin))
1300
- return localBin;
1301
- if (sourceExt.includes(path.extname(baseName)))
1302
- return;
1303
- const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
1304
- if (foundExt)
1305
- return `${localBin}${foundExt}`;
1306
- return;
1307
- }
1308
- this._checkForMissingMandatoryOptions();
1309
- this._checkForConflictingOptions();
1310
- let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1311
- let executableDir = this._executableDir || "";
1312
- if (this._scriptPath) {
1313
- let resolvedScriptPath;
1314
- try {
1315
- resolvedScriptPath = fs.realpathSync(this._scriptPath);
1316
- } catch {
1317
- resolvedScriptPath = this._scriptPath;
1318
- }
1319
- executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
1320
- }
1321
- if (executableDir) {
1322
- let localFile = findFile(executableDir, executableFile);
1323
- if (!localFile && !subcommand._executableFile && this._scriptPath) {
1324
- const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
1325
- if (legacyName !== this._name) {
1326
- localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1327
- }
1328
- }
1329
- executableFile = localFile || executableFile;
1330
- }
1331
- launchWithNode = sourceExt.includes(path.extname(executableFile));
1332
- let proc;
1333
- if (process3.platform !== "win32") {
1334
- if (launchWithNode) {
1335
- args.unshift(executableFile);
1336
- args = incrementNodeInspectorPort(process3.execArgv).concat(args);
1337
- proc = childProcess.spawn(process3.argv[0], args, { stdio: "inherit" });
1338
- } else {
1339
- proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1340
- }
1341
- } else {
1342
- this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1343
- args.unshift(executableFile);
1344
- args = incrementNodeInspectorPort(process3.execArgv).concat(args);
1345
- proc = childProcess.spawn(process3.execPath, args, { stdio: "inherit" });
1346
- }
1347
- if (!proc.killed) {
1348
- const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
1349
- signals.forEach((signal) => {
1350
- process3.on(signal, () => {
1351
- if (proc.killed === false && proc.exitCode === null) {
1352
- proc.kill(signal);
1353
- }
1354
- });
1355
- });
1356
- }
1357
- const exitCallback = this._exitCallback;
1358
- proc.on("close", (code) => {
1359
- code = code ?? 1;
1360
- if (!exitCallback) {
1361
- process3.exit(code);
1362
- } else {
1363
- exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
1364
- }
1365
- });
1366
- proc.on("error", (err) => {
1367
- if (err.code === "ENOENT") {
1368
- this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1369
- } else if (err.code === "EACCES") {
1370
- throw new Error(`'${executableFile}' not executable`);
1371
- }
1372
- if (!exitCallback) {
1373
- process3.exit(1);
1374
- } else {
1375
- const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
1376
- wrappedError.nestedError = err;
1377
- exitCallback(wrappedError);
1378
- }
1379
- });
1380
- this.runningCommand = proc;
1381
- }
1382
- _dispatchSubcommand(commandName, operands, unknown) {
1383
- const subCommand = this._findCommand(commandName);
1384
- if (!subCommand)
1385
- this.help({ error: true });
1386
- subCommand._prepareForParse();
1387
- let promiseChain;
1388
- promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1389
- promiseChain = this._chainOrCall(promiseChain, () => {
1390
- if (subCommand._executableHandler) {
1391
- this._executeSubCommand(subCommand, operands.concat(unknown));
1392
- } else {
1393
- return subCommand._parseCommand(operands, unknown);
1394
- }
1395
- });
1396
- return promiseChain;
1397
- }
1398
- _dispatchHelpCommand(subcommandName) {
1399
- if (!subcommandName) {
1400
- this.help();
1401
- }
1402
- const subCommand = this._findCommand(subcommandName);
1403
- if (subCommand && !subCommand._executableHandler) {
1404
- subCommand.help();
1405
- }
1406
- return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
1407
- }
1408
- _checkNumberOfArguments() {
1409
- this.registeredArguments.forEach((arg, i) => {
1410
- if (arg.required && this.args[i] == null) {
1411
- this.missingArgument(arg.name());
1412
- }
1413
- });
1414
- if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1415
- return;
1416
- }
1417
- if (this.args.length > this.registeredArguments.length) {
1418
- this._excessArguments(this.args);
1419
- }
1420
- }
1421
- _processArguments() {
1422
- const myParseArg = (argument, value, previous) => {
1423
- let parsedValue = value;
1424
- if (value !== null && argument.parseArg) {
1425
- const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1426
- parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1427
- }
1428
- return parsedValue;
1429
- };
1430
- this._checkNumberOfArguments();
1431
- const processedArgs = [];
1432
- this.registeredArguments.forEach((declaredArg, index) => {
1433
- let value = declaredArg.defaultValue;
1434
- if (declaredArg.variadic) {
1435
- if (index < this.args.length) {
1436
- value = this.args.slice(index);
1437
- if (declaredArg.parseArg) {
1438
- value = value.reduce((processed, v) => {
1439
- return myParseArg(declaredArg, v, processed);
1440
- }, declaredArg.defaultValue);
1441
- }
1442
- } else if (value === undefined) {
1443
- value = [];
1444
- }
1445
- } else if (index < this.args.length) {
1446
- value = this.args[index];
1447
- if (declaredArg.parseArg) {
1448
- value = myParseArg(declaredArg, value, declaredArg.defaultValue);
1449
- }
1450
- }
1451
- processedArgs[index] = value;
1452
- });
1453
- this.processedArgs = processedArgs;
1454
- }
1455
- _chainOrCall(promise, fn) {
1456
- if (promise && promise.then && typeof promise.then === "function") {
1457
- return promise.then(() => fn());
1458
- }
1459
- return fn();
1460
- }
1461
- _chainOrCallHooks(promise, event) {
1462
- let result = promise;
1463
- const hooks = [];
1464
- this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
1465
- hookedCommand._lifeCycleHooks[event].forEach((callback) => {
1466
- hooks.push({ hookedCommand, callback });
1467
- });
1468
- });
1469
- if (event === "postAction") {
1470
- hooks.reverse();
1471
- }
1472
- hooks.forEach((hookDetail) => {
1473
- result = this._chainOrCall(result, () => {
1474
- return hookDetail.callback(hookDetail.hookedCommand, this);
1475
- });
1476
- });
1477
- return result;
1478
- }
1479
- _chainOrCallSubCommandHook(promise, subCommand, event) {
1480
- let result = promise;
1481
- if (this._lifeCycleHooks[event] !== undefined) {
1482
- this._lifeCycleHooks[event].forEach((hook) => {
1483
- result = this._chainOrCall(result, () => {
1484
- return hook(this, subCommand);
1485
- });
1486
- });
1487
- }
1488
- return result;
1489
- }
1490
- _parseCommand(operands, unknown) {
1491
- const parsed = this.parseOptions(unknown);
1492
- this._parseOptionsEnv();
1493
- this._parseOptionsImplied();
1494
- operands = operands.concat(parsed.operands);
1495
- unknown = parsed.unknown;
1496
- this.args = operands.concat(unknown);
1497
- if (operands && this._findCommand(operands[0])) {
1498
- return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
1499
- }
1500
- if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
1501
- return this._dispatchHelpCommand(operands[1]);
1502
- }
1503
- if (this._defaultCommandName) {
1504
- this._outputHelpIfRequested(unknown);
1505
- return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
1506
- }
1507
- if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
1508
- this.help({ error: true });
1509
- }
1510
- this._outputHelpIfRequested(parsed.unknown);
1511
- this._checkForMissingMandatoryOptions();
1512
- this._checkForConflictingOptions();
1513
- const checkForUnknownOptions = () => {
1514
- if (parsed.unknown.length > 0) {
1515
- this.unknownOption(parsed.unknown[0]);
1516
- }
1517
- };
1518
- const commandEvent = `command:${this.name()}`;
1519
- if (this._actionHandler) {
1520
- checkForUnknownOptions();
1521
- this._processArguments();
1522
- let promiseChain;
1523
- promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
1524
- promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
1525
- if (this.parent) {
1526
- promiseChain = this._chainOrCall(promiseChain, () => {
1527
- this.parent.emit(commandEvent, operands, unknown);
1528
- });
1529
- }
1530
- promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
1531
- return promiseChain;
1532
- }
1533
- if (this.parent && this.parent.listenerCount(commandEvent)) {
1534
- checkForUnknownOptions();
1535
- this._processArguments();
1536
- this.parent.emit(commandEvent, operands, unknown);
1537
- } else if (operands.length) {
1538
- if (this._findCommand("*")) {
1539
- return this._dispatchSubcommand("*", operands, unknown);
1540
- }
1541
- if (this.listenerCount("command:*")) {
1542
- this.emit("command:*", operands, unknown);
1543
- } else if (this.commands.length) {
1544
- this.unknownCommand();
1545
- } else {
1546
- checkForUnknownOptions();
1547
- this._processArguments();
1548
- }
1549
- } else if (this.commands.length) {
1550
- checkForUnknownOptions();
1551
- this.help({ error: true });
1552
- } else {
1553
- checkForUnknownOptions();
1554
- this._processArguments();
1555
- }
1556
- }
1557
- _findCommand(name) {
1558
- if (!name)
1559
- return;
1560
- return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
1561
- }
1562
- _findOption(arg) {
1563
- return this.options.find((option) => option.is(arg));
1564
- }
1565
- _checkForMissingMandatoryOptions() {
1566
- this._getCommandAndAncestors().forEach((cmd) => {
1567
- cmd.options.forEach((anOption) => {
1568
- if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
1569
- cmd.missingMandatoryOptionValue(anOption);
1570
- }
1571
- });
1572
- });
1573
- }
1574
- _checkForConflictingLocalOptions() {
1575
- const definedNonDefaultOptions = this.options.filter((option) => {
1576
- const optionKey = option.attributeName();
1577
- if (this.getOptionValue(optionKey) === undefined) {
1578
- return false;
1579
- }
1580
- return this.getOptionValueSource(optionKey) !== "default";
1581
- });
1582
- const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
1583
- optionsWithConflicting.forEach((option) => {
1584
- const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
1585
- if (conflictingAndDefined) {
1586
- this._conflictingOption(option, conflictingAndDefined);
1587
- }
1588
- });
1589
- }
1590
- _checkForConflictingOptions() {
1591
- this._getCommandAndAncestors().forEach((cmd) => {
1592
- cmd._checkForConflictingLocalOptions();
1593
- });
1594
- }
1595
- parseOptions(argv) {
1596
- const operands = [];
1597
- const unknown = [];
1598
- let dest = operands;
1599
- const args = argv.slice();
1600
- function maybeOption(arg) {
1601
- return arg.length > 1 && arg[0] === "-";
1602
- }
1603
- const negativeNumberArg = (arg) => {
1604
- if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg))
1605
- return false;
1606
- return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
1607
- };
1608
- let activeVariadicOption = null;
1609
- while (args.length) {
1610
- const arg = args.shift();
1611
- if (arg === "--") {
1612
- if (dest === unknown)
1613
- dest.push(arg);
1614
- dest.push(...args);
1615
- break;
1616
- }
1617
- if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
1618
- this.emit(`option:${activeVariadicOption.name()}`, arg);
1619
- continue;
1620
- }
1621
- activeVariadicOption = null;
1622
- if (maybeOption(arg)) {
1623
- const option = this._findOption(arg);
1624
- if (option) {
1625
- if (option.required) {
1626
- const value = args.shift();
1627
- if (value === undefined)
1628
- this.optionMissingArgument(option);
1629
- this.emit(`option:${option.name()}`, value);
1630
- } else if (option.optional) {
1631
- let value = null;
1632
- if (args.length > 0 && (!maybeOption(args[0]) || negativeNumberArg(args[0]))) {
1633
- value = args.shift();
1634
- }
1635
- this.emit(`option:${option.name()}`, value);
1636
- } else {
1637
- this.emit(`option:${option.name()}`);
1638
- }
1639
- activeVariadicOption = option.variadic ? option : null;
1640
- continue;
1641
- }
1642
- }
1643
- if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
1644
- const option = this._findOption(`-${arg[1]}`);
1645
- if (option) {
1646
- if (option.required || option.optional && this._combineFlagAndOptionalValue) {
1647
- this.emit(`option:${option.name()}`, arg.slice(2));
1648
- } else {
1649
- this.emit(`option:${option.name()}`);
1650
- args.unshift(`-${arg.slice(2)}`);
1651
- }
1652
- continue;
1653
- }
1654
- }
1655
- if (/^--[^=]+=/.test(arg)) {
1656
- const index = arg.indexOf("=");
1657
- const option = this._findOption(arg.slice(0, index));
1658
- if (option && (option.required || option.optional)) {
1659
- this.emit(`option:${option.name()}`, arg.slice(index + 1));
1660
- continue;
1661
- }
1662
- }
1663
- if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
1664
- dest = unknown;
1665
- }
1666
- if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1667
- if (this._findCommand(arg)) {
1668
- operands.push(arg);
1669
- if (args.length > 0)
1670
- unknown.push(...args);
1671
- break;
1672
- } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1673
- operands.push(arg);
1674
- if (args.length > 0)
1675
- operands.push(...args);
1676
- break;
1677
- } else if (this._defaultCommandName) {
1678
- unknown.push(arg);
1679
- if (args.length > 0)
1680
- unknown.push(...args);
1681
- break;
1682
- }
1683
- }
1684
- if (this._passThroughOptions) {
1685
- dest.push(arg);
1686
- if (args.length > 0)
1687
- dest.push(...args);
1688
- break;
1689
- }
1690
- dest.push(arg);
1691
- }
1692
- return { operands, unknown };
1693
- }
1694
- opts() {
1695
- if (this._storeOptionsAsProperties) {
1696
- const result = {};
1697
- const len = this.options.length;
1698
- for (let i = 0;i < len; i++) {
1699
- const key = this.options[i].attributeName();
1700
- result[key] = key === this._versionOptionName ? this._version : this[key];
1701
- }
1702
- return result;
1703
- }
1704
- return this._optionValues;
1705
- }
1706
- optsWithGlobals() {
1707
- return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
1708
- }
1709
- error(message, errorOptions) {
1710
- this._outputConfiguration.outputError(`${message}
1711
- `, this._outputConfiguration.writeErr);
1712
- if (typeof this._showHelpAfterError === "string") {
1713
- this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1714
- `);
1715
- } else if (this._showHelpAfterError) {
1716
- this._outputConfiguration.writeErr(`
1717
- `);
1718
- this.outputHelp({ error: true });
1719
- }
1720
- const config = errorOptions || {};
1721
- const exitCode = config.exitCode || 1;
1722
- const code = config.code || "commander.error";
1723
- this._exit(exitCode, code, message);
1724
- }
1725
- _parseOptionsEnv() {
1726
- this.options.forEach((option) => {
1727
- if (option.envVar && option.envVar in process3.env) {
1728
- const optionKey = option.attributeName();
1729
- if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
1730
- if (option.required || option.optional) {
1731
- this.emit(`optionEnv:${option.name()}`, process3.env[option.envVar]);
1732
- } else {
1733
- this.emit(`optionEnv:${option.name()}`);
1734
- }
1735
- }
1736
- }
1737
- });
1738
- }
1739
- _parseOptionsImplied() {
1740
- const dualHelper = new DualOptions(this.options);
1741
- const hasCustomOptionValue = (optionKey) => {
1742
- return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
1743
- };
1744
- this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
1745
- Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
1746
- this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
1747
- });
1748
- });
1749
- }
1750
- missingArgument(name) {
1751
- const message = `error: missing required argument '${name}'`;
1752
- this.error(message, { code: "commander.missingArgument" });
1753
- }
1754
- optionMissingArgument(option) {
1755
- const message = `error: option '${option.flags}' argument missing`;
1756
- this.error(message, { code: "commander.optionMissingArgument" });
1757
- }
1758
- missingMandatoryOptionValue(option) {
1759
- const message = `error: required option '${option.flags}' not specified`;
1760
- this.error(message, { code: "commander.missingMandatoryOptionValue" });
1761
- }
1762
- _conflictingOption(option, conflictingOption) {
1763
- const findBestOptionFromValue = (option2) => {
1764
- const optionKey = option2.attributeName();
1765
- const optionValue = this.getOptionValue(optionKey);
1766
- const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
1767
- const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
1768
- if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
1769
- return negativeOption;
1770
- }
1771
- return positiveOption || option2;
1772
- };
1773
- const getErrorMessage = (option2) => {
1774
- const bestOption = findBestOptionFromValue(option2);
1775
- const optionKey = bestOption.attributeName();
1776
- const source = this.getOptionValueSource(optionKey);
1777
- if (source === "env") {
1778
- return `environment variable '${bestOption.envVar}'`;
1779
- }
1780
- return `option '${bestOption.flags}'`;
1781
- };
1782
- const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
1783
- this.error(message, { code: "commander.conflictingOption" });
1784
- }
1785
- unknownOption(flag) {
1786
- if (this._allowUnknownOption)
1787
- return;
1788
- let suggestion = "";
1789
- if (flag.startsWith("--") && this._showSuggestionAfterError) {
1790
- let candidateFlags = [];
1791
- let command = this;
1792
- do {
1793
- const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
1794
- candidateFlags = candidateFlags.concat(moreFlags);
1795
- command = command.parent;
1796
- } while (command && !command._enablePositionalOptions);
1797
- suggestion = suggestSimilar(flag, candidateFlags);
1798
- }
1799
- const message = `error: unknown option '${flag}'${suggestion}`;
1800
- this.error(message, { code: "commander.unknownOption" });
1801
- }
1802
- _excessArguments(receivedArgs) {
1803
- if (this._allowExcessArguments)
1804
- return;
1805
- const expected = this.registeredArguments.length;
1806
- const s = expected === 1 ? "" : "s";
1807
- const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
1808
- const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
1809
- this.error(message, { code: "commander.excessArguments" });
1810
- }
1811
- unknownCommand() {
1812
- const unknownName = this.args[0];
1813
- let suggestion = "";
1814
- if (this._showSuggestionAfterError) {
1815
- const candidateNames = [];
1816
- this.createHelp().visibleCommands(this).forEach((command) => {
1817
- candidateNames.push(command.name());
1818
- if (command.alias())
1819
- candidateNames.push(command.alias());
1820
- });
1821
- suggestion = suggestSimilar(unknownName, candidateNames);
1822
- }
1823
- const message = `error: unknown command '${unknownName}'${suggestion}`;
1824
- this.error(message, { code: "commander.unknownCommand" });
1825
- }
1826
- version(str, flags, description) {
1827
- if (str === undefined)
1828
- return this._version;
1829
- this._version = str;
1830
- flags = flags || "-V, --version";
1831
- description = description || "output the version number";
1832
- const versionOption = this.createOption(flags, description);
1833
- this._versionOptionName = versionOption.attributeName();
1834
- this._registerOption(versionOption);
1835
- this.on("option:" + versionOption.name(), () => {
1836
- this._outputConfiguration.writeOut(`${str}
1837
- `);
1838
- this._exit(0, "commander.version", str);
1839
- });
1840
- return this;
1841
- }
1842
- description(str, argsDescription) {
1843
- if (str === undefined && argsDescription === undefined)
1844
- return this._description;
1845
- this._description = str;
1846
- if (argsDescription) {
1847
- this._argsDescription = argsDescription;
1848
- }
1849
- return this;
1850
- }
1851
- summary(str) {
1852
- if (str === undefined)
1853
- return this._summary;
1854
- this._summary = str;
1855
- return this;
1856
- }
1857
- alias(alias) {
1858
- if (alias === undefined)
1859
- return this._aliases[0];
1860
- let command = this;
1861
- if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1862
- command = this.commands[this.commands.length - 1];
1863
- }
1864
- if (alias === command._name)
1865
- throw new Error("Command alias can't be the same as its name");
1866
- const matchingCommand = this.parent?._findCommand(alias);
1867
- if (matchingCommand) {
1868
- const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
1869
- throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
1870
- }
1871
- command._aliases.push(alias);
1872
- return this;
1873
- }
1874
- aliases(aliases) {
1875
- if (aliases === undefined)
1876
- return this._aliases;
1877
- aliases.forEach((alias) => this.alias(alias));
1878
- return this;
1879
- }
1880
- usage(str) {
1881
- if (str === undefined) {
1882
- if (this._usage)
1883
- return this._usage;
1884
- const args = this.registeredArguments.map((arg) => {
1885
- return humanReadableArgName(arg);
1886
- });
1887
- return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
1888
- }
1889
- this._usage = str;
1890
- return this;
1891
- }
1892
- name(str) {
1893
- if (str === undefined)
1894
- return this._name;
1895
- this._name = str;
1896
- return this;
1897
- }
1898
- helpGroup(heading) {
1899
- if (heading === undefined)
1900
- return this._helpGroupHeading ?? "";
1901
- this._helpGroupHeading = heading;
1902
- return this;
1903
- }
1904
- commandsGroup(heading) {
1905
- if (heading === undefined)
1906
- return this._defaultCommandGroup ?? "";
1907
- this._defaultCommandGroup = heading;
1908
- return this;
1909
- }
1910
- optionsGroup(heading) {
1911
- if (heading === undefined)
1912
- return this._defaultOptionGroup ?? "";
1913
- this._defaultOptionGroup = heading;
1914
- return this;
1915
- }
1916
- _initOptionGroup(option) {
1917
- if (this._defaultOptionGroup && !option.helpGroupHeading)
1918
- option.helpGroup(this._defaultOptionGroup);
1919
- }
1920
- _initCommandGroup(cmd) {
1921
- if (this._defaultCommandGroup && !cmd.helpGroup())
1922
- cmd.helpGroup(this._defaultCommandGroup);
1923
- }
1924
- nameFromFilename(filename) {
1925
- this._name = path.basename(filename, path.extname(filename));
1926
- return this;
1927
- }
1928
- executableDir(path2) {
1929
- if (path2 === undefined)
1930
- return this._executableDir;
1931
- this._executableDir = path2;
1932
- return this;
1933
- }
1934
- helpInformation(contextOptions) {
1935
- const helper = this.createHelp();
1936
- const context = this._getOutputContext(contextOptions);
1937
- helper.prepareContext({
1938
- error: context.error,
1939
- helpWidth: context.helpWidth,
1940
- outputHasColors: context.hasColors
1941
- });
1942
- const text = helper.formatHelp(this, helper);
1943
- if (context.hasColors)
1944
- return text;
1945
- return this._outputConfiguration.stripColor(text);
1946
- }
1947
- _getOutputContext(contextOptions) {
1948
- contextOptions = contextOptions || {};
1949
- const error = !!contextOptions.error;
1950
- let baseWrite;
1951
- let hasColors;
1952
- let helpWidth;
1953
- if (error) {
1954
- baseWrite = (str) => this._outputConfiguration.writeErr(str);
1955
- hasColors = this._outputConfiguration.getErrHasColors();
1956
- helpWidth = this._outputConfiguration.getErrHelpWidth();
1957
- } else {
1958
- baseWrite = (str) => this._outputConfiguration.writeOut(str);
1959
- hasColors = this._outputConfiguration.getOutHasColors();
1960
- helpWidth = this._outputConfiguration.getOutHelpWidth();
1961
- }
1962
- const write = (str) => {
1963
- if (!hasColors)
1964
- str = this._outputConfiguration.stripColor(str);
1965
- return baseWrite(str);
1966
- };
1967
- return { error, write, hasColors, helpWidth };
1968
- }
1969
- outputHelp(contextOptions) {
1970
- let deprecatedCallback;
1971
- if (typeof contextOptions === "function") {
1972
- deprecatedCallback = contextOptions;
1973
- contextOptions = undefined;
1974
- }
1975
- const outputContext = this._getOutputContext(contextOptions);
1976
- const eventContext = {
1977
- error: outputContext.error,
1978
- write: outputContext.write,
1979
- command: this
1980
- };
1981
- this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
1982
- this.emit("beforeHelp", eventContext);
1983
- let helpInformation = this.helpInformation({ error: outputContext.error });
1984
- if (deprecatedCallback) {
1985
- helpInformation = deprecatedCallback(helpInformation);
1986
- if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
1987
- throw new Error("outputHelp callback must return a string or a Buffer");
1988
- }
1989
- }
1990
- outputContext.write(helpInformation);
1991
- if (this._getHelpOption()?.long) {
1992
- this.emit(this._getHelpOption().long);
1993
- }
1994
- this.emit("afterHelp", eventContext);
1995
- this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
1996
- }
1997
- helpOption(flags, description) {
1998
- if (typeof flags === "boolean") {
1999
- if (flags) {
2000
- if (this._helpOption === null)
2001
- this._helpOption = undefined;
2002
- if (this._defaultOptionGroup) {
2003
- this._initOptionGroup(this._getHelpOption());
2004
- }
2005
- } else {
2006
- this._helpOption = null;
2007
- }
2008
- return this;
2009
- }
2010
- this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
2011
- if (flags || description)
2012
- this._initOptionGroup(this._helpOption);
2013
- return this;
2014
- }
2015
- _getHelpOption() {
2016
- if (this._helpOption === undefined) {
2017
- this.helpOption(undefined, undefined);
2018
- }
2019
- return this._helpOption;
2020
- }
2021
- addHelpOption(option) {
2022
- this._helpOption = option;
2023
- this._initOptionGroup(option);
2024
- return this;
2025
- }
2026
- help(contextOptions) {
2027
- this.outputHelp(contextOptions);
2028
- let exitCode = Number(process3.exitCode ?? 0);
2029
- if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
2030
- exitCode = 1;
2031
- }
2032
- this._exit(exitCode, "commander.help", "(outputHelp)");
2033
- }
2034
- addHelpText(position, text) {
2035
- const allowedValues = ["beforeAll", "before", "after", "afterAll"];
2036
- if (!allowedValues.includes(position)) {
2037
- throw new Error(`Unexpected value for position to addHelpText.
2038
- Expecting one of '${allowedValues.join("', '")}'`);
2039
- }
2040
- const helpEvent = `${position}Help`;
2041
- this.on(helpEvent, (context) => {
2042
- let helpStr;
2043
- if (typeof text === "function") {
2044
- helpStr = text({ error: context.error, command: context.command });
2045
- } else {
2046
- helpStr = text;
2047
- }
2048
- if (helpStr) {
2049
- context.write(`${helpStr}
2050
- `);
2051
- }
2052
- });
2053
- return this;
2054
- }
2055
- _outputHelpIfRequested(args) {
2056
- const helpOption = this._getHelpOption();
2057
- const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
2058
- if (helpRequested) {
2059
- this.outputHelp();
2060
- this._exit(0, "commander.helpDisplayed", "(outputHelp)");
2061
- }
2062
- }
2063
- }
2064
- function incrementNodeInspectorPort(args) {
2065
- return args.map((arg) => {
2066
- if (!arg.startsWith("--inspect")) {
2067
- return arg;
2068
- }
2069
- let debugOption;
2070
- let debugHost = "127.0.0.1";
2071
- let debugPort = "9229";
2072
- let match;
2073
- if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
2074
- debugOption = match[1];
2075
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2076
- debugOption = match[1];
2077
- if (/^\d+$/.test(match[3])) {
2078
- debugPort = match[3];
2079
- } else {
2080
- debugHost = match[3];
2081
- }
2082
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2083
- debugOption = match[1];
2084
- debugHost = match[3];
2085
- debugPort = match[4];
2086
- }
2087
- if (debugOption && debugPort !== "0") {
2088
- return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
2089
- }
2090
- return arg;
2091
- });
2092
- }
2093
- function useColor() {
2094
- if (process3.env.NO_COLOR || process3.env.FORCE_COLOR === "0" || process3.env.FORCE_COLOR === "false")
2095
- return false;
2096
- if (process3.env.FORCE_COLOR || process3.env.CLICOLOR_FORCE !== undefined)
2097
- return true;
2098
- return;
2099
- }
2100
- exports.Command = Command;
2101
- exports.useColor = useColor;
2102
- });
2103
-
2104
- // node_modules/commander/index.js
2105
- var require_commander = __commonJS((exports) => {
2106
- var { Argument } = require_argument();
2107
- var { Command } = require_command();
2108
- var { CommanderError, InvalidArgumentError } = require_error();
2109
- var { Help } = require_help();
2110
- var { Option } = require_option();
2111
- exports.program = new Command;
2112
- exports.createCommand = (name) => new Command(name);
2113
- exports.createOption = (flags, description) => new Option(flags, description);
2114
- exports.createArgument = (name, description) => new Argument(name, description);
2115
- exports.Command = Command;
2116
- exports.Option = Option;
2117
- exports.Argument = Argument;
2118
- exports.Help = Help;
2119
- exports.CommanderError = CommanderError;
2120
- exports.InvalidArgumentError = InvalidArgumentError;
2121
- exports.InvalidOptionArgumentError = InvalidArgumentError;
2122
- });
2123
-
2124
- // node_modules/chalk/source/vendor/ansi-styles/index.js
2125
- var ANSI_BACKGROUND_OFFSET = 10;
2126
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
2127
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
2128
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
2129
- var styles = {
2130
- modifier: {
2131
- reset: [0, 0],
2132
- bold: [1, 22],
2133
- dim: [2, 22],
2134
- italic: [3, 23],
2135
- underline: [4, 24],
2136
- overline: [53, 55],
2137
- inverse: [7, 27],
2138
- hidden: [8, 28],
2139
- strikethrough: [9, 29]
2140
- },
2141
- color: {
2142
- black: [30, 39],
2143
- red: [31, 39],
2144
- green: [32, 39],
2145
- yellow: [33, 39],
2146
- blue: [34, 39],
2147
- magenta: [35, 39],
2148
- cyan: [36, 39],
2149
- white: [37, 39],
2150
- blackBright: [90, 39],
2151
- gray: [90, 39],
2152
- grey: [90, 39],
2153
- redBright: [91, 39],
2154
- greenBright: [92, 39],
2155
- yellowBright: [93, 39],
2156
- blueBright: [94, 39],
2157
- magentaBright: [95, 39],
2158
- cyanBright: [96, 39],
2159
- whiteBright: [97, 39]
2160
- },
2161
- bgColor: {
2162
- bgBlack: [40, 49],
2163
- bgRed: [41, 49],
2164
- bgGreen: [42, 49],
2165
- bgYellow: [43, 49],
2166
- bgBlue: [44, 49],
2167
- bgMagenta: [45, 49],
2168
- bgCyan: [46, 49],
2169
- bgWhite: [47, 49],
2170
- bgBlackBright: [100, 49],
2171
- bgGray: [100, 49],
2172
- bgGrey: [100, 49],
2173
- bgRedBright: [101, 49],
2174
- bgGreenBright: [102, 49],
2175
- bgYellowBright: [103, 49],
2176
- bgBlueBright: [104, 49],
2177
- bgMagentaBright: [105, 49],
2178
- bgCyanBright: [106, 49],
2179
- bgWhiteBright: [107, 49]
2180
- }
2181
- };
2182
- var modifierNames = Object.keys(styles.modifier);
2183
- var foregroundColorNames = Object.keys(styles.color);
2184
- var backgroundColorNames = Object.keys(styles.bgColor);
2185
- var colorNames = [...foregroundColorNames, ...backgroundColorNames];
2186
- function assembleStyles() {
2187
- const codes = new Map;
2188
- for (const [groupName, group] of Object.entries(styles)) {
2189
- for (const [styleName, style] of Object.entries(group)) {
2190
- styles[styleName] = {
2191
- open: `\x1B[${style[0]}m`,
2192
- close: `\x1B[${style[1]}m`
2193
- };
2194
- group[styleName] = styles[styleName];
2195
- codes.set(style[0], style[1]);
2196
- }
2197
- Object.defineProperty(styles, groupName, {
2198
- value: group,
2199
- enumerable: false
2200
- });
2201
- }
2202
- Object.defineProperty(styles, "codes", {
2203
- value: codes,
2204
- enumerable: false
2205
- });
2206
- styles.color.close = "\x1B[39m";
2207
- styles.bgColor.close = "\x1B[49m";
2208
- styles.color.ansi = wrapAnsi16();
2209
- styles.color.ansi256 = wrapAnsi256();
2210
- styles.color.ansi16m = wrapAnsi16m();
2211
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
2212
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
2213
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
2214
- Object.defineProperties(styles, {
2215
- rgbToAnsi256: {
2216
- value(red, green, blue) {
2217
- if (red === green && green === blue) {
2218
- if (red < 8) {
2219
- return 16;
2220
- }
2221
- if (red > 248) {
2222
- return 231;
2223
- }
2224
- return Math.round((red - 8) / 247 * 24) + 232;
2225
- }
2226
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
2227
- },
2228
- enumerable: false
2229
- },
2230
- hexToRgb: {
2231
- value(hex) {
2232
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
2233
- if (!matches) {
2234
- return [0, 0, 0];
2235
- }
2236
- let [colorString] = matches;
2237
- if (colorString.length === 3) {
2238
- colorString = [...colorString].map((character) => character + character).join("");
2239
- }
2240
- const integer = Number.parseInt(colorString, 16);
2241
- return [
2242
- integer >> 16 & 255,
2243
- integer >> 8 & 255,
2244
- integer & 255
2245
- ];
2246
- },
2247
- enumerable: false
2248
- },
2249
- hexToAnsi256: {
2250
- value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
2251
- enumerable: false
2252
- },
2253
- ansi256ToAnsi: {
2254
- value(code) {
2255
- if (code < 8) {
2256
- return 30 + code;
2257
- }
2258
- if (code < 16) {
2259
- return 90 + (code - 8);
2260
- }
2261
- let red;
2262
- let green;
2263
- let blue;
2264
- if (code >= 232) {
2265
- red = ((code - 232) * 10 + 8) / 255;
2266
- green = red;
2267
- blue = red;
2268
- } else {
2269
- code -= 16;
2270
- const remainder = code % 36;
2271
- red = Math.floor(code / 36) / 5;
2272
- green = Math.floor(remainder / 6) / 5;
2273
- blue = remainder % 6 / 5;
2274
- }
2275
- const value = Math.max(red, green, blue) * 2;
2276
- if (value === 0) {
2277
- return 30;
2278
- }
2279
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
2280
- if (value === 2) {
2281
- result += 60;
2282
- }
2283
- return result;
2284
- },
2285
- enumerable: false
2286
- },
2287
- rgbToAnsi: {
2288
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
2289
- enumerable: false
2290
- },
2291
- hexToAnsi: {
2292
- value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
2293
- enumerable: false
2294
- }
2295
- });
2296
- return styles;
2297
- }
2298
- var ansiStyles = assembleStyles();
2299
- var ansi_styles_default = ansiStyles;
2300
-
2301
- // node_modules/chalk/source/vendor/supports-color/index.js
2302
- import process2 from "node:process";
2303
- import os from "node:os";
2304
- import tty from "node:tty";
2305
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
2306
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
2307
- const position = argv.indexOf(prefix + flag);
2308
- const terminatorPosition = argv.indexOf("--");
2309
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
2310
- }
2311
- var { env } = process2;
2312
- var flagForceColor;
2313
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
2314
- flagForceColor = 0;
2315
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
2316
- flagForceColor = 1;
2317
- }
2318
- function envForceColor() {
2319
- if ("FORCE_COLOR" in env) {
2320
- if (env.FORCE_COLOR === "true") {
2321
- return 1;
2322
- }
2323
- if (env.FORCE_COLOR === "false") {
2324
- return 0;
2325
- }
2326
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
2327
- }
2328
- }
2329
- function translateLevel(level) {
2330
- if (level === 0) {
2331
- return false;
2332
- }
2333
- return {
2334
- level,
2335
- hasBasic: true,
2336
- has256: level >= 2,
2337
- has16m: level >= 3
2338
- };
2339
- }
2340
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
2341
- const noFlagForceColor = envForceColor();
2342
- if (noFlagForceColor !== undefined) {
2343
- flagForceColor = noFlagForceColor;
2344
- }
2345
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
2346
- if (forceColor === 0) {
2347
- return 0;
2348
- }
2349
- if (sniffFlags) {
2350
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
2351
- return 3;
2352
- }
2353
- if (hasFlag("color=256")) {
2354
- return 2;
2355
- }
2356
- }
2357
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
2358
- return 1;
2359
- }
2360
- if (haveStream && !streamIsTTY && forceColor === undefined) {
2361
- return 0;
2362
- }
2363
- const min = forceColor || 0;
2364
- if (env.TERM === "dumb") {
2365
- return min;
2366
- }
2367
- if (process2.platform === "win32") {
2368
- const osRelease = os.release().split(".");
2369
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
2370
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
2371
- }
2372
- return 1;
2373
- }
2374
- if ("CI" in env) {
2375
- if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
2376
- return 3;
2377
- }
2378
- if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
2379
- return 1;
2380
- }
2381
- return min;
2382
- }
2383
- if ("TEAMCITY_VERSION" in env) {
2384
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
2385
- }
2386
- if (env.COLORTERM === "truecolor") {
2387
- return 3;
2388
- }
2389
- if (env.TERM === "xterm-kitty") {
2390
- return 3;
2391
- }
2392
- if (env.TERM === "xterm-ghostty") {
2393
- return 3;
2394
- }
2395
- if ("TERM_PROGRAM" in env) {
2396
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
2397
- switch (env.TERM_PROGRAM) {
2398
- case "iTerm.app": {
2399
- return version >= 3 ? 3 : 2;
2400
- }
2401
- case "Apple_Terminal": {
2402
- return 2;
2403
- }
2404
- }
2405
- }
2406
- if (/-256(color)?$/i.test(env.TERM)) {
2407
- return 2;
2408
- }
2409
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
2410
- return 1;
2411
- }
2412
- if ("COLORTERM" in env) {
2413
- return 1;
2414
- }
2415
- return min;
2416
- }
2417
- function createSupportsColor(stream, options = {}) {
2418
- const level = _supportsColor(stream, {
2419
- streamIsTTY: stream && stream.isTTY,
2420
- ...options
2421
- });
2422
- return translateLevel(level);
2423
- }
2424
- var supportsColor = {
2425
- stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
2426
- stderr: createSupportsColor({ isTTY: tty.isatty(2) })
2427
- };
2428
- var supports_color_default = supportsColor;
2429
-
2430
- // node_modules/chalk/source/utilities.js
2431
- function stringReplaceAll(string, substring, replacer) {
2432
- let index = string.indexOf(substring);
2433
- if (index === -1) {
2434
- return string;
2435
- }
2436
- const substringLength = substring.length;
2437
- let endIndex = 0;
2438
- let returnValue = "";
2439
- do {
2440
- returnValue += string.slice(endIndex, index) + substring + replacer;
2441
- endIndex = index + substringLength;
2442
- index = string.indexOf(substring, endIndex);
2443
- } while (index !== -1);
2444
- returnValue += string.slice(endIndex);
2445
- return returnValue;
2446
- }
2447
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
2448
- let endIndex = 0;
2449
- let returnValue = "";
2450
- do {
2451
- const gotCR = string[index - 1] === "\r";
2452
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
2453
- ` : `
2454
- `) + postfix;
2455
- endIndex = index + 1;
2456
- index = string.indexOf(`
2457
- `, endIndex);
2458
- } while (index !== -1);
2459
- returnValue += string.slice(endIndex);
2460
- return returnValue;
2461
- }
2462
-
2463
- // node_modules/chalk/source/index.js
2464
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
2465
- var GENERATOR = Symbol("GENERATOR");
2466
- var STYLER = Symbol("STYLER");
2467
- var IS_EMPTY = Symbol("IS_EMPTY");
2468
- var levelMapping = [
2469
- "ansi",
2470
- "ansi",
2471
- "ansi256",
2472
- "ansi16m"
2473
- ];
2474
- var styles2 = Object.create(null);
2475
- var applyOptions = (object, options = {}) => {
2476
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2477
- throw new Error("The `level` option should be an integer from 0 to 3");
2478
- }
2479
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
2480
- object.level = options.level === undefined ? colorLevel : options.level;
2481
- };
2482
- var chalkFactory = (options) => {
2483
- const chalk = (...strings) => strings.join(" ");
2484
- applyOptions(chalk, options);
2485
- Object.setPrototypeOf(chalk, createChalk.prototype);
2486
- return chalk;
2487
- };
2488
- function createChalk(options) {
2489
- return chalkFactory(options);
2490
- }
2491
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
2492
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
2493
- styles2[styleName] = {
2494
- get() {
2495
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
2496
- Object.defineProperty(this, styleName, { value: builder });
2497
- return builder;
2498
- }
2499
- };
2500
- }
2501
- styles2.visible = {
2502
- get() {
2503
- const builder = createBuilder(this, this[STYLER], true);
2504
- Object.defineProperty(this, "visible", { value: builder });
2505
- return builder;
2506
- }
2507
- };
2508
- var getModelAnsi = (model, level, type, ...arguments_) => {
2509
- if (model === "rgb") {
2510
- if (level === "ansi16m") {
2511
- return ansi_styles_default[type].ansi16m(...arguments_);
2512
- }
2513
- if (level === "ansi256") {
2514
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
2515
- }
2516
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
2517
- }
2518
- if (model === "hex") {
2519
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
2520
- }
2521
- return ansi_styles_default[type][model](...arguments_);
2522
- };
2523
- var usedModels = ["rgb", "hex", "ansi256"];
2524
- for (const model of usedModels) {
2525
- styles2[model] = {
2526
- get() {
2527
- const { level } = this;
2528
- return function(...arguments_) {
2529
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
2530
- return createBuilder(this, styler, this[IS_EMPTY]);
2531
- };
2532
- }
2533
- };
2534
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
2535
- styles2[bgModel] = {
2536
- get() {
2537
- const { level } = this;
2538
- return function(...arguments_) {
2539
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
2540
- return createBuilder(this, styler, this[IS_EMPTY]);
2541
- };
2542
- }
2543
- };
2544
- }
2545
- var proto = Object.defineProperties(() => {}, {
2546
- ...styles2,
2547
- level: {
2548
- enumerable: true,
2549
- get() {
2550
- return this[GENERATOR].level;
2551
- },
2552
- set(level) {
2553
- this[GENERATOR].level = level;
2554
- }
2555
- }
2556
- });
2557
- var createStyler = (open, close, parent) => {
2558
- let openAll;
2559
- let closeAll;
2560
- if (parent === undefined) {
2561
- openAll = open;
2562
- closeAll = close;
2563
- } else {
2564
- openAll = parent.openAll + open;
2565
- closeAll = close + parent.closeAll;
2566
- }
2567
- return {
2568
- open,
2569
- close,
2570
- openAll,
2571
- closeAll,
2572
- parent
2573
- };
2574
- };
2575
- var createBuilder = (self, _styler, _isEmpty) => {
2576
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
2577
- Object.setPrototypeOf(builder, proto);
2578
- builder[GENERATOR] = self;
2579
- builder[STYLER] = _styler;
2580
- builder[IS_EMPTY] = _isEmpty;
2581
- return builder;
2582
- };
2583
- var applyStyle = (self, string) => {
2584
- if (self.level <= 0 || !string) {
2585
- return self[IS_EMPTY] ? "" : string;
2586
- }
2587
- let styler = self[STYLER];
2588
- if (styler === undefined) {
2589
- return string;
2590
- }
2591
- const { openAll, closeAll } = styler;
2592
- if (string.includes("\x1B")) {
2593
- while (styler !== undefined) {
2594
- string = stringReplaceAll(string, styler.close, styler.open);
2595
- styler = styler.parent;
2596
- }
2597
- }
2598
- const lfIndex = string.indexOf(`
2599
- `);
2600
- if (lfIndex !== -1) {
2601
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
2602
- }
2603
- return openAll + string + closeAll;
2604
- };
2605
- Object.defineProperties(createChalk.prototype, styles2);
2606
- var chalk = createChalk();
2607
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
2608
- var source_default = chalk;
2609
-
2610
- // node_modules/commander/esm.mjs
2611
- var import__ = __toESM(require_commander(), 1);
2612
- var {
2613
- program,
2614
- createCommand,
2615
- createArgument,
2616
- createOption,
2617
- CommanderError,
2618
- InvalidArgumentError,
2619
- InvalidOptionArgumentError,
2620
- Command,
2621
- Argument,
2622
- Option,
2623
- Help
2624
- } = import__.default;
2625
-
2626
- // src/bb-bundle.ts
2627
- var availableCommands = ["init"];
2628
- var program2 = new Command;
2629
- program2.usage(`<${availableCommands.join("|")}>`).name("bb bundle").command("init <path>", "create a new vendor bundle").on("command:*", ([command]) => {
2630
- if (!availableCommands.includes(command)) {
2631
- console.error(source_default.red(`
2632
- Invalid command: %s
2633
- `), command);
2634
- program2.outputHelp();
2635
- }
2636
- }).parse(process.argv);