@clerc/plugin-completions 1.0.0-beta.27 → 1.0.0-beta.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,1526 +1,6 @@
1
1
  import t from "@bomb.sh/tab";
2
- import { Clerc, DOUBLE_DASH, NoCommandSpecifiedError, NoSuchCommandError, Types, definePlugin, normalizeFlagValue, resolveCommand } from "@clerc/core";
3
- import tty from "node:tty";
2
+ import { Types, definePlugin, extractParameterInfo, normalizeFlagValue, normalizeParameterValue } from "@clerc/core";
4
3
 
5
- //#region rolldown:runtime
6
- var __create = Object.create;
7
- var __defProp = Object.defineProperty;
8
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
- var __getOwnPropNames = Object.getOwnPropertyNames;
10
- var __getProtoOf = Object.getPrototypeOf;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
13
- var __export = (all, symbols) => {
14
- let target = {};
15
- for (var name in all) {
16
- __defProp(target, name, {
17
- get: all[name],
18
- enumerable: true
19
- });
20
- }
21
- if (symbols) {
22
- __defProp(target, Symbol.toStringTag, { value: "Module" });
23
- }
24
- return target;
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
29
- key = keys[i];
30
- if (!__hasOwnProp.call(to, key) && key !== except) {
31
- __defProp(to, key, {
32
- get: ((k) => from[k]).bind(null, key),
33
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
34
- });
35
- }
36
- }
37
- }
38
- return to;
39
- };
40
- var __reExport = (target, mod, secondTarget, symbols) => {
41
- if (symbols) {
42
- __defProp(target, Symbol.toStringTag, { value: "Module" });
43
- secondTarget && __defProp(secondTarget, Symbol.toStringTag, { value: "Module" });
44
- }
45
- __copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
46
- };
47
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
48
- value: mod,
49
- enumerable: true
50
- }) : target, mod));
51
-
52
- //#endregion
53
- //#region ../utils/src/index.ts
54
- const toArray = (a) => Array.isArray(a) ? a : [a];
55
- function joinWithAnd(values) {
56
- if (values.length === 0) return "";
57
- if (values.length === 1) return values[0];
58
- const last = values.pop();
59
- return `${values.join(", ")} and ${last}`;
60
- }
61
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
62
- const formatFlagName = (n) => n.length <= 1 ? `-${n}` : `--${kebabCase(n)}`;
63
- const formatVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`;
64
- const isTruthy = Boolean;
65
- const objectIsEmpty = (obj) => Object.keys(obj).length === 0;
66
-
67
- //#endregion
68
- //#region ../plugin-help/src/utils.ts
69
- function formatTypeValue(type) {
70
- if (typeof type === "function") return type.display ?? type.name;
71
- const innerType = type[0];
72
- return `Array<${innerType.displayName ?? innerType.name}>`;
73
- }
74
- function formatFlagDefault(value) {
75
- if (typeof value === "function" && "display" in value && value.display) return value.display;
76
- return String(value);
77
- }
78
- function formatCommandName(name) {
79
- if (name === "") return "(root)";
80
- return name;
81
- }
82
-
83
- //#endregion
84
- //#region ../plugin-help/src/formatters.ts
85
- const defaultFormatters = {
86
- formatTypeValue,
87
- formatFlagDefault
88
- };
89
-
90
- //#endregion
91
- //#region ../../node_modules/.pnpm/ansi-regex@6.1.0/node_modules/ansi-regex/index.js
92
- function ansiRegex({ onlyFirst = false } = {}) {
93
- const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
94
- return new RegExp(pattern, onlyFirst ? void 0 : "g");
95
- }
96
-
97
- //#endregion
98
- //#region ../../node_modules/.pnpm/strip-ansi@7.1.0/node_modules/strip-ansi/index.js
99
- const regex = ansiRegex();
100
- function stripAnsi(string) {
101
- if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
102
- return string.replace(regex, "");
103
- }
104
-
105
- //#endregion
106
- //#region ../../node_modules/.pnpm/get-east-asian-width@1.3.0/node_modules/get-east-asian-width/lookup.js
107
- function isAmbiguous(x) {
108
- return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
109
- }
110
- function isFullWidth(x) {
111
- return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
112
- }
113
- function isWide(x) {
114
- return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101631 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129673 || x >= 129679 && x <= 129734 || x >= 129742 && x <= 129756 || x >= 129759 && x <= 129769 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
115
- }
116
-
117
- //#endregion
118
- //#region ../../node_modules/.pnpm/get-east-asian-width@1.3.0/node_modules/get-east-asian-width/index.js
119
- function validate(codePoint) {
120
- if (!Number.isSafeInteger(codePoint)) throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
121
- }
122
- function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
123
- validate(codePoint);
124
- if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
125
- return 1;
126
- }
127
-
128
- //#endregion
129
- //#region ../../node_modules/.pnpm/string-width@8.1.0/node_modules/string-width/index.js
130
- /**
131
- Logic:
132
- - Segment graphemes to match how terminals render clusters.
133
- - Width rules:
134
- 1. Skip non-printing clusters (Default_Ignorable, Control, pure Mark, lone Surrogates). Tabs are ignored by design.
135
- 2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
136
- 3. Otherwise use East Asian Width of the cluster’s first visible code point, and add widths for trailing Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
137
- */
138
- const segmenter = new Intl.Segmenter();
139
- const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Mark}|\p{Surrogate})+$/v;
140
- const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Mark}\p{Surrogate}]+/v;
141
- const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
142
- function baseVisible(segment) {
143
- return segment.replace(leadingNonPrintingRegex, "");
144
- }
145
- function isZeroWidthCluster(segment) {
146
- return zeroWidthClusterRegex.test(segment);
147
- }
148
- function trailingHalfwidthWidth(segment, eastAsianWidthOptions) {
149
- let extra = 0;
150
- if (segment.length > 1) {
151
- for (const char of segment.slice(1)) if (char >= "＀" && char <= "￯") extra += eastAsianWidth(char.codePointAt(0), eastAsianWidthOptions);
152
- }
153
- return extra;
154
- }
155
- function stringWidth(input, options = {}) {
156
- if (typeof input !== "string" || input.length === 0) return 0;
157
- const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
158
- let string = input;
159
- if (!countAnsiEscapeCodes) string = stripAnsi(string);
160
- if (string.length === 0) return 0;
161
- let width = 0;
162
- const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
163
- for (const { segment } of segmenter.segment(string)) {
164
- if (isZeroWidthCluster(segment)) continue;
165
- if (rgiEmojiRegex.test(segment)) {
166
- width += 2;
167
- continue;
168
- }
169
- const codePoint = baseVisible(segment).codePointAt(0);
170
- width += eastAsianWidth(codePoint, eastAsianWidthOptions);
171
- width += trailingHalfwidthWidth(segment, eastAsianWidthOptions);
172
- }
173
- return width;
174
- }
175
-
176
- //#endregion
177
- //#region ../../node_modules/.pnpm/text-table@0.2.0/node_modules/text-table/index.js
178
- var require_text_table = /* @__PURE__ */ __commonJSMin(((exports, module) => {
179
- module.exports = function(rows_, opts) {
180
- if (!opts) opts = {};
181
- var hsep = opts.hsep === void 0 ? " " : opts.hsep;
182
- var align = opts.align || [];
183
- var stringLength = opts.stringLength || function(s) {
184
- return String(s).length;
185
- };
186
- var dotsizes = reduce(rows_, function(acc, row) {
187
- forEach(row, function(c, ix) {
188
- var n = dotindex(c);
189
- if (!acc[ix] || n > acc[ix]) acc[ix] = n;
190
- });
191
- return acc;
192
- }, []);
193
- var rows = map(rows_, function(row) {
194
- return map(row, function(c_, ix) {
195
- var c = String(c_);
196
- if (align[ix] === ".") {
197
- var index = dotindex(c);
198
- var size = dotsizes[ix] + (/\./.test(c) ? 1 : 2) - (stringLength(c) - index);
199
- return c + Array(size).join(" ");
200
- } else return c;
201
- });
202
- });
203
- var sizes = reduce(rows, function(acc, row) {
204
- forEach(row, function(c, ix) {
205
- var n = stringLength(c);
206
- if (!acc[ix] || n > acc[ix]) acc[ix] = n;
207
- });
208
- return acc;
209
- }, []);
210
- return map(rows, function(row) {
211
- return map(row, function(c, ix) {
212
- var n = sizes[ix] - stringLength(c) || 0;
213
- var s = Array(Math.max(n + 1, 1)).join(" ");
214
- if (align[ix] === "r" || align[ix] === ".") return s + c;
215
- if (align[ix] === "c") return Array(Math.ceil(n / 2 + 1)).join(" ") + c + Array(Math.floor(n / 2 + 1)).join(" ");
216
- return c + s;
217
- }).join(hsep).replace(/\s+$/, "");
218
- }).join("\n");
219
- };
220
- function dotindex(c) {
221
- var m = /\.[^.]*$/.exec(c);
222
- return m ? m.index + 1 : c.length;
223
- }
224
- function reduce(xs, f, init) {
225
- if (xs.reduce) return xs.reduce(f, init);
226
- var i = 0;
227
- var acc = arguments.length >= 3 ? init : xs[i++];
228
- for (; i < xs.length; i++) f(acc, xs[i], i);
229
- return acc;
230
- }
231
- function forEach(xs, f) {
232
- if (xs.forEach) return xs.forEach(f);
233
- for (var i = 0; i < xs.length; i++) f.call(xs, xs[i], i);
234
- }
235
- function map(xs, f) {
236
- if (xs.map) return xs.map(f);
237
- var res = [];
238
- for (var i = 0; i < xs.length; i++) res.push(f.call(xs, xs[i], i));
239
- return res;
240
- }
241
- }));
242
-
243
- //#endregion
244
- //#region ../../node_modules/.pnpm/yoctocolors@2.1.2/node_modules/yoctocolors/base.js
245
- const hasColors = tty?.WriteStream?.prototype?.hasColors?.() ?? false;
246
- const format = (open, close) => {
247
- if (!hasColors) return (input) => input;
248
- const openCode = `\u001B[${open}m`;
249
- const closeCode = `\u001B[${close}m`;
250
- return (input) => {
251
- const string = input + "";
252
- let index = string.indexOf(closeCode);
253
- if (index === -1) return openCode + string + closeCode;
254
- let result = openCode;
255
- let lastIndex = 0;
256
- const replaceCode = (close === 22 ? closeCode : "") + openCode;
257
- while (index !== -1) {
258
- result += string.slice(lastIndex, index) + replaceCode;
259
- lastIndex = index + closeCode.length;
260
- index = string.indexOf(closeCode, lastIndex);
261
- }
262
- result += string.slice(lastIndex) + closeCode;
263
- return result;
264
- };
265
- };
266
- const reset = format(0, 0);
267
- const bold = format(1, 22);
268
- const dim = format(2, 22);
269
- const italic = format(3, 23);
270
- const underline = format(4, 24);
271
- const overline = format(53, 55);
272
- const inverse = format(7, 27);
273
- const hidden = format(8, 28);
274
- const strikethrough = format(9, 29);
275
- const black = format(30, 39);
276
- const red = format(31, 39);
277
- const green = format(32, 39);
278
- const yellow = format(33, 39);
279
- const blue = format(34, 39);
280
- const magenta = format(35, 39);
281
- const cyan = format(36, 39);
282
- const white = format(37, 39);
283
- const gray = format(90, 39);
284
- const bgBlack = format(40, 49);
285
- const bgRed = format(41, 49);
286
- const bgGreen = format(42, 49);
287
- const bgYellow = format(43, 49);
288
- const bgBlue = format(44, 49);
289
- const bgMagenta = format(45, 49);
290
- const bgCyan = format(46, 49);
291
- const bgWhite = format(47, 49);
292
- const bgGray = format(100, 49);
293
- const redBright = format(91, 39);
294
- const greenBright = format(92, 39);
295
- const yellowBright = format(93, 39);
296
- const blueBright = format(94, 39);
297
- const magentaBright = format(95, 39);
298
- const cyanBright = format(96, 39);
299
- const whiteBright = format(97, 39);
300
- const bgRedBright = format(101, 49);
301
- const bgGreenBright = format(102, 49);
302
- const bgYellowBright = format(103, 49);
303
- const bgBlueBright = format(104, 49);
304
- const bgMagentaBright = format(105, 49);
305
- const bgCyanBright = format(106, 49);
306
- const bgWhiteBright = format(107, 49);
307
-
308
- //#endregion
309
- //#region ../plugin-help/src/renderer.ts
310
- var import_text_table = /* @__PURE__ */ __toESM(require_text_table(), 1);
311
- const DEFAULT_GROUP_KEY = "default";
312
- const table = (items) => (0, import_text_table.default)(items, { stringLength: stringWidth });
313
- const splitTable = (items) => table(items).split("\n");
314
- const DELIMITER = "-";
315
- const INDENT = " ".repeat(2);
316
- const withIndent = (str) => `${INDENT}${str}`;
317
- function groupDefinitionsToMap(definitions) {
318
- const map$1 = /* @__PURE__ */ new Map();
319
- if (definitions) for (const [key, name] of definitions) map$1.set(key, name);
320
- return map$1;
321
- }
322
- function validateGroup(group, groupMap, itemType, itemName) {
323
- if (group && group !== DEFAULT_GROUP_KEY && !groupMap.has(group)) throw new Error(`Unknown ${itemType} group "${group}" for "${itemName}". Available groups: ${[...groupMap.keys()].join(", ") || "(none)"}`);
324
- }
325
- var HelpRenderer = class {
326
- _command;
327
- get _commandGroups() {
328
- return groupDefinitionsToMap(this._getGroups().commands);
329
- }
330
- get _flagGroups() {
331
- return groupDefinitionsToMap(this._getGroups().flags);
332
- }
333
- get _globalFlagGroups() {
334
- return groupDefinitionsToMap(this._getGroups().globalFlags);
335
- }
336
- constructor(_formatters, _cli, _globalFlags, _getGroups, _getExamples, _notes) {
337
- this._formatters = _formatters;
338
- this._cli = _cli;
339
- this._globalFlags = _globalFlags;
340
- this._getGroups = _getGroups;
341
- this._getExamples = _getExamples;
342
- this._notes = _notes;
343
- }
344
- setCommand(command) {
345
- if (command) {
346
- this._command = command;
347
- this._getExamples = () => command?.help?.examples;
348
- this._notes = command?.help?.notes;
349
- }
350
- }
351
- renderSections(sections) {
352
- return sections.filter(isTruthy).map((section) => {
353
- const body = Array.isArray(section.body) ? section.body.filter((s) => s !== void 0).join("\n") : section.body;
354
- if (!section.title) return body;
355
- return `${underline(bold(section.title))}\n${body.split("\n").map(withIndent).join("\n")}`;
356
- }).join("\n\n");
357
- }
358
- render() {
359
- const sections = [
360
- this.renderHeader(),
361
- this.renderUsage(),
362
- this.renderParameters(),
363
- this.renderCommandFlags(),
364
- this.renderGlobalFlags(),
365
- this.renderCommands(),
366
- this.renderExamples(),
367
- this.renderNotes()
368
- ];
369
- return this.renderSections(sections);
370
- }
371
- renderHeader() {
372
- const { _name, _version, _description } = this._cli;
373
- const command = this._command;
374
- const description = command ? command.description : _description;
375
- const formattedCommandName = command?.name ? ` ${bold(command.name)}` : "";
376
- const headerLine = command ? `${dim(_name)}${formattedCommandName}` : `${bold(_name)} ${formatVersion(_version)}`;
377
- const alias = command?.alias ? `Alias${toArray(command.alias).length > 1 ? "es" : ""}: ${toArray(command.alias).map((a) => bold(a)).join(", ")}` : void 0;
378
- return { body: [`${headerLine}${description ? ` ${DELIMITER} ${description}` : ""}`, alias] };
379
- }
380
- renderUsage() {
381
- const { _scriptName } = this._cli;
382
- const command = this._command;
383
- let usage = `$ ${_scriptName}`;
384
- if (command) {
385
- if (command.name) usage += ` ${command.name}`;
386
- if (command.parameters) usage += ` ${command.parameters.map((p$1) => typeof p$1 === "string" ? p$1 : p$1.key).join(" ")}`;
387
- } else if (this._cli._commands.size > 0 && !(this._cli._commands.has("") && this._cli._commands.size === 1)) usage += this._cli._commands.has("") ? ` ${dim("[command]")}` : ` ${dim("<command>")}`;
388
- if (command?.flags && !objectIsEmpty(command.flags) || !objectIsEmpty(this._globalFlags)) usage += ` ${dim("[flags]")}`;
389
- return {
390
- title: "Usage",
391
- body: [usage]
392
- };
393
- }
394
- renderParameters() {
395
- const command = this._command;
396
- if (!command?.parameters || command.parameters.length === 0) return;
397
- return {
398
- title: "Parameters",
399
- body: splitTable(command.parameters.filter((p$1) => p$1 !== DOUBLE_DASH).map((parameter) => {
400
- const key = typeof parameter === "string" ? parameter : parameter.key;
401
- const type = typeof parameter === "string" ? void 0 : parameter.type;
402
- const formattedType = type ? this._formatters.formatTypeValue(type) : "string";
403
- const description = typeof parameter === "string" ? void 0 : parameter.description;
404
- return [
405
- bold(key),
406
- dim(formattedType),
407
- description
408
- ].filter(isTruthy);
409
- }))
410
- };
411
- }
412
- getSubcommands(parentCommandName) {
413
- const subcommands = /* @__PURE__ */ new Map();
414
- if (parentCommandName === "") return subcommands;
415
- const prefix = `${parentCommandName} `;
416
- for (const [name, command] of this._cli._commands) if (name.startsWith(prefix)) {
417
- const subcommandName = name.slice(prefix.length);
418
- subcommands.set(subcommandName, command);
419
- }
420
- return subcommands;
421
- }
422
- buildGroupedCommandsBody(commandsToShow, prefix) {
423
- const groupedCommands = /* @__PURE__ */ new Map();
424
- const defaultCommands = [];
425
- let rootCommand = [];
426
- for (const command of commandsToShow.values()) {
427
- if (command.__isAlias || command.help?.show === false) continue;
428
- const group = command.help?.group;
429
- validateGroup(group, this._commandGroups, "command", command.name);
430
- const item = [`${bold(formatCommandName(command.name.slice(prefix.length)))}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description].filter(isTruthy);
431
- if (command.name === "") rootCommand = item;
432
- else if (group && group !== DEFAULT_GROUP_KEY) {
433
- const groupItems = groupedCommands.get(group) ?? [];
434
- groupItems.push(item);
435
- groupedCommands.set(group, groupItems);
436
- } else defaultCommands.push(item);
437
- }
438
- const body = [];
439
- const defaultGroup = [];
440
- if (rootCommand.length > 0) defaultGroup.push(rootCommand);
441
- if (defaultCommands.length > 0) defaultGroup.push(...defaultCommands);
442
- if (defaultGroup.length > 0) body.push(...splitTable(defaultGroup));
443
- for (const [key, name] of this._commandGroups) {
444
- const items = groupedCommands.get(key);
445
- if (items && items.length > 0) {
446
- if (body.length > 0) body.push("");
447
- body.push(`${dim(name)}`);
448
- body.push(...splitTable(items).map(withIndent));
449
- }
450
- }
451
- return body;
452
- }
453
- renderAvailableSubcommands(parentCommandName) {
454
- const subcommands = this.getSubcommands(parentCommandName);
455
- if (subcommands.size === 0) return "";
456
- const prefix = `${parentCommandName} `;
457
- const body = this.buildGroupedCommandsBody(subcommands, prefix);
458
- if (body.length === 0) return "";
459
- const sections = [{ body: `${this._cli._name} ${bold(parentCommandName)} not found` }, {
460
- title: "Available Subcommands",
461
- body
462
- }];
463
- return this.renderSections(sections);
464
- }
465
- renderCommands() {
466
- const commands = this._cli._commands;
467
- let commandsToShow;
468
- let title = "Commands";
469
- let prefix = "";
470
- if (this._command) {
471
- prefix = this._command.name ? `${this._command.name} ` : "";
472
- title = "Subcommands";
473
- commandsToShow = this.getSubcommands(this._command.name);
474
- if (commandsToShow.size === 0) return;
475
- } else commandsToShow = commands;
476
- if (commandsToShow.size === 0) return;
477
- const body = this.buildGroupedCommandsBody(commandsToShow, prefix);
478
- return {
479
- title,
480
- body
481
- };
482
- }
483
- renderFlagItem(name, flag) {
484
- flag = normalizeFlagValue(flag);
485
- let flagName = formatFlagName(name);
486
- if (flag.short) flagName += `, ${formatFlagName(flag.short)}`;
487
- const type = this._formatters.formatTypeValue(flag.type);
488
- const default_ = flag.default !== void 0 && dim(`[default: ${bold(this._formatters.formatFlagDefault(flag.default))}]`);
489
- return [
490
- bold(flagName),
491
- dim(type),
492
- flag.description,
493
- default_
494
- ].filter(isTruthy);
495
- }
496
- renderGroupedFlags(flags, groupMap, itemType) {
497
- const groupedFlags = /* @__PURE__ */ new Map();
498
- const defaultFlags = [];
499
- for (const [name, flag] of Object.entries(flags)) {
500
- const group = flag.help?.group;
501
- validateGroup(group, groupMap, itemType, name);
502
- const item = this.renderFlagItem(name, flag);
503
- if (group && group !== DEFAULT_GROUP_KEY) {
504
- const groupItems = groupedFlags.get(group) ?? [];
505
- groupItems.push(item);
506
- groupedFlags.set(group, groupItems);
507
- } else defaultFlags.push(item);
508
- }
509
- const body = [];
510
- if (defaultFlags.length > 0) body.push(...splitTable(defaultFlags));
511
- for (const [key, name] of groupMap) {
512
- const items = groupedFlags.get(key);
513
- if (items && items.length > 0) {
514
- if (body.length > 0) body.push("");
515
- body.push(`${dim(name)}`);
516
- body.push(...splitTable(items).map(withIndent));
517
- }
518
- }
519
- return body;
520
- }
521
- renderCommandFlags() {
522
- const command = this._command;
523
- if (!command?.flags || objectIsEmpty(command.flags)) return;
524
- return {
525
- title: "Flags",
526
- body: this.renderGroupedFlags(command.flags, this._flagGroups, "flag")
527
- };
528
- }
529
- renderGlobalFlags() {
530
- if (!this._globalFlags || objectIsEmpty(this._globalFlags)) return;
531
- return {
532
- title: "Global Flags",
533
- body: this.renderGroupedFlags(this._globalFlags, this._globalFlagGroups, "global flag")
534
- };
535
- }
536
- renderNotes() {
537
- if (!this._notes?.length) return;
538
- return {
539
- title: "Notes",
540
- body: this._notes
541
- };
542
- }
543
- renderExamples() {
544
- const examples = this._getExamples();
545
- if (!examples?.length) return;
546
- return {
547
- title: "Examples",
548
- body: splitTable(examples.map(([command, description]) => {
549
- return [
550
- command,
551
- DELIMITER,
552
- description
553
- ];
554
- }))
555
- };
556
- }
557
- };
558
-
559
- //#endregion
560
- //#region ../plugin-help/src/store.ts
561
- function addStoreApi(cli, { groups }) {
562
- cli.store.help = { addGroup: (options) => {
563
- if (options.commands) groups.commands = [...groups.commands ?? [], ...options.commands];
564
- if (options.flags) groups.flags = [...groups.flags ?? [], ...options.flags];
565
- if (options.globalFlags) groups.globalFlags = [...groups.globalFlags ?? [], ...options.globalFlags];
566
- } };
567
- }
568
-
569
- //#endregion
570
- //#region ../plugin-help/src/index.ts
571
- const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecified = true, notes, examples, banner, formatters, groups = {} } = {}) => definePlugin({ setup: (cli) => {
572
- addStoreApi(cli, { groups });
573
- const mergedFormatters = {
574
- ...defaultFormatters,
575
- ...formatters
576
- };
577
- const generalHelpNotes = [
578
- "If no command is specified, show help for the CLI.",
579
- "If a command is specified, show help for the command.",
580
- flag && "-h is an alias for --help."
581
- ].filter(isTruthy);
582
- const getGeneralHelpExamples = () => [
583
- command && [`$ ${cli._scriptName} help`, "Show help"],
584
- command && [`$ ${cli._scriptName} help <command>`, "Show help for a specific command"],
585
- flag && [`$ ${cli._scriptName} <command> --help`, "Show help for a specific command"]
586
- ].filter(isTruthy);
587
- const effectiveNotes = notes ?? generalHelpNotes;
588
- const getEffectiveExamples = () => examples ?? getGeneralHelpExamples();
589
- function printHelp(s) {
590
- if (banner) console.log(banner);
591
- console.log(s);
592
- }
593
- const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups, getEffectiveExamples, effectiveNotes);
594
- function tryPrintSubcommandsHelp(commandName) {
595
- const subcommandsOutput = renderer.renderAvailableSubcommands(commandName);
596
- if (subcommandsOutput) {
597
- printHelp(subcommandsOutput);
598
- return true;
599
- }
600
- return false;
601
- }
602
- if (command) cli.command("help", "Show help", {
603
- parameters: ["[command...]"],
604
- help: {
605
- notes: generalHelpNotes,
606
- examples: getGeneralHelpExamples()
607
- }
608
- }).on("help", (ctx) => {
609
- const commandName = ctx.parameters.command;
610
- let command$1;
611
- if (commandName.length > 0) {
612
- [command$1] = resolveCommand(cli._commands, commandName);
613
- if (!command$1) {
614
- const parentCommandName = commandName.join(" ");
615
- if (tryPrintSubcommandsHelp(parentCommandName)) return;
616
- throw new NoSuchCommandError(parentCommandName);
617
- }
618
- }
619
- renderer.setCommand(command$1);
620
- printHelp(renderer.render());
621
- });
622
- if (flag) cli.globalFlag("help", "Show help", {
623
- short: "h",
624
- type: Boolean,
625
- default: false
626
- });
627
- cli.interceptor({
628
- enforce: "post",
629
- handler: async (ctx, next) => {
630
- if (ctx.flags.help) {
631
- const command$1 = ctx.command;
632
- if (!command$1 && ctx.rawParsed.parameters.length > 0) {
633
- if (tryPrintSubcommandsHelp(ctx.rawParsed.parameters.join(" "))) return;
634
- await next();
635
- }
636
- renderer.setCommand(command$1);
637
- printHelp(renderer.render());
638
- } else if (showHelpWhenNoCommandSpecified && !ctx.command && ctx.rawParsed.parameters.length === 0) printHelp(renderer.render());
639
- else await next();
640
- }
641
- });
642
- } });
643
-
644
- //#endregion
645
- //#region ../plugin-version/src/index.ts
646
- const versionPlugin = ({ command = true, flag = true } = {}) => definePlugin({ setup: (cli) => {
647
- if (command) cli.command("version", "Prints current version", {}).on("version", () => {
648
- console.log(formatVersion(cli._version));
649
- });
650
- if (flag) cli.globalFlag("version", "Prints current version", {
651
- short: "V",
652
- type: Boolean,
653
- default: false
654
- }).interceptor({
655
- enforce: "pre",
656
- handler: async (ctx, next) => {
657
- if (ctx.flags.version) console.log(formatVersion(cli._version));
658
- else await next();
659
- }
660
- });
661
- } });
662
-
663
- //#endregion
664
- //#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
665
- var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
666
- let p = process || {}, argv = p.argv || [], env = p.env || {};
667
- let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
668
- let formatter = (open, close, replace = open) => (input) => {
669
- let string = "" + input, index = string.indexOf(close, open.length);
670
- return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
671
- };
672
- let replaceClose = (string, close, replace, index) => {
673
- let result = "", cursor = 0;
674
- do {
675
- result += string.substring(cursor, index) + replace;
676
- cursor = index + close.length;
677
- index = string.indexOf(close, cursor);
678
- } while (~index);
679
- return result + string.substring(cursor);
680
- };
681
- let createColors = (enabled = isColorSupported) => {
682
- let f = enabled ? formatter : () => String;
683
- return {
684
- isColorSupported: enabled,
685
- reset: f("\x1B[0m", "\x1B[0m"),
686
- bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
687
- dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
688
- italic: f("\x1B[3m", "\x1B[23m"),
689
- underline: f("\x1B[4m", "\x1B[24m"),
690
- inverse: f("\x1B[7m", "\x1B[27m"),
691
- hidden: f("\x1B[8m", "\x1B[28m"),
692
- strikethrough: f("\x1B[9m", "\x1B[29m"),
693
- black: f("\x1B[30m", "\x1B[39m"),
694
- red: f("\x1B[31m", "\x1B[39m"),
695
- green: f("\x1B[32m", "\x1B[39m"),
696
- yellow: f("\x1B[33m", "\x1B[39m"),
697
- blue: f("\x1B[34m", "\x1B[39m"),
698
- magenta: f("\x1B[35m", "\x1B[39m"),
699
- cyan: f("\x1B[36m", "\x1B[39m"),
700
- white: f("\x1B[37m", "\x1B[39m"),
701
- gray: f("\x1B[90m", "\x1B[39m"),
702
- bgBlack: f("\x1B[40m", "\x1B[49m"),
703
- bgRed: f("\x1B[41m", "\x1B[49m"),
704
- bgGreen: f("\x1B[42m", "\x1B[49m"),
705
- bgYellow: f("\x1B[43m", "\x1B[49m"),
706
- bgBlue: f("\x1B[44m", "\x1B[49m"),
707
- bgMagenta: f("\x1B[45m", "\x1B[49m"),
708
- bgCyan: f("\x1B[46m", "\x1B[49m"),
709
- bgWhite: f("\x1B[47m", "\x1B[49m"),
710
- blackBright: f("\x1B[90m", "\x1B[39m"),
711
- redBright: f("\x1B[91m", "\x1B[39m"),
712
- greenBright: f("\x1B[92m", "\x1B[39m"),
713
- yellowBright: f("\x1B[93m", "\x1B[39m"),
714
- blueBright: f("\x1B[94m", "\x1B[39m"),
715
- magentaBright: f("\x1B[95m", "\x1B[39m"),
716
- cyanBright: f("\x1B[96m", "\x1B[39m"),
717
- whiteBright: f("\x1B[97m", "\x1B[39m"),
718
- bgBlackBright: f("\x1B[100m", "\x1B[49m"),
719
- bgRedBright: f("\x1B[101m", "\x1B[49m"),
720
- bgGreenBright: f("\x1B[102m", "\x1B[49m"),
721
- bgYellowBright: f("\x1B[103m", "\x1B[49m"),
722
- bgBlueBright: f("\x1B[104m", "\x1B[49m"),
723
- bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
724
- bgCyanBright: f("\x1B[106m", "\x1B[49m"),
725
- bgWhiteBright: f("\x1B[107m", "\x1B[49m")
726
- };
727
- };
728
- module.exports = createColors();
729
- module.exports.createColors = createColors;
730
- }));
731
-
732
- //#endregion
733
- //#region ../../node_modules/.pnpm/kons@0.7.1/node_modules/kons/dist/utils-6230ae77.mjs
734
- var import_picocolors$1 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
735
- function parseStack(stack) {
736
- return stack.split("\n").splice(1).map((l) => l.trim().replace("file://", ""));
737
- }
738
- function formatStack(stack) {
739
- return `
740
- ${parseStack(stack).map((line) => ` ${line.replace(/^at ([\s\S]+) \((.+)\)/, (_, m1, m2) => import_picocolors$1.default.gray(`at ${m1} (${import_picocolors$1.default.cyan(m2)})`))}`).join("\n")}`;
741
- }
742
- const NEWLINE_RE = /\r?\n/g;
743
- function formatMessage(messages) {
744
- return messages.map((m) => {
745
- if (typeof (m == null ? void 0 : m.stack) === "string") return [m.message, formatStack(m.stack)];
746
- if (typeof m === "string") return m.split(NEWLINE_RE);
747
- return m;
748
- }).flat();
749
- }
750
- function createBadge(badgeType, bgColor) {
751
- const upperType = badgeType.toUpperCase();
752
- const bgColorFormatter = import_picocolors$1.default[bgColor];
753
- return import_picocolors$1.default.bold(import_picocolors$1.default.inverse(bgColorFormatter(` ${upperType} `)));
754
- }
755
-
756
- //#endregion
757
- //#region ../../node_modules/.pnpm/kons@0.7.1/node_modules/kons/dist/index.mjs
758
- var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
759
- function createFormatter(type, bgColor, { target = console.log, textColor, newline = true } = {}) {
760
- const bgColorFormatter = import_picocolors.default[bgColor];
761
- const textColorFormatter = textColor ? import_picocolors.default[textColor] : bgColorFormatter;
762
- return (...messages) => {
763
- const formattedMessages = formatMessage(messages);
764
- const badge = createBadge(type, bgColor);
765
- for (const message of formattedMessages) target(`${badge} ${textColorFormatter(message)}${newline ? "\n" : ""}`);
766
- };
767
- }
768
- const log = createFormatter("log", "gray");
769
- const info = createFormatter("info", "blue", { target: console.info });
770
- const warn = createFormatter("warn", "yellow", { target: console.warn });
771
- const success = createFormatter("success", "green");
772
- const error = createFormatter("error", "red", { target: console.error });
773
-
774
- //#endregion
775
- //#region ../plugin-friendly-error/src/index.ts
776
- const friendlyErrorPlugin = ({ target = error } = {}) => definePlugin({ setup: (cli) => cli.errorHandler((err) => {
777
- target(err.message);
778
- process.exit(1);
779
- }) });
780
-
781
- //#endregion
782
- //#region ../../node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.js
783
- var require_fastest_levenshtein = /* @__PURE__ */ __commonJSMin(((exports) => {
784
- exports.__esModule = true;
785
- exports.distance = exports.closest = void 0;
786
- var peq = new Uint32Array(65536);
787
- var myers_32 = function(a, b) {
788
- var n = a.length;
789
- var m = b.length;
790
- var lst = 1 << n - 1;
791
- var pv = -1;
792
- var mv = 0;
793
- var sc = n;
794
- var i = n;
795
- while (i--) peq[a.charCodeAt(i)] |= 1 << i;
796
- for (i = 0; i < m; i++) {
797
- var eq = peq[b.charCodeAt(i)];
798
- var xv = eq | mv;
799
- eq |= (eq & pv) + pv ^ pv;
800
- mv |= ~(eq | pv);
801
- pv &= eq;
802
- if (mv & lst) sc++;
803
- if (pv & lst) sc--;
804
- mv = mv << 1 | 1;
805
- pv = pv << 1 | ~(xv | mv);
806
- mv &= xv;
807
- }
808
- i = n;
809
- while (i--) peq[a.charCodeAt(i)] = 0;
810
- return sc;
811
- };
812
- var myers_x = function(b, a) {
813
- var n = a.length;
814
- var m = b.length;
815
- var mhc = [];
816
- var phc = [];
817
- var hsize = Math.ceil(n / 32);
818
- var vsize = Math.ceil(m / 32);
819
- for (var i = 0; i < hsize; i++) {
820
- phc[i] = -1;
821
- mhc[i] = 0;
822
- }
823
- var j = 0;
824
- for (; j < vsize - 1; j++) {
825
- var mv_1 = 0;
826
- var pv_1 = -1;
827
- var start_1 = j * 32;
828
- var vlen_1 = Math.min(32, m) + start_1;
829
- for (var k = start_1; k < vlen_1; k++) peq[b.charCodeAt(k)] |= 1 << k;
830
- for (var i = 0; i < n; i++) {
831
- var eq = peq[a.charCodeAt(i)];
832
- var pb = phc[i / 32 | 0] >>> i & 1;
833
- var mb = mhc[i / 32 | 0] >>> i & 1;
834
- var xv = eq | mv_1;
835
- var xh = ((eq | mb) & pv_1) + pv_1 ^ pv_1 | eq | mb;
836
- var ph = mv_1 | ~(xh | pv_1);
837
- var mh = pv_1 & xh;
838
- if (ph >>> 31 ^ pb) phc[i / 32 | 0] ^= 1 << i;
839
- if (mh >>> 31 ^ mb) mhc[i / 32 | 0] ^= 1 << i;
840
- ph = ph << 1 | pb;
841
- mh = mh << 1 | mb;
842
- pv_1 = mh | ~(xv | ph);
843
- mv_1 = ph & xv;
844
- }
845
- for (var k = start_1; k < vlen_1; k++) peq[b.charCodeAt(k)] = 0;
846
- }
847
- var mv = 0;
848
- var pv = -1;
849
- var start = j * 32;
850
- var vlen = Math.min(32, m - start) + start;
851
- for (var k = start; k < vlen; k++) peq[b.charCodeAt(k)] |= 1 << k;
852
- var score = m;
853
- for (var i = 0; i < n; i++) {
854
- var eq = peq[a.charCodeAt(i)];
855
- var pb = phc[i / 32 | 0] >>> i & 1;
856
- var mb = mhc[i / 32 | 0] >>> i & 1;
857
- var xv = eq | mv;
858
- var xh = ((eq | mb) & pv) + pv ^ pv | eq | mb;
859
- var ph = mv | ~(xh | pv);
860
- var mh = pv & xh;
861
- score += ph >>> m - 1 & 1;
862
- score -= mh >>> m - 1 & 1;
863
- if (ph >>> 31 ^ pb) phc[i / 32 | 0] ^= 1 << i;
864
- if (mh >>> 31 ^ mb) mhc[i / 32 | 0] ^= 1 << i;
865
- ph = ph << 1 | pb;
866
- mh = mh << 1 | mb;
867
- pv = mh | ~(xv | ph);
868
- mv = ph & xv;
869
- }
870
- for (var k = start; k < vlen; k++) peq[b.charCodeAt(k)] = 0;
871
- return score;
872
- };
873
- var distance$1 = function(a, b) {
874
- if (a.length < b.length) {
875
- var tmp = b;
876
- b = a;
877
- a = tmp;
878
- }
879
- if (b.length === 0) return a.length;
880
- if (a.length <= 32) return myers_32(a, b);
881
- return myers_x(a, b);
882
- };
883
- exports.distance = distance$1;
884
- var closest = function(str, arr) {
885
- var min_distance = Infinity;
886
- var min_index = 0;
887
- for (var i = 0; i < arr.length; i++) {
888
- var dist = distance$1(str, arr[i]);
889
- if (dist < min_distance) {
890
- min_distance = dist;
891
- min_index = i;
892
- }
893
- }
894
- return arr[min_index];
895
- };
896
- exports.closest = closest;
897
- }));
898
-
899
- //#endregion
900
- //#region ../../node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.js
901
- var require_lodash = /* @__PURE__ */ __commonJSMin(((exports, module) => {
902
- /**
903
- * lodash (Custom Build) <https://lodash.com/>
904
- * Build: `lodash modularize exports="npm" -o ./`
905
- * Copyright jQuery Foundation and other contributors <https://jquery.org/>
906
- * Released under MIT license <https://lodash.com/license>
907
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
908
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
909
- */
910
- /** Used as references for various `Number` constants. */
911
- var INFINITY = Infinity;
912
- /** `Object#toString` result references. */
913
- var symbolTag = "[object Symbol]";
914
- /** Used to match Latin Unicode letters (excluding mathematical operators). */
915
- var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
916
- /**
917
- * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
918
- * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
919
- */
920
- var reComboMark = RegExp("[\\u0300-\\u036f\\ufe20-\\ufe23\\u20d0-\\u20f0]", "g");
921
- /** Used to map Latin Unicode letters to basic Latin letters. */
922
- var deburredLetters = {
923
- "À": "A",
924
- "Á": "A",
925
- "Â": "A",
926
- "Ã": "A",
927
- "Ä": "A",
928
- "Å": "A",
929
- "à": "a",
930
- "á": "a",
931
- "â": "a",
932
- "ã": "a",
933
- "ä": "a",
934
- "å": "a",
935
- "Ç": "C",
936
- "ç": "c",
937
- "Ð": "D",
938
- "ð": "d",
939
- "È": "E",
940
- "É": "E",
941
- "Ê": "E",
942
- "Ë": "E",
943
- "è": "e",
944
- "é": "e",
945
- "ê": "e",
946
- "ë": "e",
947
- "Ì": "I",
948
- "Í": "I",
949
- "Î": "I",
950
- "Ï": "I",
951
- "ì": "i",
952
- "í": "i",
953
- "î": "i",
954
- "ï": "i",
955
- "Ñ": "N",
956
- "ñ": "n",
957
- "Ò": "O",
958
- "Ó": "O",
959
- "Ô": "O",
960
- "Õ": "O",
961
- "Ö": "O",
962
- "Ø": "O",
963
- "ò": "o",
964
- "ó": "o",
965
- "ô": "o",
966
- "õ": "o",
967
- "ö": "o",
968
- "ø": "o",
969
- "Ù": "U",
970
- "Ú": "U",
971
- "Û": "U",
972
- "Ü": "U",
973
- "ù": "u",
974
- "ú": "u",
975
- "û": "u",
976
- "ü": "u",
977
- "Ý": "Y",
978
- "ý": "y",
979
- "ÿ": "y",
980
- "Æ": "Ae",
981
- "æ": "ae",
982
- "Þ": "Th",
983
- "þ": "th",
984
- "ß": "ss",
985
- "Ā": "A",
986
- "Ă": "A",
987
- "Ą": "A",
988
- "ā": "a",
989
- "ă": "a",
990
- "ą": "a",
991
- "Ć": "C",
992
- "Ĉ": "C",
993
- "Ċ": "C",
994
- "Č": "C",
995
- "ć": "c",
996
- "ĉ": "c",
997
- "ċ": "c",
998
- "č": "c",
999
- "Ď": "D",
1000
- "Đ": "D",
1001
- "ď": "d",
1002
- "đ": "d",
1003
- "Ē": "E",
1004
- "Ĕ": "E",
1005
- "Ė": "E",
1006
- "Ę": "E",
1007
- "Ě": "E",
1008
- "ē": "e",
1009
- "ĕ": "e",
1010
- "ė": "e",
1011
- "ę": "e",
1012
- "ě": "e",
1013
- "Ĝ": "G",
1014
- "Ğ": "G",
1015
- "Ġ": "G",
1016
- "Ģ": "G",
1017
- "ĝ": "g",
1018
- "ğ": "g",
1019
- "ġ": "g",
1020
- "ģ": "g",
1021
- "Ĥ": "H",
1022
- "Ħ": "H",
1023
- "ĥ": "h",
1024
- "ħ": "h",
1025
- "Ĩ": "I",
1026
- "Ī": "I",
1027
- "Ĭ": "I",
1028
- "Į": "I",
1029
- "İ": "I",
1030
- "ĩ": "i",
1031
- "ī": "i",
1032
- "ĭ": "i",
1033
- "į": "i",
1034
- "ı": "i",
1035
- "Ĵ": "J",
1036
- "ĵ": "j",
1037
- "Ķ": "K",
1038
- "ķ": "k",
1039
- "ĸ": "k",
1040
- "Ĺ": "L",
1041
- "Ļ": "L",
1042
- "Ľ": "L",
1043
- "Ŀ": "L",
1044
- "Ł": "L",
1045
- "ĺ": "l",
1046
- "ļ": "l",
1047
- "ľ": "l",
1048
- "ŀ": "l",
1049
- "ł": "l",
1050
- "Ń": "N",
1051
- "Ņ": "N",
1052
- "Ň": "N",
1053
- "Ŋ": "N",
1054
- "ń": "n",
1055
- "ņ": "n",
1056
- "ň": "n",
1057
- "ŋ": "n",
1058
- "Ō": "O",
1059
- "Ŏ": "O",
1060
- "Ő": "O",
1061
- "ō": "o",
1062
- "ŏ": "o",
1063
- "ő": "o",
1064
- "Ŕ": "R",
1065
- "Ŗ": "R",
1066
- "Ř": "R",
1067
- "ŕ": "r",
1068
- "ŗ": "r",
1069
- "ř": "r",
1070
- "Ś": "S",
1071
- "Ŝ": "S",
1072
- "Ş": "S",
1073
- "Š": "S",
1074
- "ś": "s",
1075
- "ŝ": "s",
1076
- "ş": "s",
1077
- "š": "s",
1078
- "Ţ": "T",
1079
- "Ť": "T",
1080
- "Ŧ": "T",
1081
- "ţ": "t",
1082
- "ť": "t",
1083
- "ŧ": "t",
1084
- "Ũ": "U",
1085
- "Ū": "U",
1086
- "Ŭ": "U",
1087
- "Ů": "U",
1088
- "Ű": "U",
1089
- "Ų": "U",
1090
- "ũ": "u",
1091
- "ū": "u",
1092
- "ŭ": "u",
1093
- "ů": "u",
1094
- "ű": "u",
1095
- "ų": "u",
1096
- "Ŵ": "W",
1097
- "ŵ": "w",
1098
- "Ŷ": "Y",
1099
- "ŷ": "y",
1100
- "Ÿ": "Y",
1101
- "Ź": "Z",
1102
- "Ż": "Z",
1103
- "Ž": "Z",
1104
- "ź": "z",
1105
- "ż": "z",
1106
- "ž": "z",
1107
- "IJ": "IJ",
1108
- "ij": "ij",
1109
- "Œ": "Oe",
1110
- "œ": "oe",
1111
- "ʼn": "'n",
1112
- "ſ": "ss"
1113
- };
1114
- /** Detect free variable `global` from Node.js. */
1115
- var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
1116
- /** Detect free variable `self`. */
1117
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
1118
- /** Used as a reference to the global object. */
1119
- var root = freeGlobal || freeSelf || Function("return this")();
1120
- /**
1121
- * The base implementation of `_.propertyOf` without support for deep paths.
1122
- *
1123
- * @private
1124
- * @param {Object} object The object to query.
1125
- * @returns {Function} Returns the new accessor function.
1126
- */
1127
- function basePropertyOf(object) {
1128
- return function(key) {
1129
- return object == null ? void 0 : object[key];
1130
- };
1131
- }
1132
- /**
1133
- * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
1134
- * letters to basic Latin letters.
1135
- *
1136
- * @private
1137
- * @param {string} letter The matched letter to deburr.
1138
- * @returns {string} Returns the deburred letter.
1139
- */
1140
- var deburrLetter = basePropertyOf(deburredLetters);
1141
- /**
1142
- * Used to resolve the
1143
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1144
- * of values.
1145
- */
1146
- var objectToString = Object.prototype.toString;
1147
- /** Built-in value references. */
1148
- var Symbol$1 = root.Symbol;
1149
- /** Used to convert symbols to primitives and strings. */
1150
- var symbolProto = Symbol$1 ? Symbol$1.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
1151
- /**
1152
- * The base implementation of `_.toString` which doesn't convert nullish
1153
- * values to empty strings.
1154
- *
1155
- * @private
1156
- * @param {*} value The value to process.
1157
- * @returns {string} Returns the string.
1158
- */
1159
- function baseToString(value) {
1160
- if (typeof value == "string") return value;
1161
- if (isSymbol(value)) return symbolToString ? symbolToString.call(value) : "";
1162
- var result = value + "";
1163
- return result == "0" && 1 / value == -INFINITY ? "-0" : result;
1164
- }
1165
- /**
1166
- * Checks if `value` is object-like. A value is object-like if it's not `null`
1167
- * and has a `typeof` result of "object".
1168
- *
1169
- * @static
1170
- * @memberOf _
1171
- * @since 4.0.0
1172
- * @category Lang
1173
- * @param {*} value The value to check.
1174
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1175
- * @example
1176
- *
1177
- * _.isObjectLike({});
1178
- * // => true
1179
- *
1180
- * _.isObjectLike([1, 2, 3]);
1181
- * // => true
1182
- *
1183
- * _.isObjectLike(_.noop);
1184
- * // => false
1185
- *
1186
- * _.isObjectLike(null);
1187
- * // => false
1188
- */
1189
- function isObjectLike(value) {
1190
- return !!value && typeof value == "object";
1191
- }
1192
- /**
1193
- * Checks if `value` is classified as a `Symbol` primitive or object.
1194
- *
1195
- * @static
1196
- * @memberOf _
1197
- * @since 4.0.0
1198
- * @category Lang
1199
- * @param {*} value The value to check.
1200
- * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
1201
- * @example
1202
- *
1203
- * _.isSymbol(Symbol.iterator);
1204
- * // => true
1205
- *
1206
- * _.isSymbol('abc');
1207
- * // => false
1208
- */
1209
- function isSymbol(value) {
1210
- return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
1211
- }
1212
- /**
1213
- * Converts `value` to a string. An empty string is returned for `null`
1214
- * and `undefined` values. The sign of `-0` is preserved.
1215
- *
1216
- * @static
1217
- * @memberOf _
1218
- * @since 4.0.0
1219
- * @category Lang
1220
- * @param {*} value The value to process.
1221
- * @returns {string} Returns the string.
1222
- * @example
1223
- *
1224
- * _.toString(null);
1225
- * // => ''
1226
- *
1227
- * _.toString(-0);
1228
- * // => '-0'
1229
- *
1230
- * _.toString([1, 2, 3]);
1231
- * // => '1,2,3'
1232
- */
1233
- function toString(value) {
1234
- return value == null ? "" : baseToString(value);
1235
- }
1236
- /**
1237
- * Deburrs `string` by converting
1238
- * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
1239
- * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
1240
- * letters to basic Latin letters and removing
1241
- * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
1242
- *
1243
- * @static
1244
- * @memberOf _
1245
- * @since 3.0.0
1246
- * @category String
1247
- * @param {string} [string=''] The string to deburr.
1248
- * @returns {string} Returns the deburred string.
1249
- * @example
1250
- *
1251
- * _.deburr('déjà vu');
1252
- * // => 'deja vu'
1253
- */
1254
- function deburr$1(string) {
1255
- string = toString(string);
1256
- return string && string.replace(reLatin, deburrLetter).replace(reComboMark, "");
1257
- }
1258
- module.exports = deburr$1;
1259
- }));
1260
-
1261
- //#endregion
1262
- //#region ../../node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs
1263
- var import_fastest_levenshtein = require_fastest_levenshtein();
1264
- var import_lodash = /* @__PURE__ */ __toESM(require_lodash(), 1);
1265
- let ReturnTypeEnums = /* @__PURE__ */ function(ReturnTypeEnums$1) {
1266
- ReturnTypeEnums$1["ALL_CLOSEST_MATCHES"] = "all-closest-matches";
1267
- ReturnTypeEnums$1["ALL_MATCHES"] = "all-matches";
1268
- ReturnTypeEnums$1["ALL_SORTED_MATCHES"] = "all-sorted-matches";
1269
- ReturnTypeEnums$1["FIRST_CLOSEST_MATCH"] = "first-closest-match";
1270
- ReturnTypeEnums$1["FIRST_MATCH"] = "first-match";
1271
- return ReturnTypeEnums$1;
1272
- }({});
1273
- let ThresholdTypeEnums = /* @__PURE__ */ function(ThresholdTypeEnums$1) {
1274
- ThresholdTypeEnums$1["EDIT_DISTANCE"] = "edit-distance";
1275
- ThresholdTypeEnums$1["SIMILARITY"] = "similarity";
1276
- return ThresholdTypeEnums$1;
1277
- }({});
1278
- const fillDefaultOptions = (options) => {
1279
- const optionsWithDefaultValues = {
1280
- caseSensitive: false,
1281
- deburr: true,
1282
- matchPath: [],
1283
- returnType: ReturnTypeEnums.FIRST_CLOSEST_MATCH,
1284
- thresholdType: ThresholdTypeEnums.SIMILARITY,
1285
- trimSpaces: true,
1286
- ...options
1287
- };
1288
- if (!Object.values(ReturnTypeEnums).includes(optionsWithDefaultValues.returnType)) throw new TypeError("unknown returnType");
1289
- if (!Object.values(ThresholdTypeEnums).includes(optionsWithDefaultValues.thresholdType)) throw new TypeError("unknown thresholdType");
1290
- switch (optionsWithDefaultValues.thresholdType) {
1291
- case ThresholdTypeEnums.EDIT_DISTANCE: return {
1292
- threshold: 20,
1293
- ...optionsWithDefaultValues
1294
- };
1295
- case ThresholdTypeEnums.SIMILARITY: return {
1296
- threshold: .4,
1297
- ...optionsWithDefaultValues
1298
- };
1299
- }
1300
- };
1301
- /**
1302
- * Using edit distance between `a` and `b` to calculate similarity
1303
- *
1304
- * @param {string} a - `input`
1305
- * @param {string} b - String from `matchList`
1306
- * @returns {number} similarity between `a` and `b`
1307
- */
1308
- const getSimilarity = (a, b) => {
1309
- if (!a || !b) return 0;
1310
- if (a === b) return 1;
1311
- const editDistance = (0, import_fastest_levenshtein.distance)(a, b);
1312
- const longestLength = Math.max(a.length, b.length);
1313
- return (longestLength - editDistance) / longestLength;
1314
- };
1315
- /**
1316
- * Normalize a string
1317
- *
1318
- * @param {string} str - any string
1319
- * @param {object} options - options that allows you to modify the behavior
1320
- * @returns {string} - normalized string
1321
- */
1322
- const normalizeString = (str, options) => {
1323
- let s = str;
1324
- if (options.trimSpaces) s = s.trim().replaceAll(/\s+/gu, " ");
1325
- if (options.deburr) s = (0, import_lodash.default)(s);
1326
- if (!options.caseSensitive) s = s.toLowerCase();
1327
- return s;
1328
- };
1329
- const getMatchItemStr = (matchItem, matchPath) => {
1330
- const matchItemStr = matchPath.length > 0 ? matchPath.reduce((acc, prop) => {
1331
- return acc?.[prop];
1332
- }, matchItem) : matchItem;
1333
- if (typeof matchItemStr !== "string") return "";
1334
- return matchItemStr;
1335
- };
1336
- /**
1337
- * Process matchItem according to options
1338
- *
1339
- * @param {object | string} matchItem - Item for matching with `input`
1340
- * @param {object} options - options that allows you to modify the behavior
1341
- * @returns {string} - processed matchItem
1342
- */
1343
- const matchItemProcessor = (matchItem, options) => {
1344
- const { matchPath } = options;
1345
- return normalizeString(getMatchItemStr(matchItem, matchPath), options);
1346
- };
1347
- /**
1348
- * Generate result
1349
- *
1350
- * @param {object[] | string[]} matchList - List for matching with `input`
1351
- * @param {number[]} matchedIndexes - indexes of matchList that need to be returned as result
1352
- * @param {ReturnTypeEnums} returnType - how the result will response to user
1353
- * @returns {Array | null | object | string} - matched result(s), return object if `match` is `{Object[]}`
1354
- */
1355
- const resultProcessor = (matchList, matchedIndexes, returnType) => {
1356
- switch (returnType) {
1357
- case ReturnTypeEnums.ALL_CLOSEST_MATCHES:
1358
- case ReturnTypeEnums.ALL_MATCHES:
1359
- case ReturnTypeEnums.ALL_SORTED_MATCHES: return matchedIndexes.map((matchedIndex) => matchList[matchedIndex]);
1360
- case ReturnTypeEnums.FIRST_CLOSEST_MATCH:
1361
- case ReturnTypeEnums.FIRST_MATCH: {
1362
- const matchedIndex = matchedIndexes[0];
1363
- if (matchedIndex === void 0) return null;
1364
- return matchList[matchedIndex];
1365
- }
1366
- }
1367
- };
1368
- /**
1369
- * Main function for didyoumean2
1370
- *
1371
- * @param {string} input - string that you are not sure and want to match with `matchList`
1372
- * @param {object[] | string[]} matchList - List for matching with `input`
1373
- * @param {null | object | undefined} options - options that allows you to modify the behavior
1374
- * @returns {Array | null | object | string} - matched result(s), return object if `match` is `{Object[]}`
1375
- */
1376
- function didYouMean(input, matchList, options) {
1377
- const optionsWithDefaults = fillDefaultOptions(options);
1378
- const { returnType, threshold, thresholdType } = optionsWithDefaults;
1379
- const normalizedInput = normalizeString(input, optionsWithDefaults);
1380
- let checkIfMatched;
1381
- let scoreProcessor;
1382
- switch (thresholdType) {
1383
- case ThresholdTypeEnums.EDIT_DISTANCE:
1384
- checkIfMatched = (score) => score <= threshold;
1385
- scoreProcessor = (matchItem) => (0, import_fastest_levenshtein.distance)(normalizedInput, matchItemProcessor(matchItem, optionsWithDefaults));
1386
- break;
1387
- case ThresholdTypeEnums.SIMILARITY:
1388
- checkIfMatched = (score) => score >= threshold;
1389
- scoreProcessor = (matchItem) => getSimilarity(normalizedInput, matchItemProcessor(matchItem, optionsWithDefaults));
1390
- break;
1391
- }
1392
- const matchedIndexes = [];
1393
- switch (returnType) {
1394
- case ReturnTypeEnums.ALL_CLOSEST_MATCHES:
1395
- case ReturnTypeEnums.FIRST_CLOSEST_MATCH: {
1396
- const scores = [];
1397
- let marginValue;
1398
- switch (thresholdType) {
1399
- case ThresholdTypeEnums.EDIT_DISTANCE:
1400
- marginValue = Number.POSITIVE_INFINITY;
1401
- for (const matchItem of matchList) {
1402
- const score = scoreProcessor(matchItem);
1403
- if (marginValue > score) marginValue = score;
1404
- scores.push(score);
1405
- }
1406
- break;
1407
- case ThresholdTypeEnums.SIMILARITY:
1408
- marginValue = 0;
1409
- for (const matchItem of matchList) {
1410
- const score = scoreProcessor(matchItem);
1411
- if (marginValue < score) marginValue = score;
1412
- scores.push(score);
1413
- }
1414
- break;
1415
- }
1416
- for (const [i, score] of scores.entries()) if (checkIfMatched(score) && score === marginValue) matchedIndexes.push(i);
1417
- break;
1418
- }
1419
- case ReturnTypeEnums.ALL_MATCHES:
1420
- for (const [i, matchItem] of matchList.entries()) {
1421
- const score = scoreProcessor(matchItem);
1422
- if (checkIfMatched(score)) matchedIndexes.push(i);
1423
- }
1424
- break;
1425
- case ReturnTypeEnums.ALL_SORTED_MATCHES: {
1426
- const unsortedResults = [];
1427
- for (const [i, matchItem] of matchList.entries()) {
1428
- const score = scoreProcessor(matchItem);
1429
- if (checkIfMatched(score)) unsortedResults.push({
1430
- score,
1431
- index: i
1432
- });
1433
- }
1434
- switch (thresholdType) {
1435
- case ThresholdTypeEnums.EDIT_DISTANCE:
1436
- unsortedResults.sort((a, b) => a.score - b.score);
1437
- break;
1438
- case ThresholdTypeEnums.SIMILARITY:
1439
- unsortedResults.sort((a, b) => b.score - a.score);
1440
- break;
1441
- }
1442
- for (const unsortedResult of unsortedResults) matchedIndexes.push(unsortedResult.index);
1443
- break;
1444
- }
1445
- case ReturnTypeEnums.FIRST_MATCH:
1446
- for (const [i, matchItem] of matchList.entries()) {
1447
- const score = scoreProcessor(matchItem);
1448
- if (checkIfMatched(score)) {
1449
- matchedIndexes.push(i);
1450
- break;
1451
- }
1452
- }
1453
- break;
1454
- }
1455
- return resultProcessor(matchList, matchedIndexes, returnType);
1456
- }
1457
-
1458
- //#endregion
1459
- //#region ../plugin-not-found/src/index.ts
1460
- const notFoundPlugin = () => definePlugin({ setup: (cli) => cli.interceptor({
1461
- enforce: "post",
1462
- handler: async (_ctx, next) => {
1463
- const commandKeys = [...cli._commands.keys()];
1464
- const hasCommands = commandKeys.length > 0;
1465
- try {
1466
- await next();
1467
- } catch (e) {
1468
- if (!(e instanceof NoSuchCommandError || e instanceof NoCommandSpecifiedError)) throw e;
1469
- if (e instanceof NoCommandSpecifiedError) {
1470
- let text$1 = "No command specified.";
1471
- if (hasCommands) text$1 += `\nPossible commands: ${commandKeys.join(", ")}.`;
1472
- throw new NoCommandSpecifiedError(text$1);
1473
- }
1474
- const { commandName } = e;
1475
- const closestCommandName = didYouMean(commandName, commandKeys);
1476
- let text = `Command "${strikethrough(commandName)}" not found.`;
1477
- if (hasCommands && closestCommandName) text += `\nDid you mean "${bold(closestCommandName)}"?`;
1478
- else if (!hasCommands) text += "\nNo commands registered.";
1479
- throw new NoSuchCommandError(commandName, text);
1480
- }
1481
- }
1482
- }) });
1483
-
1484
- //#endregion
1485
- //#region ../plugin-strict-flags/src/index.ts
1486
- const strictFlagsPlugin = () => definePlugin({ setup: (cli) => {
1487
- cli.interceptor(async (ctx, next) => {
1488
- const keys = Object.keys(ctx.rawParsed.unknown);
1489
- if (!ctx.command || keys.length === 0) await next();
1490
- else throw keys.length > 1 ? /* @__PURE__ */ new Error(`Unexpected flags: ${joinWithAnd(keys)}`) : /* @__PURE__ */ new Error(`Unexpected flag: ${keys[0]}`);
1491
- });
1492
- } });
1493
-
1494
- //#endregion
1495
- //#region ../clerc/src/re-exports.ts
1496
- var re_exports_exports = /* @__PURE__ */ __export({
1497
- completionsPlugin: () => completionsPlugin,
1498
- defaultFormatters: () => defaultFormatters,
1499
- friendlyErrorPlugin: () => friendlyErrorPlugin,
1500
- helpPlugin: () => helpPlugin,
1501
- notFoundPlugin: () => notFoundPlugin,
1502
- strictFlagsPlugin: () => strictFlagsPlugin,
1503
- versionPlugin: () => versionPlugin
1504
- });
1505
- import * as import___clerc_core from "@clerc/core";
1506
- __reExport(re_exports_exports, import___clerc_core);
1507
-
1508
- //#endregion
1509
- //#region ../clerc/src/index.ts
1510
- var src_exports = /* @__PURE__ */ __export({
1511
- Cli: () => Cli,
1512
- completionsPlugin: () => completionsPlugin,
1513
- defaultFormatters: () => defaultFormatters,
1514
- friendlyErrorPlugin: () => friendlyErrorPlugin,
1515
- helpPlugin: () => helpPlugin,
1516
- notFoundPlugin: () => notFoundPlugin,
1517
- strictFlagsPlugin: () => strictFlagsPlugin,
1518
- versionPlugin: () => versionPlugin
1519
- });
1520
- __reExport(src_exports, re_exports_exports);
1521
- const Cli = (options) => Clerc.create(options).use(versionPlugin()).use(helpPlugin());
1522
-
1523
- //#endregion
1524
4
  //#region src/t.ts
