@bomb.sh/tab 0.0.4 → 0.0.5
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/bin/cli.js +3 -1352
- package/dist/cac-NlDEuVbb.js +1 -0
- package/dist/cac.d.ts +2 -2
- package/dist/cac.js +1 -5
- package/dist/citty.d.ts +2 -2
- package/dist/citty.js +1 -192
- package/dist/commander.d.ts +1 -1
- package/dist/commander.js +1 -102
- package/dist/{shared-NttFmF7I.d.ts → shared-BkI4Wff4.d.ts} +1 -1
- package/dist/shared-CDiJt0Dj.js +1 -0
- package/dist/t-BDEAdEmc.js +113 -457
- package/dist/t.d.ts +1 -1
- package/dist/t.js +1 -3
- package/package.json +18 -2
- package/dist/cac-D7fQPv8f.js +0 -92
- package/dist/consola.36c0034f-DcBvmSjS.js +0 -826
- package/dist/prompt-Cjrbe4Tk.js +0 -756
- package/dist/shared-H1O-vFhE.js +0 -11
- /package/dist/{t-_VA0Gr6E.d.ts → t-xAUxUB2j.d.ts} +0 -0
package/dist/bin/cli.js
CHANGED
|
@@ -1,1353 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import "../shared-H1O-vFhE.js";
|
|
4
|
-
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
|
-
import { EventEmitter } from "events";
|
|
7
|
-
import { readFileSync } from "node:fs";
|
|
8
|
-
import child_process from "node:child_process";
|
|
9
|
-
import { readFileSync as readFileSync$1 } from "fs";
|
|
10
|
-
import { execSync } from "child_process";
|
|
11
|
-
|
|
12
|
-
//#region node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
13
|
-
function toArr(any) {
|
|
14
|
-
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
15
|
-
}
|
|
16
|
-
function toVal(out, key, val, opts) {
|
|
17
|
-
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
18
|
-
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
19
|
-
}
|
|
20
|
-
function mri2(args, opts) {
|
|
21
|
-
args = args || [];
|
|
22
|
-
opts = opts || {};
|
|
23
|
-
var k, arr, arg, name, val, out = { _: [] };
|
|
24
|
-
var i = 0, j = 0, idx = 0, len = args.length;
|
|
25
|
-
const alibi = opts.alias !== void 0;
|
|
26
|
-
const strict = opts.unknown !== void 0;
|
|
27
|
-
const defaults = opts.default !== void 0;
|
|
28
|
-
opts.alias = opts.alias || {};
|
|
29
|
-
opts.string = toArr(opts.string);
|
|
30
|
-
opts.boolean = toArr(opts.boolean);
|
|
31
|
-
if (alibi) for (k in opts.alias) {
|
|
32
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
33
|
-
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
34
|
-
}
|
|
35
|
-
for (i = opts.boolean.length; i-- > 0;) {
|
|
36
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
37
|
-
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
38
|
-
}
|
|
39
|
-
for (i = opts.string.length; i-- > 0;) {
|
|
40
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
41
|
-
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
42
|
-
}
|
|
43
|
-
if (defaults) for (k in opts.default) {
|
|
44
|
-
name = typeof opts.default[k];
|
|
45
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
46
|
-
if (opts[name] !== void 0) {
|
|
47
|
-
opts[name].push(k);
|
|
48
|
-
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
52
|
-
for (i = 0; i < len; i++) {
|
|
53
|
-
arg = args[i];
|
|
54
|
-
if (arg === "--") {
|
|
55
|
-
out._ = out._.concat(args.slice(++i));
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
59
|
-
if (j === 0) out._.push(arg);
|
|
60
|
-
else if (arg.substring(j, j + 3) === "no-") {
|
|
61
|
-
name = arg.substring(j + 3);
|
|
62
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
63
|
-
out[name] = false;
|
|
64
|
-
} else {
|
|
65
|
-
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
66
|
-
name = arg.substring(j, idx);
|
|
67
|
-
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
68
|
-
arr = j === 2 ? [name] : name;
|
|
69
|
-
for (idx = 0; idx < arr.length; idx++) {
|
|
70
|
-
name = arr[idx];
|
|
71
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
72
|
-
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (defaults) {
|
|
77
|
-
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
78
|
-
}
|
|
79
|
-
if (alibi) for (k in out) {
|
|
80
|
-
arr = opts.alias[k] || [];
|
|
81
|
-
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
82
|
-
}
|
|
83
|
-
return out;
|
|
84
|
-
}
|
|
85
|
-
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
86
|
-
const findAllBrackets = (v) => {
|
|
87
|
-
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
88
|
-
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
89
|
-
const res = [];
|
|
90
|
-
const parse = (match) => {
|
|
91
|
-
let variadic = false;
|
|
92
|
-
let value = match[1];
|
|
93
|
-
if (value.startsWith("...")) {
|
|
94
|
-
value = value.slice(3);
|
|
95
|
-
variadic = true;
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
required: match[0].startsWith("<"),
|
|
99
|
-
value,
|
|
100
|
-
variadic
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
let angledMatch;
|
|
104
|
-
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
105
|
-
let squareMatch;
|
|
106
|
-
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
107
|
-
return res;
|
|
108
|
-
};
|
|
109
|
-
const getMriOptions = (options) => {
|
|
110
|
-
const result = {
|
|
111
|
-
alias: {},
|
|
112
|
-
boolean: []
|
|
113
|
-
};
|
|
114
|
-
for (const [index, option] of options.entries()) {
|
|
115
|
-
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
116
|
-
if (option.isBoolean) if (option.negated) {
|
|
117
|
-
if (!options.some((o, i) => {
|
|
118
|
-
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
119
|
-
})) result.boolean.push(option.names[0]);
|
|
120
|
-
} else result.boolean.push(option.names[0]);
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
};
|
|
124
|
-
const findLongest = (arr) => {
|
|
125
|
-
return arr.sort((a, b) => {
|
|
126
|
-
return a.length > b.length ? -1 : 1;
|
|
127
|
-
})[0];
|
|
128
|
-
};
|
|
129
|
-
const padRight = (str, length) => {
|
|
130
|
-
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
131
|
-
};
|
|
132
|
-
const camelcase = (input) => {
|
|
133
|
-
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
134
|
-
return p1 + p2.toUpperCase();
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
const setDotProp = (obj, keys, val) => {
|
|
138
|
-
let i = 0;
|
|
139
|
-
let length = keys.length;
|
|
140
|
-
let t = obj;
|
|
141
|
-
let x;
|
|
142
|
-
for (; i < length; ++i) {
|
|
143
|
-
x = t[keys[i]];
|
|
144
|
-
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
const setByType = (obj, transforms) => {
|
|
148
|
-
for (const key of Object.keys(transforms)) {
|
|
149
|
-
const transform = transforms[key];
|
|
150
|
-
if (transform.shouldTransform) {
|
|
151
|
-
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
152
|
-
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const getFileName = (input) => {
|
|
157
|
-
const m = /([^\\\/]+)$/.exec(input);
|
|
158
|
-
return m ? m[1] : "";
|
|
159
|
-
};
|
|
160
|
-
const camelcaseOptionName = (name) => {
|
|
161
|
-
return name.split(".").map((v, i) => {
|
|
162
|
-
return i === 0 ? camelcase(v) : v;
|
|
163
|
-
}).join(".");
|
|
164
|
-
};
|
|
165
|
-
var CACError = class extends Error {
|
|
166
|
-
constructor(message) {
|
|
167
|
-
super(message);
|
|
168
|
-
this.name = this.constructor.name;
|
|
169
|
-
if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, this.constructor);
|
|
170
|
-
else this.stack = new Error(message).stack;
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
var Option = class {
|
|
174
|
-
constructor(rawName, description, config) {
|
|
175
|
-
this.rawName = rawName;
|
|
176
|
-
this.description = description;
|
|
177
|
-
this.config = Object.assign({}, config);
|
|
178
|
-
rawName = rawName.replace(/\.\*/g, "");
|
|
179
|
-
this.negated = false;
|
|
180
|
-
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
181
|
-
let name = v.trim().replace(/^-{1,2}/, "");
|
|
182
|
-
if (name.startsWith("no-")) {
|
|
183
|
-
this.negated = true;
|
|
184
|
-
name = name.replace(/^no-/, "");
|
|
185
|
-
}
|
|
186
|
-
return camelcaseOptionName(name);
|
|
187
|
-
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
188
|
-
this.name = this.names[this.names.length - 1];
|
|
189
|
-
if (this.negated && this.config.default == null) this.config.default = true;
|
|
190
|
-
if (rawName.includes("<")) this.required = true;
|
|
191
|
-
else if (rawName.includes("[")) this.required = false;
|
|
192
|
-
else this.isBoolean = true;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
const processArgs = process.argv;
|
|
196
|
-
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
197
|
-
var Command = class {
|
|
198
|
-
constructor(rawName, description, config = {}, cli) {
|
|
199
|
-
this.rawName = rawName;
|
|
200
|
-
this.description = description;
|
|
201
|
-
this.config = config;
|
|
202
|
-
this.cli = cli;
|
|
203
|
-
this.options = [];
|
|
204
|
-
this.aliasNames = [];
|
|
205
|
-
this.name = removeBrackets(rawName);
|
|
206
|
-
this.args = findAllBrackets(rawName);
|
|
207
|
-
this.examples = [];
|
|
208
|
-
}
|
|
209
|
-
usage(text) {
|
|
210
|
-
this.usageText = text;
|
|
211
|
-
return this;
|
|
212
|
-
}
|
|
213
|
-
allowUnknownOptions() {
|
|
214
|
-
this.config.allowUnknownOptions = true;
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
ignoreOptionDefaultValue() {
|
|
218
|
-
this.config.ignoreOptionDefaultValue = true;
|
|
219
|
-
return this;
|
|
220
|
-
}
|
|
221
|
-
version(version, customFlags = "-v, --version") {
|
|
222
|
-
this.versionNumber = version;
|
|
223
|
-
this.option(customFlags, "Display version number");
|
|
224
|
-
return this;
|
|
225
|
-
}
|
|
226
|
-
example(example) {
|
|
227
|
-
this.examples.push(example);
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
option(rawName, description, config) {
|
|
231
|
-
const option = new Option(rawName, description, config);
|
|
232
|
-
this.options.push(option);
|
|
233
|
-
return this;
|
|
234
|
-
}
|
|
235
|
-
alias(name) {
|
|
236
|
-
this.aliasNames.push(name);
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
action(callback) {
|
|
240
|
-
this.commandAction = callback;
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
isMatched(name) {
|
|
244
|
-
return this.name === name || this.aliasNames.includes(name);
|
|
245
|
-
}
|
|
246
|
-
get isDefaultCommand() {
|
|
247
|
-
return this.name === "" || this.aliasNames.includes("!");
|
|
248
|
-
}
|
|
249
|
-
get isGlobalCommand() {
|
|
250
|
-
return this instanceof GlobalCommand;
|
|
251
|
-
}
|
|
252
|
-
hasOption(name) {
|
|
253
|
-
name = name.split(".")[0];
|
|
254
|
-
return this.options.find((option) => {
|
|
255
|
-
return option.names.includes(name);
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
outputHelp() {
|
|
259
|
-
const { name, commands } = this.cli;
|
|
260
|
-
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
261
|
-
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
262
|
-
sections.push({
|
|
263
|
-
title: "Usage",
|
|
264
|
-
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
265
|
-
});
|
|
266
|
-
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
267
|
-
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
268
|
-
sections.push({
|
|
269
|
-
title: "Commands",
|
|
270
|
-
body: commands.map((command) => {
|
|
271
|
-
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
272
|
-
}).join("\n")
|
|
273
|
-
});
|
|
274
|
-
sections.push({
|
|
275
|
-
title: `For more info, run any command with the \`--help\` flag`,
|
|
276
|
-
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
280
|
-
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
281
|
-
if (options.length > 0) {
|
|
282
|
-
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
283
|
-
sections.push({
|
|
284
|
-
title: "Options",
|
|
285
|
-
body: options.map((option) => {
|
|
286
|
-
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
287
|
-
}).join("\n")
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
if (this.examples.length > 0) sections.push({
|
|
291
|
-
title: "Examples",
|
|
292
|
-
body: this.examples.map((example) => {
|
|
293
|
-
if (typeof example === "function") return example(name);
|
|
294
|
-
return example;
|
|
295
|
-
}).join("\n")
|
|
296
|
-
});
|
|
297
|
-
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
298
|
-
console.log(sections.map((section) => {
|
|
299
|
-
return section.title ? `${section.title}:
|
|
300
|
-
${section.body}` : section.body;
|
|
301
|
-
}).join("\n\n"));
|
|
302
|
-
}
|
|
303
|
-
outputVersion() {
|
|
304
|
-
const { name } = this.cli;
|
|
305
|
-
const { versionNumber } = this.cli.globalCommand;
|
|
306
|
-
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
307
|
-
}
|
|
308
|
-
checkRequiredArgs() {
|
|
309
|
-
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
310
|
-
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
311
|
-
}
|
|
312
|
-
checkUnknownOptions() {
|
|
313
|
-
const { options, globalCommand } = this.cli;
|
|
314
|
-
if (!this.config.allowUnknownOptions) {
|
|
315
|
-
for (const name of Object.keys(options)) if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
checkOptionValue() {
|
|
319
|
-
const { options: parsedOptions, globalCommand } = this.cli;
|
|
320
|
-
const options = [...globalCommand.options, ...this.options];
|
|
321
|
-
for (const option of options) {
|
|
322
|
-
const value = parsedOptions[option.name.split(".")[0]];
|
|
323
|
-
if (option.required) {
|
|
324
|
-
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
325
|
-
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
var GlobalCommand = class extends Command {
|
|
331
|
-
constructor(cli) {
|
|
332
|
-
super("@@global@@", "", {}, cli);
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
var __assign = Object.assign;
|
|
336
|
-
var CAC = class extends EventEmitter {
|
|
337
|
-
constructor(name = "") {
|
|
338
|
-
super();
|
|
339
|
-
this.name = name;
|
|
340
|
-
this.commands = [];
|
|
341
|
-
this.rawArgs = [];
|
|
342
|
-
this.args = [];
|
|
343
|
-
this.options = {};
|
|
344
|
-
this.globalCommand = new GlobalCommand(this);
|
|
345
|
-
this.globalCommand.usage("<command> [options]");
|
|
346
|
-
}
|
|
347
|
-
usage(text) {
|
|
348
|
-
this.globalCommand.usage(text);
|
|
349
|
-
return this;
|
|
350
|
-
}
|
|
351
|
-
command(rawName, description, config) {
|
|
352
|
-
const command = new Command(rawName, description || "", config, this);
|
|
353
|
-
command.globalCommand = this.globalCommand;
|
|
354
|
-
this.commands.push(command);
|
|
355
|
-
return command;
|
|
356
|
-
}
|
|
357
|
-
option(rawName, description, config) {
|
|
358
|
-
this.globalCommand.option(rawName, description, config);
|
|
359
|
-
return this;
|
|
360
|
-
}
|
|
361
|
-
help(callback) {
|
|
362
|
-
this.globalCommand.option("-h, --help", "Display this message");
|
|
363
|
-
this.globalCommand.helpCallback = callback;
|
|
364
|
-
this.showHelpOnExit = true;
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
version(version, customFlags = "-v, --version") {
|
|
368
|
-
this.globalCommand.version(version, customFlags);
|
|
369
|
-
this.showVersionOnExit = true;
|
|
370
|
-
return this;
|
|
371
|
-
}
|
|
372
|
-
example(example) {
|
|
373
|
-
this.globalCommand.example(example);
|
|
374
|
-
return this;
|
|
375
|
-
}
|
|
376
|
-
outputHelp() {
|
|
377
|
-
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
378
|
-
else this.globalCommand.outputHelp();
|
|
379
|
-
}
|
|
380
|
-
outputVersion() {
|
|
381
|
-
this.globalCommand.outputVersion();
|
|
382
|
-
}
|
|
383
|
-
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
384
|
-
this.args = args;
|
|
385
|
-
this.options = options;
|
|
386
|
-
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
387
|
-
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
388
|
-
return this;
|
|
389
|
-
}
|
|
390
|
-
unsetMatchedCommand() {
|
|
391
|
-
this.matchedCommand = void 0;
|
|
392
|
-
this.matchedCommandName = void 0;
|
|
393
|
-
}
|
|
394
|
-
parse(argv = processArgs, { run = true } = {}) {
|
|
395
|
-
this.rawArgs = argv;
|
|
396
|
-
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
397
|
-
let shouldParse = true;
|
|
398
|
-
for (const command of this.commands) {
|
|
399
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
400
|
-
const commandName = parsed.args[0];
|
|
401
|
-
if (command.isMatched(commandName)) {
|
|
402
|
-
shouldParse = false;
|
|
403
|
-
const parsedInfo = __assign(__assign({}, parsed), { args: parsed.args.slice(1) });
|
|
404
|
-
this.setParsedInfo(parsedInfo, command, commandName);
|
|
405
|
-
this.emit(`command:${commandName}`, command);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if (shouldParse) {
|
|
409
|
-
for (const command of this.commands) if (command.name === "") {
|
|
410
|
-
shouldParse = false;
|
|
411
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
412
|
-
this.setParsedInfo(parsed, command);
|
|
413
|
-
this.emit(`command:!`, command);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (shouldParse) {
|
|
417
|
-
const parsed = this.mri(argv.slice(2));
|
|
418
|
-
this.setParsedInfo(parsed);
|
|
419
|
-
}
|
|
420
|
-
if (this.options.help && this.showHelpOnExit) {
|
|
421
|
-
this.outputHelp();
|
|
422
|
-
run = false;
|
|
423
|
-
this.unsetMatchedCommand();
|
|
424
|
-
}
|
|
425
|
-
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
426
|
-
this.outputVersion();
|
|
427
|
-
run = false;
|
|
428
|
-
this.unsetMatchedCommand();
|
|
429
|
-
}
|
|
430
|
-
const parsedArgv = {
|
|
431
|
-
args: this.args,
|
|
432
|
-
options: this.options
|
|
433
|
-
};
|
|
434
|
-
if (run) this.runMatchedCommand();
|
|
435
|
-
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
|
436
|
-
return parsedArgv;
|
|
437
|
-
}
|
|
438
|
-
mri(argv, command) {
|
|
439
|
-
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
440
|
-
const mriOptions = getMriOptions(cliOptions);
|
|
441
|
-
let argsAfterDoubleDashes = [];
|
|
442
|
-
const doubleDashesIndex = argv.indexOf("--");
|
|
443
|
-
if (doubleDashesIndex > -1) {
|
|
444
|
-
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
445
|
-
argv = argv.slice(0, doubleDashesIndex);
|
|
446
|
-
}
|
|
447
|
-
let parsed = mri2(argv, mriOptions);
|
|
448
|
-
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
449
|
-
return __assign(__assign({}, res), { [camelcaseOptionName(name)]: parsed[name] });
|
|
450
|
-
}, { _: [] });
|
|
451
|
-
const args = parsed._;
|
|
452
|
-
const options = { "--": argsAfterDoubleDashes };
|
|
453
|
-
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
454
|
-
let transforms = Object.create(null);
|
|
455
|
-
for (const cliOption of cliOptions) {
|
|
456
|
-
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
457
|
-
if (Array.isArray(cliOption.config.type)) {
|
|
458
|
-
if (transforms[cliOption.name] === void 0) {
|
|
459
|
-
transforms[cliOption.name] = Object.create(null);
|
|
460
|
-
transforms[cliOption.name]["shouldTransform"] = true;
|
|
461
|
-
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
466
|
-
const keys = key.split(".");
|
|
467
|
-
setDotProp(options, keys, parsed[key]);
|
|
468
|
-
setByType(options, transforms);
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
args,
|
|
472
|
-
options
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
runMatchedCommand() {
|
|
476
|
-
const { args, options, matchedCommand: command } = this;
|
|
477
|
-
if (!command || !command.commandAction) return;
|
|
478
|
-
command.checkUnknownOptions();
|
|
479
|
-
command.checkOptionValue();
|
|
480
|
-
command.checkRequiredArgs();
|
|
481
|
-
const actionArgs = [];
|
|
482
|
-
command.args.forEach((arg, index) => {
|
|
483
|
-
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
484
|
-
else actionArgs.push(args[index]);
|
|
485
|
-
});
|
|
486
|
-
actionArgs.push(options);
|
|
487
|
-
return command.commandAction.apply(this, actionArgs);
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
const cac = (name = "") => new CAC(name);
|
|
491
|
-
var dist_default = cac;
|
|
492
|
-
|
|
493
|
-
//#endregion
|
|
494
|
-
//#region bin/utils/filesystem-utils.ts
|
|
495
|
-
function getWorkspacePatterns() {
|
|
496
|
-
try {
|
|
497
|
-
let content;
|
|
498
|
-
try {
|
|
499
|
-
content = readFileSync("pnpm-workspace.yaml", "utf8");
|
|
500
|
-
} catch {
|
|
501
|
-
content = readFileSync("pnpm-workspace.yml", "utf8");
|
|
502
|
-
}
|
|
503
|
-
const packagesMatch = content.match(/packages:\s*\n((?:\s*-\s*.+\n?)*)/);
|
|
504
|
-
if (!packagesMatch) return [];
|
|
505
|
-
return packagesMatch[1].split("\n").map((line) => line.trim()).filter((line) => line.startsWith("-")).map((line) => line.substring(1).trim()).filter((pattern) => pattern && !pattern.startsWith("#"));
|
|
506
|
-
} catch {
|
|
507
|
-
return [];
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
//#endregion
|
|
512
|
-
//#region bin/utils/package-json-utils.ts
|
|
513
|
-
function getPackageJsonScripts() {
|
|
514
|
-
try {
|
|
515
|
-
const packageJson = JSON.parse(readFileSync$1("package.json", "utf8"));
|
|
516
|
-
return Object.keys(packageJson.scripts || {});
|
|
517
|
-
} catch {
|
|
518
|
-
return [];
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
function getPackageJsonDependencies() {
|
|
522
|
-
try {
|
|
523
|
-
const packageJson = JSON.parse(readFileSync$1("package.json", "utf8"));
|
|
524
|
-
const deps = {
|
|
525
|
-
...packageJson.dependencies,
|
|
526
|
-
...packageJson.devDependencies,
|
|
527
|
-
...packageJson.peerDependencies,
|
|
528
|
-
...packageJson.optionalDependencies
|
|
529
|
-
};
|
|
530
|
-
return Object.keys(deps);
|
|
531
|
-
} catch {
|
|
532
|
-
return [];
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
//#endregion
|
|
537
|
-
//#region bin/completions/completion-producers.ts
|
|
538
|
-
const packageJsonScriptCompletion = async (complete) => {
|
|
539
|
-
getPackageJsonScripts().forEach((script$1) => {
|
|
540
|
-
const escapedScript = script$1.replace(/:/g, "\\:");
|
|
541
|
-
complete(escapedScript, " ");
|
|
542
|
-
});
|
|
543
|
-
};
|
|
544
|
-
const packageJsonDependencyCompletion = async (complete) => {
|
|
545
|
-
getPackageJsonDependencies().forEach((dep) => complete(dep, ""));
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
//#endregion
|
|
549
|
-
//#region bin/utils/shared.ts
|
|
550
|
-
const exec = promisify(child_process.exec);
|
|
551
|
-
const { execSync: execSync$1 } = child_process;
|
|
552
|
-
const commonOptionHandlers = { workspace(complete) {
|
|
553
|
-
getWorkspacePatterns().forEach((p) => complete(p, `Workspace pattern: ${p}`));
|
|
554
|
-
} };
|
|
555
|
-
function setupLazyOptionLoading(cmd, command, _packageManager, loadOptionsSync) {
|
|
556
|
-
cmd._lazyCommand = command;
|
|
557
|
-
cmd._optionsLoaded = false;
|
|
558
|
-
const store = cmd.options;
|
|
559
|
-
cmd.optionsRaw = store;
|
|
560
|
-
Object.defineProperty(cmd, "options", {
|
|
561
|
-
get() {
|
|
562
|
-
if (!this._optionsLoaded) {
|
|
563
|
-
this._optionsLoaded = true;
|
|
564
|
-
loadOptionsSync(this, this._lazyCommand);
|
|
565
|
-
}
|
|
566
|
-
return store;
|
|
567
|
-
},
|
|
568
|
-
configurable: true
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
function setupCommandArguments(cmd, command, _packageManager) {
|
|
572
|
-
if ([
|
|
573
|
-
"remove",
|
|
574
|
-
"rm",
|
|
575
|
-
"uninstall",
|
|
576
|
-
"un",
|
|
577
|
-
"update",
|
|
578
|
-
"up"
|
|
579
|
-
].includes(command)) cmd.argument("package", packageJsonDependencyCompletion);
|
|
580
|
-
if (["run", "run-script"].includes(command)) cmd.argument("script", packageJsonScriptCompletion, true);
|
|
581
|
-
}
|
|
582
|
-
async function safeExec(command, options = {}) {
|
|
583
|
-
try {
|
|
584
|
-
const { stdout } = await exec(command, {
|
|
585
|
-
encoding: "utf8",
|
|
586
|
-
timeout: 500,
|
|
587
|
-
maxBuffer: 4 * 1024 * 1024,
|
|
588
|
-
...options
|
|
589
|
-
});
|
|
590
|
-
return stdout;
|
|
591
|
-
} catch (error) {
|
|
592
|
-
if (error instanceof Error && "stdout" in error) return error.stdout;
|
|
593
|
-
return "";
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function safeExecSync(command, options = {}) {
|
|
597
|
-
try {
|
|
598
|
-
return execSync$1(command, {
|
|
599
|
-
encoding: "utf8",
|
|
600
|
-
timeout: 500,
|
|
601
|
-
...options
|
|
602
|
-
});
|
|
603
|
-
} catch (error) {
|
|
604
|
-
return error?.stdout ? error.stdout : "";
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
function createLogLevelHandler(levels) {
|
|
608
|
-
return (complete) => levels.forEach((lvl) => complete(lvl, " "));
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
//#endregion
|
|
612
|
-
//#region bin/utils/text-utils.ts
|
|
613
|
-
const ANSI_ESCAPE_RE = /\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g;
|
|
614
|
-
const COMMAND_ROW_RE = /^\s+([a-z][a-z\s,-]*?)\s{2,}(\S.*)$/i;
|
|
615
|
-
const OPTION_ROW_RE = /^\s*(?:-(?<short>[A-Za-z]),\s*)?--(?<long>[a-z0-9-]+)(?<val>\s+(?:<[^>]+>|\[[^\]]+\]))?\s{2,}(?<desc>\S.*)$/i;
|
|
616
|
-
const OPTION_HEAD_RE = /^\s*(?:-[A-Za-z],\s*)?--[a-z0-9-]+/i;
|
|
617
|
-
const stripAnsiEscapes = (s) => s.replace(ANSI_ESCAPE_RE, "");
|
|
618
|
-
const measureIndent = (s) => (s.match(/^\s*/) || [""])[0].length;
|
|
619
|
-
const parseAliasList = (s) => s.split(",").map((t) => t.trim()).filter(Boolean);
|
|
620
|
-
|
|
621
|
-
//#endregion
|
|
622
|
-
//#region bin/handlers/pnpm-handler.ts
|
|
623
|
-
const OPTIONS_SECTION_RE$2 = /^\s*Options:/i;
|
|
624
|
-
const LEVEL_MATCH_RE = /(?:levels?|options?|values?)[^:]*:\s*([^.]+)/i;
|
|
625
|
-
const LINE_SPLIT_RE$2 = /\r?\n/;
|
|
626
|
-
const COMMA_SPACE_SPLIT_RE = /[,\s]+/;
|
|
627
|
-
const OPTION_WITH_VALUE_RE = /^\s*(?:-\w,?\s*)?--(\w+(?:-\w+)*)\s+(\w+(?:-\w+)*)\s+(.+)$/;
|
|
628
|
-
const OPTION_ALIAS_RE = /^\s*-\w,?\s*--\w+(?:,\s*--(\w+(?:-\w+)*)\s+(\w+(?:-\w+)*))?\s+(.+)$/;
|
|
629
|
-
const CONTINUATION_LINE_RE = /^\s{20,}/;
|
|
630
|
-
const SECTION_HEADER_RE = /^\s*[A-Z][^:]*:\s*$/;
|
|
631
|
-
function toLines$3(text) {
|
|
632
|
-
return stripAnsiEscapes(text).split(LINE_SPLIT_RE$2);
|
|
633
|
-
}
|
|
634
|
-
function findCommandDescColumn(lines) {
|
|
635
|
-
let col = Number.POSITIVE_INFINITY;
|
|
636
|
-
for (const line of lines) {
|
|
637
|
-
const m = line.match(COMMAND_ROW_RE);
|
|
638
|
-
if (!m) continue;
|
|
639
|
-
const idx = line.indexOf(m[2]);
|
|
640
|
-
if (idx >= 0 && idx < col) col = idx;
|
|
641
|
-
}
|
|
642
|
-
return col;
|
|
643
|
-
}
|
|
644
|
-
function findOptionDescColumn(lines, flagsOnly) {
|
|
645
|
-
let col = Number.POSITIVE_INFINITY;
|
|
646
|
-
for (const line of lines) {
|
|
647
|
-
const m = line.match(OPTION_ROW_RE);
|
|
648
|
-
if (!m) continue;
|
|
649
|
-
if (flagsOnly && m.groups?.val) continue;
|
|
650
|
-
const idx = line.indexOf(m.groups.desc);
|
|
651
|
-
if (idx >= 0 && idx < col) col = idx;
|
|
652
|
-
}
|
|
653
|
-
return col;
|
|
654
|
-
}
|
|
655
|
-
function extractValidValuesFromHelp(helpText, optionName) {
|
|
656
|
-
const lines = toLines$3(helpText);
|
|
657
|
-
const results = [];
|
|
658
|
-
for (let i = 0; i < lines.length; i++) {
|
|
659
|
-
const line = lines[i];
|
|
660
|
-
const optionMatch = line.match(OPTION_WITH_VALUE_RE);
|
|
661
|
-
if (optionMatch) {
|
|
662
|
-
const [, option, value, initialDesc] = optionMatch;
|
|
663
|
-
if (option === optionName) {
|
|
664
|
-
let fullDesc = initialDesc.trim();
|
|
665
|
-
let j = i + 1;
|
|
666
|
-
while (j < lines.length) {
|
|
667
|
-
const nextLine = lines[j];
|
|
668
|
-
const isIndented = CONTINUATION_LINE_RE.test(nextLine);
|
|
669
|
-
const isNewOption = OPTION_WITH_VALUE_RE.test(nextLine) || OPTION_ALIAS_RE.test(nextLine);
|
|
670
|
-
const isEmptyOrSection = !nextLine.trim() || SECTION_HEADER_RE.test(nextLine);
|
|
671
|
-
if (isIndented && !isNewOption && !isEmptyOrSection) {
|
|
672
|
-
fullDesc += " " + nextLine.trim();
|
|
673
|
-
j++;
|
|
674
|
-
} else break;
|
|
675
|
-
}
|
|
676
|
-
results.push({
|
|
677
|
-
value,
|
|
678
|
-
desc: fullDesc
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
const aliasMatch = line.match(OPTION_ALIAS_RE);
|
|
683
|
-
if (aliasMatch) {
|
|
684
|
-
const [, option, value, initialDesc] = aliasMatch;
|
|
685
|
-
if (option === optionName && value) {
|
|
686
|
-
let fullDesc = initialDesc.trim();
|
|
687
|
-
let j = i + 1;
|
|
688
|
-
while (j < lines.length) {
|
|
689
|
-
const nextLine = lines[j];
|
|
690
|
-
const isIndented = CONTINUATION_LINE_RE.test(nextLine);
|
|
691
|
-
const isNewOption = OPTION_WITH_VALUE_RE.test(nextLine) || OPTION_ALIAS_RE.test(nextLine);
|
|
692
|
-
const isEmptyOrSection = !nextLine.trim() || SECTION_HEADER_RE.test(nextLine);
|
|
693
|
-
if (isIndented && !isNewOption && !isEmptyOrSection) {
|
|
694
|
-
fullDesc += " " + nextLine.trim();
|
|
695
|
-
j++;
|
|
696
|
-
} else break;
|
|
697
|
-
}
|
|
698
|
-
results.push({
|
|
699
|
-
value,
|
|
700
|
-
desc: fullDesc
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
if (results.length) return results;
|
|
706
|
-
for (let i = 0; i < lines.length; i++) {
|
|
707
|
-
const ln = lines[i];
|
|
708
|
-
if (ln.includes(`--${optionName}`) || ln.includes(`${optionName}:`)) for (let j = i; j < Math.min(i + 3, lines.length); j++) {
|
|
709
|
-
const m = lines[j].match(LEVEL_MATCH_RE);
|
|
710
|
-
if (m) return m[1].split(COMMA_SPACE_SPLIT_RE).map((v) => v.trim()).filter((v) => v && !v.includes("(") && !v.includes(")")).map((value) => ({
|
|
711
|
-
value,
|
|
712
|
-
desc: `Log level: ${value}`
|
|
713
|
-
}));
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
return [];
|
|
717
|
-
}
|
|
718
|
-
const pnpmOptionHandlers = {
|
|
719
|
-
...commonOptionHandlers,
|
|
720
|
-
loglevel(complete) {
|
|
721
|
-
const fromHelp = extractValidValuesFromHelp(safeExecSync("pnpm install --help"), "loglevel");
|
|
722
|
-
if (fromHelp.length) fromHelp.forEach(({ value, desc }) => complete(value, desc));
|
|
723
|
-
else createLogLevelHandler([
|
|
724
|
-
"debug",
|
|
725
|
-
"info",
|
|
726
|
-
"warn",
|
|
727
|
-
"error",
|
|
728
|
-
"silent"
|
|
729
|
-
])(complete);
|
|
730
|
-
},
|
|
731
|
-
reporter(complete) {
|
|
732
|
-
const out = extractValidValuesFromHelp(safeExecSync("pnpm install --help"), "reporter");
|
|
733
|
-
if (out.length) out.forEach(({ value, desc }) => complete(value, desc));
|
|
734
|
-
else createLogLevelHandler([
|
|
735
|
-
"default",
|
|
736
|
-
"append-only",
|
|
737
|
-
"ndjson",
|
|
738
|
-
"silent"
|
|
739
|
-
])(complete);
|
|
740
|
-
},
|
|
741
|
-
filter(complete) {
|
|
742
|
-
complete(".", "Current working directory");
|
|
743
|
-
complete("!<selector>", "Exclude packages matching selector");
|
|
744
|
-
getWorkspacePatterns().forEach((p) => {
|
|
745
|
-
complete(p, `Workspace pattern: ${p}`);
|
|
746
|
-
complete(`${p}...`, `Include dependencies of ${p}`);
|
|
747
|
-
});
|
|
748
|
-
complete("@*/*", "All scoped packages");
|
|
749
|
-
complete("...<pattern>", "Include dependencies of pattern");
|
|
750
|
-
complete("<pattern>...", "Include dependents of pattern");
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
function parsePnpmHelp(helpText) {
|
|
754
|
-
const lines = toLines$3(helpText);
|
|
755
|
-
const descCol = findCommandDescColumn(lines);
|
|
756
|
-
if (!Number.isFinite(descCol)) return {};
|
|
757
|
-
let pending = null;
|
|
758
|
-
const out = /* @__PURE__ */ new Map();
|
|
759
|
-
const flush = () => {
|
|
760
|
-
if (!pending) return;
|
|
761
|
-
const desc = pending.desc.trim();
|
|
762
|
-
for (const n of pending.names) out.set(n, desc);
|
|
763
|
-
pending = null;
|
|
764
|
-
};
|
|
765
|
-
for (const line of lines) {
|
|
766
|
-
if (OPTIONS_SECTION_RE$2.test(line)) break;
|
|
767
|
-
const row = line.match(COMMAND_ROW_RE);
|
|
768
|
-
if (row) {
|
|
769
|
-
flush();
|
|
770
|
-
pending = {
|
|
771
|
-
names: parseAliasList(row[1]),
|
|
772
|
-
desc: row[2].trim()
|
|
773
|
-
};
|
|
774
|
-
continue;
|
|
775
|
-
}
|
|
776
|
-
if (pending) {
|
|
777
|
-
if (measureIndent(line) >= descCol && line.trim()) pending.desc += " " + line.trim();
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
flush();
|
|
781
|
-
return Object.fromEntries(out);
|
|
782
|
-
}
|
|
783
|
-
async function getPnpmCommandsFromMainHelp() {
|
|
784
|
-
const output = await safeExec("pnpm --help");
|
|
785
|
-
return output ? parsePnpmHelp(output) : {};
|
|
786
|
-
}
|
|
787
|
-
function parsePnpmOptions(helpText, { flagsOnly = true } = {}) {
|
|
788
|
-
const lines = toLines$3(helpText);
|
|
789
|
-
const descCol = findOptionDescColumn(lines, flagsOnly);
|
|
790
|
-
if (!Number.isFinite(descCol)) return [];
|
|
791
|
-
const out = [];
|
|
792
|
-
let pending = null;
|
|
793
|
-
const flush = () => {
|
|
794
|
-
if (!pending) return;
|
|
795
|
-
pending.desc = pending.desc.trim();
|
|
796
|
-
out.push(pending);
|
|
797
|
-
pending = null;
|
|
798
|
-
};
|
|
799
|
-
for (const line of lines) {
|
|
800
|
-
const m = line.match(OPTION_ROW_RE);
|
|
801
|
-
if (m) {
|
|
802
|
-
if (flagsOnly && m.groups?.val) continue;
|
|
803
|
-
flush();
|
|
804
|
-
pending = {
|
|
805
|
-
short: m.groups?.short || void 0,
|
|
806
|
-
long: m.groups.long,
|
|
807
|
-
desc: m.groups.desc.trim()
|
|
808
|
-
};
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
if (pending) {
|
|
812
|
-
const indent = measureIndent(line);
|
|
813
|
-
const startsNew = OPTION_HEAD_RE.test(line);
|
|
814
|
-
if (indent >= descCol && line.trim() && !startsNew) pending.desc += " " + line.trim();
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
flush();
|
|
818
|
-
return out;
|
|
819
|
-
}
|
|
820
|
-
function loadPnpmOptionsSync(cmd, command) {
|
|
821
|
-
const output = safeExecSync(`pnpm ${command} --help`);
|
|
822
|
-
if (!output) return;
|
|
823
|
-
const options = parsePnpmOptions(output, { flagsOnly: false });
|
|
824
|
-
for (const { long, short, desc } of options) {
|
|
825
|
-
if (cmd.optionsRaw?.get?.(long)) continue;
|
|
826
|
-
const handler = pnpmOptionHandlers[long];
|
|
827
|
-
if (handler) cmd.option(long, desc, handler, short);
|
|
828
|
-
else cmd.option(long, desc, short);
|
|
829
|
-
}
|
|
830
|
-
for (const [optionName, handler] of Object.entries(pnpmOptionHandlers)) if (!cmd.optionsRaw?.get?.(optionName)) {
|
|
831
|
-
if (extractValidValuesFromHelp(output, optionName).length > 0) cmd.option(optionName, " ", handler);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
async function setupPnpmCompletions(completion) {
|
|
835
|
-
try {
|
|
836
|
-
const commands = await getPnpmCommandsFromMainHelp();
|
|
837
|
-
for (const [command, description] of Object.entries(commands)) {
|
|
838
|
-
const c = completion.command(command, description);
|
|
839
|
-
setupCommandArguments(c, command, "pnpm");
|
|
840
|
-
setupLazyOptionLoading(c, command, "pnpm", loadPnpmOptionsSync);
|
|
841
|
-
}
|
|
842
|
-
} catch {}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
//#endregion
|
|
846
|
-
//#region bin/handlers/npm-handler.ts
|
|
847
|
-
const ALL_COMMANDS_RE = /^All commands:\s*$/i;
|
|
848
|
-
const OPTIONS_SECTION_RE$1 = /^Options:\s*$/i;
|
|
849
|
-
const SECTION_END_RE$2 = /^(aliases|run|more)/i;
|
|
850
|
-
const COMMAND_VALIDATION_RE$1 = /^[a-z][a-z0-9-]*$/;
|
|
851
|
-
const NPM_OPTION_RE = /(?:\[)?(?:-([a-z])\|)?--([a-z][a-z0-9-]+)(?:\s+<[^>]+>)?(?:\])?/gi;
|
|
852
|
-
const ANGLE_VALUE_RE = /<[^>]+>/;
|
|
853
|
-
const INDENTED_LINE_RE = /^\s/;
|
|
854
|
-
function toLines$2(helpText) {
|
|
855
|
-
return stripAnsiEscapes(helpText).split(/\r?\n/);
|
|
856
|
-
}
|
|
857
|
-
function readIndentedBlockAfter(lines, headerRe) {
|
|
858
|
-
const start = lines.findIndex((l) => headerRe.test(l.trim()));
|
|
859
|
-
if (start === -1) return "";
|
|
860
|
-
let buf = "";
|
|
861
|
-
for (let i = start + 1; i < lines.length; i++) {
|
|
862
|
-
const line = lines[i];
|
|
863
|
-
if (!INDENTED_LINE_RE.test(line) && line.trim() && !line.includes(",")) break;
|
|
864
|
-
if (INDENTED_LINE_RE.test(line)) buf += " " + line.trim();
|
|
865
|
-
}
|
|
866
|
-
return buf;
|
|
867
|
-
}
|
|
868
|
-
const listHandler = (values, describe = () => " ") => (complete) => values.forEach((v) => complete(v, describe(v)));
|
|
869
|
-
const npmOptionHandlers = {
|
|
870
|
-
...commonOptionHandlers,
|
|
871
|
-
loglevel: createLogLevelHandler([
|
|
872
|
-
"silent",
|
|
873
|
-
"error",
|
|
874
|
-
"warn",
|
|
875
|
-
"notice",
|
|
876
|
-
"http",
|
|
877
|
-
"info",
|
|
878
|
-
"verbose",
|
|
879
|
-
"silly"
|
|
880
|
-
]),
|
|
881
|
-
"install-strategy": listHandler([
|
|
882
|
-
"hoisted",
|
|
883
|
-
"nested",
|
|
884
|
-
"shallow",
|
|
885
|
-
"linked"
|
|
886
|
-
], () => " "),
|
|
887
|
-
omit: listHandler([
|
|
888
|
-
"dev",
|
|
889
|
-
"optional",
|
|
890
|
-
"peer"
|
|
891
|
-
], () => " "),
|
|
892
|
-
include: listHandler([
|
|
893
|
-
"prod",
|
|
894
|
-
"dev",
|
|
895
|
-
"optional",
|
|
896
|
-
"peer"
|
|
897
|
-
], () => " ")
|
|
898
|
-
};
|
|
899
|
-
function parseNpmHelp(helpText) {
|
|
900
|
-
const lines = toLines$2(helpText);
|
|
901
|
-
const commandsBlob = readIndentedBlockAfter(lines, ALL_COMMANDS_RE);
|
|
902
|
-
if (!commandsBlob) return {};
|
|
903
|
-
const commands = {};
|
|
904
|
-
commandsBlob.split(",").map((c) => c.trim()).filter((c) => c && COMMAND_VALIDATION_RE$1.test(c)).forEach((cmd) => {
|
|
905
|
-
commands[cmd] = " ";
|
|
906
|
-
});
|
|
907
|
-
commands["run"] = " ";
|
|
908
|
-
return commands;
|
|
909
|
-
}
|
|
910
|
-
async function getNpmCommandsFromMainHelp() {
|
|
911
|
-
const output = await safeExec("npm --help");
|
|
912
|
-
return output ? parseNpmHelp(output) : {};
|
|
913
|
-
}
|
|
914
|
-
function parseNpmOptions(helpText, { flagsOnly = true } = {}) {
|
|
915
|
-
const lines = toLines$2(helpText);
|
|
916
|
-
const start = lines.findIndex((l) => OPTIONS_SECTION_RE$1.test(l.trim()));
|
|
917
|
-
if (start === -1) return [];
|
|
918
|
-
const out = [];
|
|
919
|
-
for (const line of lines.slice(start + 1)) {
|
|
920
|
-
const trimmed = line.trim();
|
|
921
|
-
if (SECTION_END_RE$2.test(trimmed)) break;
|
|
922
|
-
const matches = line.matchAll(NPM_OPTION_RE);
|
|
923
|
-
for (const m of matches) {
|
|
924
|
-
const short = m[1] || void 0;
|
|
925
|
-
const long = m[2];
|
|
926
|
-
const takesValue = ANGLE_VALUE_RE.test(m[0]);
|
|
927
|
-
if (flagsOnly && takesValue) continue;
|
|
928
|
-
out.push({
|
|
929
|
-
short,
|
|
930
|
-
long,
|
|
931
|
-
desc: " "
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
return out;
|
|
936
|
-
}
|
|
937
|
-
function loadNpmOptionsSync(cmd, command) {
|
|
938
|
-
const output = safeExecSync(`npm ${command} --help`);
|
|
939
|
-
if (!output) return;
|
|
940
|
-
const allOptions = parseNpmOptions(output, { flagsOnly: false });
|
|
941
|
-
for (const { long, short, desc } of allOptions) {
|
|
942
|
-
if (cmd.optionsRaw?.get?.(long)) continue;
|
|
943
|
-
const handler = npmOptionHandlers[long];
|
|
944
|
-
if (handler) cmd.option(long, desc, handler, short);
|
|
945
|
-
else cmd.option(long, desc, short);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
async function setupNpmCompletions(completion) {
|
|
949
|
-
try {
|
|
950
|
-
const commands = await getNpmCommandsFromMainHelp();
|
|
951
|
-
for (const [command, description] of Object.entries(commands)) {
|
|
952
|
-
const c = completion.command(command, description);
|
|
953
|
-
setupCommandArguments(c, command, "npm");
|
|
954
|
-
setupLazyOptionLoading(c, command, "npm", loadNpmOptionsSync);
|
|
955
|
-
}
|
|
956
|
-
} catch {}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
//#endregion
|
|
960
|
-
//#region bin/handlers/yarn-handler.ts
|
|
961
|
-
const OPTIONS_SECTION_RE = /^\s*Options:\s*$/i;
|
|
962
|
-
const COMMANDS_SECTION_RE$1 = /^\s*Commands:\s*$/i;
|
|
963
|
-
const SECTION_END_RE$1 = /^(Run `yarn help|Visit https:\/\/)/i;
|
|
964
|
-
const LINE_SPLIT_RE$1 = /\r?\n/;
|
|
965
|
-
const YARN_OPTION_RE = /^\s*(?:-([a-zA-Z]),?\s*)?--([a-z][a-z0-9-]*)(?:\s+<[^>]+>|\s+\[[^\]]+\])?\s+(.+)$/;
|
|
966
|
-
const YARN_COMMAND_RE = /^\s*-\s+([a-z][a-z0-9-]*(?:\s*\/\s*[a-z][a-zA-Z]*)*)/;
|
|
967
|
-
function toLines$1(text) {
|
|
968
|
-
return stripAnsiEscapes(text).split(LINE_SPLIT_RE$1);
|
|
969
|
-
}
|
|
970
|
-
function findSectionStart$1(lines, header) {
|
|
971
|
-
for (let i = 0; i < lines.length; i++) if (header.test(lines[i].trim())) return i + 1;
|
|
972
|
-
return -1;
|
|
973
|
-
}
|
|
974
|
-
const yarnOptionHandlers = {
|
|
975
|
-
...commonOptionHandlers,
|
|
976
|
-
emoji(complete) {
|
|
977
|
-
complete("true", " ");
|
|
978
|
-
complete("false", " ");
|
|
979
|
-
},
|
|
980
|
-
production(complete) {
|
|
981
|
-
complete("true", " ");
|
|
982
|
-
complete("false", " ");
|
|
983
|
-
},
|
|
984
|
-
"scripts-prepend-node-path"(complete) {
|
|
985
|
-
complete("true", " ");
|
|
986
|
-
complete("false", " ");
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
function parseYarnHelp(helpText) {
|
|
990
|
-
const lines = toLines$1(helpText);
|
|
991
|
-
const commands = {};
|
|
992
|
-
const startIndex = findSectionStart$1(lines, COMMANDS_SECTION_RE$1);
|
|
993
|
-
if (startIndex === -1) return commands;
|
|
994
|
-
for (let i = startIndex; i < lines.length; i++) {
|
|
995
|
-
const line = lines[i];
|
|
996
|
-
if (SECTION_END_RE$1.test(line)) break;
|
|
997
|
-
if (!line.trim()) continue;
|
|
998
|
-
const match = line.match(YARN_COMMAND_RE);
|
|
999
|
-
if (match) {
|
|
1000
|
-
const [, commandWithAliases] = match;
|
|
1001
|
-
const commands_parts = commandWithAliases.split(/\s*\/\s*/);
|
|
1002
|
-
const mainCommand = commands_parts[0].trim();
|
|
1003
|
-
if (mainCommand) {
|
|
1004
|
-
commands[mainCommand] = "";
|
|
1005
|
-
for (let j = 1; j < commands_parts.length; j++) {
|
|
1006
|
-
const alias = commands_parts[j].trim();
|
|
1007
|
-
if (alias) commands[alias] = "";
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
return commands;
|
|
1013
|
-
}
|
|
1014
|
-
async function getYarnCommandsFromMainHelp() {
|
|
1015
|
-
const output = await safeExec("yarn --help");
|
|
1016
|
-
return output ? parseYarnHelp(output) : {};
|
|
1017
|
-
}
|
|
1018
|
-
function parseYarnOptions(helpText, { flagsOnly = true } = {}) {
|
|
1019
|
-
const lines = toLines$1(helpText);
|
|
1020
|
-
const out = [];
|
|
1021
|
-
const start = findSectionStart$1(lines, OPTIONS_SECTION_RE);
|
|
1022
|
-
if (start === -1) return out;
|
|
1023
|
-
for (let i = start; i < lines.length; i++) {
|
|
1024
|
-
const line = lines[i];
|
|
1025
|
-
if (SECTION_END_RE$1.test(line.trim())) break;
|
|
1026
|
-
const m = line.match(YARN_OPTION_RE);
|
|
1027
|
-
if (!m) continue;
|
|
1028
|
-
const [, short, long, desc] = m;
|
|
1029
|
-
const takesValue = line.includes("<") || line.includes("[");
|
|
1030
|
-
if (flagsOnly && takesValue) continue;
|
|
1031
|
-
out.push({
|
|
1032
|
-
short: short || void 0,
|
|
1033
|
-
long,
|
|
1034
|
-
desc: desc.trim()
|
|
1035
|
-
});
|
|
1036
|
-
}
|
|
1037
|
-
return out;
|
|
1038
|
-
}
|
|
1039
|
-
function loadYarnOptionsSync(cmd, command) {
|
|
1040
|
-
const output = safeExecSync(`yarn ${command} --help`);
|
|
1041
|
-
if (!output) return;
|
|
1042
|
-
const options = parseYarnOptions(output, { flagsOnly: false });
|
|
1043
|
-
for (const { long, short, desc } of options) {
|
|
1044
|
-
if (cmd.optionsRaw?.get?.(long)) continue;
|
|
1045
|
-
const handler = yarnOptionHandlers[long];
|
|
1046
|
-
if (handler) cmd.option(long, desc, handler, short);
|
|
1047
|
-
else cmd.option(long, desc, short);
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
async function setupYarnCompletions(completion) {
|
|
1051
|
-
try {
|
|
1052
|
-
const commands = await getYarnCommandsFromMainHelp();
|
|
1053
|
-
for (const [command, description] of Object.entries(commands)) {
|
|
1054
|
-
const c = completion.command(command, description);
|
|
1055
|
-
setupCommandArguments(c, command, "yarn");
|
|
1056
|
-
setupLazyOptionLoading(c, command, "yarn", loadYarnOptionsSync);
|
|
1057
|
-
}
|
|
1058
|
-
} catch {}
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
//#endregion
|
|
1062
|
-
//#region bin/handlers/bun-handler.ts
|
|
1063
|
-
const COMMANDS_SECTION_RE = /^Commands:\s*$/i;
|
|
1064
|
-
const FLAGS_SECTION_RE = /^Flags:\s*$/i;
|
|
1065
|
-
const SECTION_END_RE = /^(Examples|Full documentation|Learn more)/i;
|
|
1066
|
-
const COMMAND_VALIDATION_RE = /^[a-z][a-z0-9-]*$/;
|
|
1067
|
-
const BUN_OPTION_RE = /^\s*(?:-([a-zA-Z]),?\s*)?--([a-z][a-z0-9-]*)(?:=<[^>]+>)?\s+(.+)$/;
|
|
1068
|
-
const MAIN_COMMAND_RE = /^ ([a-z][a-z0-9-]*)\s+(.+)$/;
|
|
1069
|
-
const CONTINUATION_COMMAND_RE = /^\s{12,}([a-z][a-z0-9-]*)\s+(.+)$/;
|
|
1070
|
-
const EMPTY_LINE_FOLLOWED_BY_NON_COMMAND_RE = /^\s+[a-z]/;
|
|
1071
|
-
const DESCRIPTION_SPLIT_RE = /\s{2,}/;
|
|
1072
|
-
const CAPITAL_LETTER_START_RE = /^[A-Z]/;
|
|
1073
|
-
const LINE_SPLIT_RE = /\r?\n/;
|
|
1074
|
-
function toLines(text) {
|
|
1075
|
-
return stripAnsiEscapes(text).split(LINE_SPLIT_RE);
|
|
1076
|
-
}
|
|
1077
|
-
function findSectionStart(lines, header) {
|
|
1078
|
-
for (let i = 0; i < lines.length; i++) if (header.test(lines[i].trim())) return i + 1;
|
|
1079
|
-
return -1;
|
|
1080
|
-
}
|
|
1081
|
-
const bunOptionHandlers = {
|
|
1082
|
-
...commonOptionHandlers,
|
|
1083
|
-
backend(complete) {
|
|
1084
|
-
complete("clonefile", " ");
|
|
1085
|
-
complete("hardlink", " ");
|
|
1086
|
-
complete("symlink", " ");
|
|
1087
|
-
complete("copyfile", " ");
|
|
1088
|
-
},
|
|
1089
|
-
linker(complete) {
|
|
1090
|
-
complete("isolated", " ");
|
|
1091
|
-
complete("hoisted", " ");
|
|
1092
|
-
},
|
|
1093
|
-
omit(complete) {
|
|
1094
|
-
complete("dev", " ");
|
|
1095
|
-
complete("optional", " ");
|
|
1096
|
-
complete("peer", " ");
|
|
1097
|
-
},
|
|
1098
|
-
shell(complete) {
|
|
1099
|
-
complete("bun", " ");
|
|
1100
|
-
complete("system", " ");
|
|
1101
|
-
},
|
|
1102
|
-
"unhandled-rejections"(complete) {
|
|
1103
|
-
complete("strict", " ");
|
|
1104
|
-
complete("throw", " ");
|
|
1105
|
-
complete("warn", " ");
|
|
1106
|
-
complete("none", " ");
|
|
1107
|
-
complete("warn-with-error-code", " ");
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
function parseBunHelp(helpText) {
|
|
1111
|
-
const lines = toLines(helpText);
|
|
1112
|
-
const startIndex = findSectionStart(lines, COMMANDS_SECTION_RE);
|
|
1113
|
-
if (startIndex === -1) return {};
|
|
1114
|
-
const commands = {};
|
|
1115
|
-
for (let i = startIndex; i < lines.length; i++) {
|
|
1116
|
-
const line = lines[i];
|
|
1117
|
-
if (FLAGS_SECTION_RE.test(line.trim()) || line.trim() === "" && i + 1 < lines.length && !lines[i + 1].match(EMPTY_LINE_FOLLOWED_BY_NON_COMMAND_RE)) break;
|
|
1118
|
-
if (!line.trim()) continue;
|
|
1119
|
-
const main$1 = line.match(MAIN_COMMAND_RE);
|
|
1120
|
-
if (main$1) {
|
|
1121
|
-
const [, command, rest] = main$1;
|
|
1122
|
-
if (COMMAND_VALIDATION_RE.test(command)) {
|
|
1123
|
-
const parts = rest.split(DESCRIPTION_SPLIT_RE);
|
|
1124
|
-
let desc = parts[parts.length - 1];
|
|
1125
|
-
if (desc && CAPITAL_LETTER_START_RE.test(desc)) commands[command] = desc.trim();
|
|
1126
|
-
else if (parts.length > 1) {
|
|
1127
|
-
for (const p of parts) if (CAPITAL_LETTER_START_RE.test(p)) {
|
|
1128
|
-
commands[command] = p.trim();
|
|
1129
|
-
break;
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
const cont = line.match(CONTINUATION_COMMAND_RE);
|
|
1135
|
-
if (cont) {
|
|
1136
|
-
const [, command, description] = cont;
|
|
1137
|
-
if (COMMAND_VALIDATION_RE.test(command)) commands[command] = description.trim();
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
return commands;
|
|
1141
|
-
}
|
|
1142
|
-
async function getBunCommandsFromMainHelp() {
|
|
1143
|
-
const output = await safeExec("bun --help");
|
|
1144
|
-
return output ? parseBunHelp(output) : {};
|
|
1145
|
-
}
|
|
1146
|
-
function parseBunOptions(helpText, { flagsOnly = true } = {}) {
|
|
1147
|
-
const lines = toLines(helpText);
|
|
1148
|
-
const out = [];
|
|
1149
|
-
const start = findSectionStart(lines, FLAGS_SECTION_RE);
|
|
1150
|
-
if (start === -1) return out;
|
|
1151
|
-
for (let i = start; i < lines.length; i++) {
|
|
1152
|
-
const line = lines[i];
|
|
1153
|
-
if (SECTION_END_RE.test(line.trim())) break;
|
|
1154
|
-
const m = line.match(BUN_OPTION_RE);
|
|
1155
|
-
if (!m) continue;
|
|
1156
|
-
const [, short, long, desc] = m;
|
|
1157
|
-
const takesValue = line.includes("=<");
|
|
1158
|
-
if (flagsOnly && takesValue) continue;
|
|
1159
|
-
out.push({
|
|
1160
|
-
short: short || void 0,
|
|
1161
|
-
long,
|
|
1162
|
-
desc: desc.trim()
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
return out;
|
|
1166
|
-
}
|
|
1167
|
-
function loadBunOptionsSync(cmd, command) {
|
|
1168
|
-
const output = safeExecSync(`bun ${command} --help`);
|
|
1169
|
-
if (!output) return;
|
|
1170
|
-
const options = parseBunOptions(output, { flagsOnly: false });
|
|
1171
|
-
for (const { long, short, desc } of options) {
|
|
1172
|
-
if (cmd.optionsRaw?.get?.(long)) continue;
|
|
1173
|
-
const handler = bunOptionHandlers[long];
|
|
1174
|
-
if (handler) cmd.option(long, desc, handler, short);
|
|
1175
|
-
else cmd.option(long, desc, short);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
async function setupBunCompletions(completion) {
|
|
1179
|
-
try {
|
|
1180
|
-
const commands = await getBunCommandsFromMainHelp();
|
|
1181
|
-
for (const [command, description] of Object.entries(commands)) {
|
|
1182
|
-
const c = completion.command(command, description);
|
|
1183
|
-
setupCommandArguments(c, command, "bun");
|
|
1184
|
-
setupLazyOptionLoading(c, command, "bun", loadBunOptionsSync);
|
|
1185
|
-
}
|
|
1186
|
-
} catch {}
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
//#endregion
|
|
1190
|
-
//#region bin/completion-handlers.ts
|
|
1191
|
-
async function setupCompletionForPackageManager(packageManager, completion) {
|
|
1192
|
-
switch (packageManager) {
|
|
1193
|
-
case "pnpm":
|
|
1194
|
-
await setupPnpmCompletions(completion);
|
|
1195
|
-
break;
|
|
1196
|
-
case "npm":
|
|
1197
|
-
await setupNpmCompletions(completion);
|
|
1198
|
-
break;
|
|
1199
|
-
case "yarn":
|
|
1200
|
-
await setupYarnCompletions(completion);
|
|
1201
|
-
break;
|
|
1202
|
-
case "bun":
|
|
1203
|
-
await setupBunCompletions(completion);
|
|
1204
|
-
break;
|
|
1205
|
-
default: break;
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
//#endregion
|
|
1210
|
-
//#region bin/package-manager-completion.ts
|
|
1211
|
-
function debugLog(...args) {
|
|
1212
|
-
if (process.env.DEBUG) console.error("[DEBUG]", ...args);
|
|
1213
|
-
}
|
|
1214
|
-
async function checkCliHasCompletions(cliName, packageManager) {
|
|
1215
|
-
try {
|
|
1216
|
-
debugLog(`Checking if ${cliName} has completions via ${packageManager}`);
|
|
1217
|
-
const command = `${packageManager} ${cliName} complete --`;
|
|
1218
|
-
const hasCompletions = !!execSync(command, {
|
|
1219
|
-
encoding: "utf8",
|
|
1220
|
-
stdio: [
|
|
1221
|
-
"pipe",
|
|
1222
|
-
"pipe",
|
|
1223
|
-
"ignore"
|
|
1224
|
-
],
|
|
1225
|
-
timeout: 1e3
|
|
1226
|
-
}).trim();
|
|
1227
|
-
debugLog(`${cliName} supports completions: ${hasCompletions}`);
|
|
1228
|
-
return hasCompletions;
|
|
1229
|
-
} catch (error) {
|
|
1230
|
-
debugLog(`Error checking completions for ${cliName}:`, error);
|
|
1231
|
-
return false;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
async function getCliCompletions(cliName, packageManager, args) {
|
|
1235
|
-
try {
|
|
1236
|
-
const completeArgs = args.map((arg) => arg.includes(" ") ? `"${arg}"` : arg);
|
|
1237
|
-
const completeCommand = `${packageManager} ${cliName} complete -- ${completeArgs.join(" ")}`;
|
|
1238
|
-
debugLog(`Getting completions with command: ${completeCommand}`);
|
|
1239
|
-
const completions = execSync(completeCommand, {
|
|
1240
|
-
encoding: "utf8",
|
|
1241
|
-
stdio: [
|
|
1242
|
-
"pipe",
|
|
1243
|
-
"pipe",
|
|
1244
|
-
"ignore"
|
|
1245
|
-
],
|
|
1246
|
-
timeout: 1e3
|
|
1247
|
-
}).trim().split("\n").filter(Boolean);
|
|
1248
|
-
debugLog(`Got ${completions.length} completions from ${cliName}`);
|
|
1249
|
-
return completions;
|
|
1250
|
-
} catch (error) {
|
|
1251
|
-
debugLog(`Error getting completions from ${cliName}:`, error);
|
|
1252
|
-
return [];
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
/**
|
|
1256
|
-
* Package Manager Completion Wrapper
|
|
1257
|
-
*
|
|
1258
|
-
* This extends RootCommand and adds package manager-specific logic.
|
|
1259
|
-
* It acts as a layer on top of the core tab library.
|
|
1260
|
-
*/
|
|
1261
|
-
var PackageManagerCompletion = class extends RootCommand {
|
|
1262
|
-
packageManager;
|
|
1263
|
-
constructor(packageManager) {
|
|
1264
|
-
super();
|
|
1265
|
-
this.packageManager = packageManager;
|
|
1266
|
-
}
|
|
1267
|
-
async parse(args) {
|
|
1268
|
-
if (args.length >= 1 && args[0].trim() !== "") {
|
|
1269
|
-
const potentialCliName = args[0];
|
|
1270
|
-
if (![...this.commands.keys()].includes(potentialCliName)) {
|
|
1271
|
-
if (await checkCliHasCompletions(potentialCliName, this.packageManager)) {
|
|
1272
|
-
const cliArgs = args.slice(1);
|
|
1273
|
-
const suggestions = await getCliCompletions(potentialCliName, this.packageManager, cliArgs);
|
|
1274
|
-
if (suggestions.length > 0) {
|
|
1275
|
-
for (const suggestion of suggestions) {
|
|
1276
|
-
if (suggestion.startsWith(":")) continue;
|
|
1277
|
-
if (suggestion.includes(" ")) {
|
|
1278
|
-
const [value, description] = suggestion.split(" ");
|
|
1279
|
-
console.log(`${value}\t${description}`);
|
|
1280
|
-
} else console.log(suggestion);
|
|
1281
|
-
}
|
|
1282
|
-
console.log(":4");
|
|
1283
|
-
return;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
return super.parse(args);
|
|
1289
|
-
}
|
|
1290
|
-
};
|
|
1291
|
-
|
|
1292
|
-
//#endregion
|
|
1293
|
-
//#region bin/cli.ts
|
|
1294
|
-
const packageManagers = [
|
|
1295
|
-
"npm",
|
|
1296
|
-
"pnpm",
|
|
1297
|
-
"yarn",
|
|
1298
|
-
"bun"
|
|
1299
|
-
];
|
|
1300
|
-
const shells = [
|
|
1301
|
-
"zsh",
|
|
1302
|
-
"bash",
|
|
1303
|
-
"fish",
|
|
1304
|
-
"powershell"
|
|
1305
|
-
];
|
|
1306
|
-
async function main() {
|
|
1307
|
-
const cli = dist_default("tab");
|
|
1308
|
-
const args = process.argv.slice(2);
|
|
1309
|
-
if (args.length >= 2 && args[1] === "complete") {
|
|
1310
|
-
const packageManager = args[0];
|
|
1311
|
-
if (!packageManagers.includes(packageManager)) {
|
|
1312
|
-
console.error(`Error: Unsupported package manager "${packageManager}"`);
|
|
1313
|
-
console.error(`Supported package managers: ${packageManagers.join(", ")}`);
|
|
1314
|
-
process.exit(1);
|
|
1315
|
-
}
|
|
1316
|
-
const dashIndex = process.argv.indexOf("--");
|
|
1317
|
-
if (dashIndex !== -1) {
|
|
1318
|
-
const completion = new PackageManagerCompletion(packageManager);
|
|
1319
|
-
await setupCompletionForPackageManager(packageManager, completion);
|
|
1320
|
-
const toComplete = process.argv.slice(dashIndex + 1);
|
|
1321
|
-
await completion.parse(toComplete);
|
|
1322
|
-
process.exit(0);
|
|
1323
|
-
} else {
|
|
1324
|
-
console.error(`Error: Expected '--' followed by command to complete`);
|
|
1325
|
-
console.error(`Example: ${packageManager} exec @bomb.sh/tab ${packageManager} complete -- command-to-complete`);
|
|
1326
|
-
process.exit(1);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
cli.command("<packageManager> <shell>", "Generate shell completion script for a package manager").action(async (packageManager, shell) => {
|
|
1330
|
-
if (!packageManagers.includes(packageManager)) {
|
|
1331
|
-
console.error(`Error: Unsupported package manager "${packageManager}"`);
|
|
1332
|
-
console.error(`Supported package managers: ${packageManagers.join(", ")}`);
|
|
1333
|
-
process.exit(1);
|
|
1334
|
-
}
|
|
1335
|
-
if (!shells.includes(shell)) {
|
|
1336
|
-
console.error(`Error: Unsupported shell "${shell}"`);
|
|
1337
|
-
console.error(`Supported shells: ${shells.join(", ")}`);
|
|
1338
|
-
process.exit(1);
|
|
1339
|
-
}
|
|
1340
|
-
generateCompletionScript(packageManager, shell);
|
|
1341
|
-
});
|
|
1342
|
-
tab(cli);
|
|
1343
|
-
cli.parse();
|
|
1344
|
-
}
|
|
1345
|
-
function generateCompletionScript(packageManager, shell) {
|
|
1346
|
-
const name = packageManager;
|
|
1347
|
-
const executable = `node ${process.argv[1]} ${packageManager}`;
|
|
1348
|
-
script(shell, name, executable);
|
|
1349
|
-
}
|
|
1350
|
-
main().catch(console.error);
|
|
1351
|
-
|
|
1352
|
-
//#endregion
|
|
1353
|
-
export { };
|
|
2
|
+
import{RootCommand as e,script as t}from"../t-BDEAdEmc.js";import"../shared-CDiJt0Dj.js";import{tab as n}from"../cac-NlDEuVbb.js";import r from"cac";import{readFileSync as i}from"node:fs";import{promisify as a}from"node:util";import o from"node:child_process";import{readFileSync as s}from"fs";import{execSync as c}from"child_process";function l(){try{let e;try{e=i(`pnpm-workspace.yaml`,`utf8`)}catch{e=i(`pnpm-workspace.yml`,`utf8`)}let t=e.match(/packages:\s*\n((?:\s*-\s*.+\n?)*)/);return t?t[1].split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(e=>e.startsWith(`-`)).map(e=>e.substring(1).trim()).filter(e=>e&&!e.startsWith(`#`)):[]}catch{return[]}}function ee(){try{let e=JSON.parse(s(`package.json`,`utf8`));return Object.keys(e.scripts||{})}catch{return[]}}function te(){try{let e=JSON.parse(s(`package.json`,`utf8`)),t={...e.dependencies,...e.devDependencies,...e.peerDependencies,...e.optionalDependencies};return Object.keys(t)}catch{return[]}}const ne=async e=>{ee().forEach(t=>{let n=t.replace(/:/g,`\\:`);e(n,` `)})},u=async e=>{te().forEach(t=>e(t,``))},re=a(o.exec),{execSync:ie}=o,d={workspace(e){l().forEach(t=>e(t,`Workspace pattern: ${t}`))}};function f(e,t,n,r){e._lazyCommand=t,e._optionsLoaded=!1;let i=e.options;e.optionsRaw=i,Object.defineProperty(e,`options`,{get(){return this._optionsLoaded||(this._optionsLoaded=!0,r(this,this._lazyCommand)),i},configurable:!0})}function p(e,t,n){[`remove`,`rm`,`uninstall`,`un`,`update`,`up`].includes(t)&&e.argument(`package`,u),[`run`,`run-script`].includes(t)&&e.argument(`script`,ne,!0)}async function m(e,t={}){try{let{stdout:n}=await re(e,{encoding:`utf8`,timeout:500,maxBuffer:4*1024*1024,...t});return n}catch(e){return e instanceof Error&&`stdout`in e?e.stdout:``}}function h(e,t={}){try{return ie(e,{encoding:`utf8`,timeout:500,...t})}catch(e){return e?.stdout?e.stdout:``}}function g(e){return t=>e.forEach(e=>t(e,` `))}const ae=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g,_=/^\s+([a-z][a-z\s,-]*?)\s{2,}(\S.*)$/i,v=/^\s*(?:-(?<short>[A-Za-z]),\s*)?--(?<long>[a-z0-9-]+)(?<val>\s+(?:<[^>]+>|\[[^\]]+\]))?\s{2,}(?<desc>\S.*)$/i,oe=/^\s*(?:-[A-Za-z],\s*)?--[a-z0-9-]+/i,y=e=>e.replace(ae,``),b=e=>(e.match(/^\s*/)||[``])[0].length,x=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),se=/^\s*Options:/i,ce=/(?:levels?|options?|values?)[^:]*:\s*([^.]+)/i,le=/\r?\n/,ue=/[,\s]+/,S=/^\s*(?:-\w,?\s*)?--(\w+(?:-\w+)*)\s+(\w+(?:-\w+)*)\s+(.+)$/,C=/^\s*-\w,?\s*--\w+(?:,\s*--(\w+(?:-\w+)*)\s+(\w+(?:-\w+)*))?\s+(.+)$/,w=/^\s{20,}/,T=/^\s*[A-Z][^:]*:\s*$/;function E(e){return y(e).split(le)}function de(e){let t=1/0;for(let n of e){let e=n.match(_);if(!e)continue;let r=n.indexOf(e[2]);r>=0&&r<t&&(t=r)}return t}function fe(e,t){let n=1/0;for(let r of e){let e=r.match(v);if(!e||t&&e.groups?.val)continue;let i=r.indexOf(e.groups.desc);i>=0&&i<n&&(n=i)}return n}function D(e,t){let n=E(e),r=[];for(let e=0;e<n.length;e++){let i=n[e],a=i.match(S);if(a){let[,i,o,s]=a;if(i===t){let t=s.trim(),i=e+1;for(;i<n.length;){let e=n[i],r=w.test(e),a=S.test(e)||C.test(e),o=!e.trim()||T.test(e);if(r&&!a&&!o)t+=` `+e.trim(),i++;else break}r.push({value:o,desc:t})}}let o=i.match(C);if(o){let[,i,a,s]=o;if(i===t&&a){let t=s.trim(),i=e+1;for(;i<n.length;){let e=n[i],r=w.test(e),a=S.test(e)||C.test(e),o=!e.trim()||T.test(e);if(r&&!a&&!o)t+=` `+e.trim(),i++;else break}r.push({value:a,desc:t})}}}if(r.length)return r;for(let e=0;e<n.length;e++){let r=n[e];if(r.includes(`--${t}`)||r.includes(`${t}:`))for(let t=e;t<Math.min(e+3,n.length);t++){let e=n[t].match(ce);if(e)return e[1].split(ue).map(e=>e.trim()).filter(e=>e&&!e.includes(`(`)&&!e.includes(`)`)).map(e=>({value:e,desc:`Log level: ${e}`}))}}return[]}const O={...d,loglevel(e){let t=D(h(`pnpm install --help`),`loglevel`);t.length?t.forEach(({value:t,desc:n})=>e(t,n)):g([`debug`,`info`,`warn`,`error`,`silent`])(e)},reporter(e){let t=D(h(`pnpm install --help`),`reporter`);t.length?t.forEach(({value:t,desc:n})=>e(t,n)):g([`default`,`append-only`,`ndjson`,`silent`])(e)},filter(e){e(`.`,`Current working directory`),e(`!<selector>`,`Exclude packages matching selector`),l().forEach(t=>{e(t,`Workspace pattern: ${t}`),e(`${t}...`,`Include dependencies of ${t}`)}),e(`@*/*`,`All scoped packages`),e(`...<pattern>`,`Include dependencies of pattern`),e(`<pattern>...`,`Include dependents of pattern`)}};function pe(e){let t=E(e),n=de(t);if(!Number.isFinite(n))return{};let r=null,i=new Map,a=()=>{if(!r)return;let e=r.desc.trim();for(let t of r.names)i.set(t,e);r=null};for(let e of t){if(se.test(e))break;let t=e.match(_);if(t){a(),r={names:x(t[1]),desc:t[2].trim()};continue}r&&b(e)>=n&&e.trim()&&(r.desc+=` `+e.trim())}return a(),Object.fromEntries(i)}async function k(){let e=await m(`pnpm --help`);return e?pe(e):{}}function A(e,{flagsOnly:t=!0}={}){let n=E(e),r=fe(n,t);if(!Number.isFinite(r))return[];let i=[],a=null,o=()=>{a&&=(a.desc=a.desc.trim(),i.push(a),null)};for(let e of n){let n=e.match(v);if(n){if(t&&n.groups?.val)continue;o(),a={short:n.groups?.short||void 0,long:n.groups.long,desc:n.groups.desc.trim()};continue}if(a){let t=b(e),n=oe.test(e);t>=r&&e.trim()&&!n&&(a.desc+=` `+e.trim())}}return o(),i}function j(e,t){let n=h(`pnpm ${t} --help`);if(!n)return;let r=A(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=O[t];r?e.option(t,i,r,n):e.option(t,i,n)}for(let[t,r]of Object.entries(O))e.optionsRaw?.get?.(t)||D(n,t).length>0&&e.option(t,` `,r)}async function M(e){try{let t=await k();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);p(t,n,`pnpm`),f(t,n,`pnpm`,j)}}catch{}}const N=/^All commands:\s*$/i,P=/^Options:\s*$/i,F=/^(aliases|run|more)/i,I=/^[a-z][a-z0-9-]*$/,L=/(?:\[)?(?:-([a-z])\|)?--([a-z][a-z0-9-]+)(?:\s+<[^>]+>)?(?:\])?/gi,R=/<[^>]+>/,z=/^\s/;function B(e){return y(e).split(/\r?\n/)}function me(e,t){let n=e.findIndex(e=>t.test(e.trim()));if(n===-1)return``;let r=``;for(let t=n+1;t<e.length;t++){let n=e[t];if(!z.test(n)&&n.trim()&&!n.includes(`,`))break;z.test(n)&&(r+=` `+n.trim())}return r}const V=(e,t=()=>` `)=>n=>e.forEach(e=>n(e,t(e))),he={...d,loglevel:g([`silent`,`error`,`warn`,`notice`,`http`,`info`,`verbose`,`silly`]),"install-strategy":V([`hoisted`,`nested`,`shallow`,`linked`],()=>` `),omit:V([`dev`,`optional`,`peer`],()=>` `),include:V([`prod`,`dev`,`optional`,`peer`],()=>` `)};function ge(e){let t=B(e),n=me(t,N);if(!n)return{};let r={};return n.split(`,`).map(e=>e.trim()).filter(e=>e&&I.test(e)).forEach(e=>{r[e]=` `}),r.run=` `,r}async function _e(){let e=await m(`npm --help`);return e?ge(e):{}}function ve(e,{flagsOnly:t=!0}={}){let n=B(e),r=n.findIndex(e=>P.test(e.trim()));if(r===-1)return[];let i=[];for(let e of n.slice(r+1)){let n=e.trim();if(F.test(n))break;let r=e.matchAll(L);for(let e of r){let n=e[1]||void 0,r=e[2],a=R.test(e[0]);if(t&&a)continue;i.push({short:n,long:r,desc:` `})}}return i}function ye(e,t){let n=h(`npm ${t} --help`);if(!n)return;let r=ve(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=he[t];r?e.option(t,i,r,n):e.option(t,i,n)}}async function be(e){try{let t=await _e();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);p(t,n,`npm`),f(t,n,`npm`,ye)}}catch{}}const xe=/^\s*Options:\s*$/i,Se=/^\s*Commands:\s*$/i,H=/^(Run `yarn help|Visit https:\/\/)/i,Ce=/\r?\n/,we=/^\s*(?:-([a-zA-Z]),?\s*)?--([a-z][a-z0-9-]*)(?:\s+<[^>]+>|\s+\[[^\]]+\])?\s+(.+)$/,Te=/^\s*-\s+([a-z][a-z0-9-]*(?:\s*\/\s*[a-z][a-zA-Z]*)*)/;function U(e){return y(e).split(Ce)}function W(e,t){for(let n=0;n<e.length;n++)if(t.test(e[n].trim()))return n+1;return-1}const Ee={...d,emoji(e){e(`true`,` `),e(`false`,` `)},production(e){e(`true`,` `),e(`false`,` `)},"scripts-prepend-node-path"(e){e(`true`,` `),e(`false`,` `)}};function De(e){let t=U(e),n={},r=W(t,Se);if(r===-1)return n;for(let e=r;e<t.length;e++){let r=t[e];if(H.test(r))break;if(!r.trim())continue;let i=r.match(Te);if(i){let[,e]=i,t=e.split(/\s*\/\s*/),r=t[0].trim();if(r){n[r]=``;for(let e=1;e<t.length;e++){let r=t[e].trim();r&&(n[r]=``)}}}}return n}async function Oe(){let e=await m(`yarn --help`);return e?De(e):{}}function ke(e,{flagsOnly:t=!0}={}){let n=U(e),r=[],i=W(n,xe);if(i===-1)return r;for(let e=i;e<n.length;e++){let i=n[e];if(H.test(i.trim()))break;let a=i.match(we);if(!a)continue;let[,o,s,c]=a,l=i.includes(`<`)||i.includes(`[`);t&&l||r.push({short:o||void 0,long:s,desc:c.trim()})}return r}function Ae(e,t){let n=h(`yarn ${t} --help`);if(!n)return;let r=ke(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=Ee[t];r?e.option(t,i,r,n):e.option(t,i,n)}}async function je(e){try{let t=await Oe();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);p(t,n,`yarn`),f(t,n,`yarn`,Ae)}}catch{}}const Me=/^Commands:\s*$/i,G=/^Flags:\s*$/i,Ne=/^(Examples|Full documentation|Learn more)/i,K=/^[a-z][a-z0-9-]*$/,Pe=/^\s*(?:-([a-zA-Z]),?\s*)?--([a-z][a-z0-9-]*)(?:=<[^>]+>)?\s+(.+)$/,Fe=/^ ([a-z][a-z0-9-]*)\s+(.+)$/,Ie=/^\s{12,}([a-z][a-z0-9-]*)\s+(.+)$/,Le=/^\s+[a-z]/,Re=/\s{2,}/,q=/^[A-Z]/,ze=/\r?\n/;function J(e){return y(e).split(ze)}function Y(e,t){for(let n=0;n<e.length;n++)if(t.test(e[n].trim()))return n+1;return-1}const Be={...d,backend(e){e(`clonefile`,` `),e(`hardlink`,` `),e(`symlink`,` `),e(`copyfile`,` `)},linker(e){e(`isolated`,` `),e(`hoisted`,` `)},omit(e){e(`dev`,` `),e(`optional`,` `),e(`peer`,` `)},shell(e){e(`bun`,` `),e(`system`,` `)},"unhandled-rejections"(e){e(`strict`,` `),e(`throw`,` `),e(`warn`,` `),e(`none`,` `),e(`warn-with-error-code`,` `)}};function Ve(e){let t=J(e),n=Y(t,Me);if(n===-1)return{};let r={};for(let e=n;e<t.length;e++){let n=t[e];if(G.test(n.trim())||n.trim()===``&&e+1<t.length&&!t[e+1].match(Le))break;if(!n.trim())continue;let i=n.match(Fe);if(i){let[,e,t]=i;if(K.test(e)){let n=t.split(Re),i=n[n.length-1];if(i&&q.test(i))r[e]=i.trim();else if(n.length>1){for(let t of n)if(q.test(t)){r[e]=t.trim();break}}}}let a=n.match(Ie);if(a){let[,e,t]=a;K.test(e)&&(r[e]=t.trim())}}return r}async function He(){let e=await m(`bun --help`);return e?Ve(e):{}}function Ue(e,{flagsOnly:t=!0}={}){let n=J(e),r=[],i=Y(n,G);if(i===-1)return r;for(let e=i;e<n.length;e++){let i=n[e];if(Ne.test(i.trim()))break;let a=i.match(Pe);if(!a)continue;let[,o,s,c]=a,l=i.includes(`=<`);t&&l||r.push({short:o||void 0,long:s,desc:c.trim()})}return r}function We(e,t){let n=h(`bun ${t} --help`);if(!n)return;let r=Ue(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=Be[t];r?e.option(t,i,r,n):e.option(t,i,n)}}async function X(e){try{let t=await He();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);p(t,n,`bun`),f(t,n,`bun`,We)}}catch{}}async function Ge(e,t){switch(e){case`pnpm`:await M(t);break;case`npm`:await be(t);break;case`yarn`:await je(t);break;case`bun`:await X(t);break;default:break}}function Z(...e){process.env.DEBUG&&console.error(`[DEBUG]`,...e)}async function Ke(e,t){try{Z(`Checking if ${e} has completions via ${t}`);let n=`${t} ${e} complete --`,r=!!c(n,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],timeout:1e3}).trim();return Z(`${e} supports completions: ${r}`),r}catch(t){return Z(`Error checking completions for ${e}:`,t),!1}}async function qe(e,t,n){try{let r=n.map(e=>e.includes(` `)?`"${e}"`:e),i=`${t} ${e} complete -- ${r.join(` `)}`;Z(`Getting completions with command: ${i}`);let a=c(i,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],timeout:1e3}).trim().split(`
|
|
4
|
+
`).filter(Boolean);return Z(`Got ${a.length} completions from ${e}`),a}catch(t){return Z(`Error getting completions from ${e}:`,t),[]}}var Je=class extends e{packageManager;constructor(e){super(),this.packageManager=e}async parse(e){if(e.length>=1&&e[0].trim()!==``){let t=e[0];if(![...this.commands.keys()].includes(t)&&await Ke(t,this.packageManager)){let n=e.slice(1),r=await qe(t,this.packageManager,n);if(r.length>0){for(let e of r){if(e.startsWith(`:`))continue;if(e.includes(` `)){let[t,n]=e.split(` `);console.log(`${t}\t${n}`)}else console.log(e)}console.log(`:4`);return}}}return super.parse(e)}};const Q=[`npm`,`pnpm`,`yarn`,`bun`],$=[`zsh`,`bash`,`fish`,`powershell`];async function Ye(){let e=r(`tab`),t=process.argv.slice(2);if(t.length>=2&&t[1]===`complete`){let e=t[0];Q.includes(e)||(console.error(`Error: Unsupported package manager "${e}"`),console.error(`Supported package managers: ${Q.join(`, `)}`),process.exit(1));let n=process.argv.indexOf(`--`);if(n!==-1){let t=new Je(e);await Ge(e,t);let r=process.argv.slice(n+1);await t.parse(r),process.exit(0)}else console.error(`Error: Expected '--' followed by command to complete`),console.error(`Example: ${e} exec @bomb.sh/tab ${e} complete -- command-to-complete`),process.exit(1)}e.command(`<packageManager> <shell>`,`Generate shell completion script for a package manager`).action(async(e,t)=>{Q.includes(e)||(console.error(`Error: Unsupported package manager "${e}"`),console.error(`Supported package managers: ${Q.join(`, `)}`),process.exit(1)),$.includes(t)||(console.error(`Error: Unsupported shell "${t}"`),console.error(`Supported shells: ${$.join(`, `)}`),process.exit(1)),Xe(e,t)}),n(e),e.parse()}function Xe(e,n){let r=e,i=`node ${process.argv[1]} ${e}`;t(n,r,i)}Ye().catch(console.error);export{};
|