1525
5
  function resetTab() {
1526
6
  t.commands.clear();
@@ -1528,13 +8,18 @@ function resetTab() {
1528
8
  t.arguments.clear();
1529
9
  t.completions = [];
1530
10
  }
1531
- function registerGlobalFlags(globalFlags, tc) {
1532
- for (const [flagName, def] of Object.entries(globalFlags)) {
1533
- const normalized = (0, src_exports.normalizeFlagValue)(def);
1534
- const desc = normalized.description ?? "";
1535
- tc.option(flagName, desc, normalized.short);
11
+ function registerFlag(tc, flagName, def) {
12
+ const normalized = normalizeFlagValue(def);
13
+ const desc = normalized.description ?? "";
14
+ if (normalized.type === Boolean) tc.option(flagName, desc, normalized.short);
15
+ else {
16
+ const handler = normalized.completions?.handler ?? (async () => {});
17
+ tc.option(flagName, desc, handler, normalized.short);
1536
18
  }
1537
19
  }
20
+ function registerGlobalFlags(globalFlags, tc) {
21
+ for (const [flagName, def] of Object.entries(globalFlags)) registerFlag(tc, flagName, def);
22
+ }
1538
23
  function buildTabModel(globalFlags, commands) {
1539
24
  resetTab();
1540
25
  registerGlobalFlags(globalFlags, t);
@@ -1545,11 +30,13 @@ function buildTabModel(globalFlags, commands) {
1545
30
  command = t.command(cmd.name, cmd.description ?? "");
1546
31
  registerGlobalFlags(globalFlags, command);
1547
32
  }
1548
- for (const [flagName, def] of Object.entries(cmd.flags ?? {})) {
1549
- const normalized = (0, src_exports.normalizeFlagValue)(def);
1550
- const desc = normalized.description ?? "";
1551
- command.option(flagName, desc, normalized.short);
33
+ cmd.completions?.handler?.(command);
34
+ for (const def of cmd.parameters ?? []) {
35
+ const normalized = normalizeParameterValue(def);
36
+ const { name, isVariadic } = extractParameterInfo(normalized.key);
37
+ command.argument(name, normalized.completions?.handler, isVariadic);
1552
38
  }
39
+ for (const [flagName, def] of Object.entries(cmd.flags ?? {})) registerFlag(command, flagName, def);
1553
40
  }
1554
41
  }
1555
42