@mstar-harness/cli 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mstar-harness.js +4727 -0
- package/package.json +35 -0
|
@@ -0,0 +1,4727 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
10
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
11
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
12
|
+
for (let key of __getOwnPropNames(mod))
|
|
13
|
+
if (!__hasOwnProp.call(to, key))
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => mod[key],
|
|
16
|
+
enumerable: true
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
21
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
22
|
+
|
|
23
|
+
// ../../node_modules/cli-width/index.js
|
|
24
|
+
var require_cli_width = __commonJS((exports, module) => {
|
|
25
|
+
module.exports = cliWidth;
|
|
26
|
+
function normalizeOpts(options) {
|
|
27
|
+
const defaultOpts = {
|
|
28
|
+
defaultWidth: 0,
|
|
29
|
+
output: process.stdout,
|
|
30
|
+
tty: __require("tty")
|
|
31
|
+
};
|
|
32
|
+
if (!options) {
|
|
33
|
+
return defaultOpts;
|
|
34
|
+
}
|
|
35
|
+
Object.keys(defaultOpts).forEach(function(key) {
|
|
36
|
+
if (!options[key]) {
|
|
37
|
+
options[key] = defaultOpts[key];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return options;
|
|
41
|
+
}
|
|
42
|
+
function cliWidth(options) {
|
|
43
|
+
const opts = normalizeOpts(options);
|
|
44
|
+
if (opts.output.getWindowSize) {
|
|
45
|
+
return opts.output.getWindowSize()[0] || opts.defaultWidth;
|
|
46
|
+
}
|
|
47
|
+
if (opts.tty.getWindowSize) {
|
|
48
|
+
return opts.tty.getWindowSize()[1] || opts.defaultWidth;
|
|
49
|
+
}
|
|
50
|
+
if (opts.output.columns) {
|
|
51
|
+
return opts.output.columns;
|
|
52
|
+
}
|
|
53
|
+
if (process.env.CLI_WIDTH) {
|
|
54
|
+
const width = parseInt(process.env.CLI_WIDTH, 10);
|
|
55
|
+
if (!isNaN(width) && width !== 0) {
|
|
56
|
+
return width;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return opts.defaultWidth;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// ../../node_modules/mute-stream/lib/index.js
|
|
64
|
+
var require_lib = __commonJS((exports, module) => {
|
|
65
|
+
var Stream = __require("stream");
|
|
66
|
+
|
|
67
|
+
class MuteStream extends Stream {
|
|
68
|
+
#isTTY = null;
|
|
69
|
+
constructor(opts = {}) {
|
|
70
|
+
super(opts);
|
|
71
|
+
this.writable = this.readable = true;
|
|
72
|
+
this.muted = false;
|
|
73
|
+
this.on("pipe", this._onpipe);
|
|
74
|
+
this.replace = opts.replace;
|
|
75
|
+
this._prompt = opts.prompt || null;
|
|
76
|
+
this._hadControl = false;
|
|
77
|
+
}
|
|
78
|
+
#destSrc(key, def) {
|
|
79
|
+
if (this._dest) {
|
|
80
|
+
return this._dest[key];
|
|
81
|
+
}
|
|
82
|
+
if (this._src) {
|
|
83
|
+
return this._src[key];
|
|
84
|
+
}
|
|
85
|
+
return def;
|
|
86
|
+
}
|
|
87
|
+
#proxy(method, ...args) {
|
|
88
|
+
if (typeof this._dest?.[method] === "function") {
|
|
89
|
+
this._dest[method](...args);
|
|
90
|
+
}
|
|
91
|
+
if (typeof this._src?.[method] === "function") {
|
|
92
|
+
this._src[method](...args);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
get isTTY() {
|
|
96
|
+
if (this.#isTTY !== null) {
|
|
97
|
+
return this.#isTTY;
|
|
98
|
+
}
|
|
99
|
+
return this.#destSrc("isTTY", false);
|
|
100
|
+
}
|
|
101
|
+
set isTTY(val) {
|
|
102
|
+
this.#isTTY = val;
|
|
103
|
+
}
|
|
104
|
+
get rows() {
|
|
105
|
+
return this.#destSrc("rows");
|
|
106
|
+
}
|
|
107
|
+
get columns() {
|
|
108
|
+
return this.#destSrc("columns");
|
|
109
|
+
}
|
|
110
|
+
mute() {
|
|
111
|
+
this.muted = true;
|
|
112
|
+
}
|
|
113
|
+
unmute() {
|
|
114
|
+
this.muted = false;
|
|
115
|
+
}
|
|
116
|
+
_onpipe(src) {
|
|
117
|
+
this._src = src;
|
|
118
|
+
}
|
|
119
|
+
pipe(dest, options) {
|
|
120
|
+
this._dest = dest;
|
|
121
|
+
return super.pipe(dest, options);
|
|
122
|
+
}
|
|
123
|
+
pause() {
|
|
124
|
+
if (this._src) {
|
|
125
|
+
return this._src.pause();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
resume() {
|
|
129
|
+
if (this._src) {
|
|
130
|
+
return this._src.resume();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
write(c) {
|
|
134
|
+
if (this.muted) {
|
|
135
|
+
if (!this.replace) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (c.match(/^\u001b/)) {
|
|
139
|
+
if (c.indexOf(this._prompt) === 0) {
|
|
140
|
+
c = c.slice(this._prompt.length);
|
|
141
|
+
c = c.replace(/./g, this.replace);
|
|
142
|
+
c = this._prompt + c;
|
|
143
|
+
}
|
|
144
|
+
this._hadControl = true;
|
|
145
|
+
return this.emit("data", c);
|
|
146
|
+
} else {
|
|
147
|
+
if (this._prompt && this._hadControl && c.indexOf(this._prompt) === 0) {
|
|
148
|
+
this._hadControl = false;
|
|
149
|
+
this.emit("data", this._prompt);
|
|
150
|
+
c = c.slice(this._prompt.length);
|
|
151
|
+
}
|
|
152
|
+
c = c.toString().replace(/./g, this.replace);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.emit("data", c);
|
|
156
|
+
}
|
|
157
|
+
end(c) {
|
|
158
|
+
if (this.muted) {
|
|
159
|
+
if (c && this.replace) {
|
|
160
|
+
c = c.toString().replace(/./g, this.replace);
|
|
161
|
+
} else {
|
|
162
|
+
c = null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (c) {
|
|
166
|
+
this.emit("data", c);
|
|
167
|
+
}
|
|
168
|
+
this.emit("end");
|
|
169
|
+
}
|
|
170
|
+
destroy(...args) {
|
|
171
|
+
return this.#proxy("destroy", ...args);
|
|
172
|
+
}
|
|
173
|
+
destroySoon(...args) {
|
|
174
|
+
return this.#proxy("destroySoon", ...args);
|
|
175
|
+
}
|
|
176
|
+
close(...args) {
|
|
177
|
+
return this.#proxy("close", ...args);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
module.exports = MuteStream;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ../../node_modules/picocolors/picocolors.js
|
|
184
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
185
|
+
var p = process || {};
|
|
186
|
+
var argv = p.argv || [];
|
|
187
|
+
var env = p.env || {};
|
|
188
|
+
var 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);
|
|
189
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
190
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
191
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
192
|
+
};
|
|
193
|
+
var replaceClose = (string, close, replace, index) => {
|
|
194
|
+
let result = "", cursor = 0;
|
|
195
|
+
do {
|
|
196
|
+
result += string.substring(cursor, index) + replace;
|
|
197
|
+
cursor = index + close.length;
|
|
198
|
+
index = string.indexOf(close, cursor);
|
|
199
|
+
} while (~index);
|
|
200
|
+
return result + string.substring(cursor);
|
|
201
|
+
};
|
|
202
|
+
var createColors = (enabled = isColorSupported) => {
|
|
203
|
+
let f = enabled ? formatter : () => String;
|
|
204
|
+
return {
|
|
205
|
+
isColorSupported: enabled,
|
|
206
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
207
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
208
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
209
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
210
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
211
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
212
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
213
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
214
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
215
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
216
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
217
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
218
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
219
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
220
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
221
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
222
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
223
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
224
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
225
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
226
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
227
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
228
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
229
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
230
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
231
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
232
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
233
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
234
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
235
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
236
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
237
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
238
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
239
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
240
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
241
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
242
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
243
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
244
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
245
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
246
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
module.exports = createColors();
|
|
250
|
+
module.exports.createColors = createColors;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// ../../node_modules/commander/lib/error.js
|
|
254
|
+
var require_error = __commonJS((exports) => {
|
|
255
|
+
class CommanderError extends Error {
|
|
256
|
+
constructor(exitCode, code, message) {
|
|
257
|
+
super(message);
|
|
258
|
+
Error.captureStackTrace(this, this.constructor);
|
|
259
|
+
this.name = this.constructor.name;
|
|
260
|
+
this.code = code;
|
|
261
|
+
this.exitCode = exitCode;
|
|
262
|
+
this.nestedError = undefined;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
class InvalidArgumentError extends CommanderError {
|
|
267
|
+
constructor(message) {
|
|
268
|
+
super(1, "commander.invalidArgument", message);
|
|
269
|
+
Error.captureStackTrace(this, this.constructor);
|
|
270
|
+
this.name = this.constructor.name;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.CommanderError = CommanderError;
|
|
274
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ../../node_modules/commander/lib/argument.js
|
|
278
|
+
var require_argument = __commonJS((exports) => {
|
|
279
|
+
var { InvalidArgumentError } = require_error();
|
|
280
|
+
|
|
281
|
+
class Argument {
|
|
282
|
+
constructor(name, description) {
|
|
283
|
+
this.description = description || "";
|
|
284
|
+
this.variadic = false;
|
|
285
|
+
this.parseArg = undefined;
|
|
286
|
+
this.defaultValue = undefined;
|
|
287
|
+
this.defaultValueDescription = undefined;
|
|
288
|
+
this.argChoices = undefined;
|
|
289
|
+
switch (name[0]) {
|
|
290
|
+
case "<":
|
|
291
|
+
this.required = true;
|
|
292
|
+
this._name = name.slice(1, -1);
|
|
293
|
+
break;
|
|
294
|
+
case "[":
|
|
295
|
+
this.required = false;
|
|
296
|
+
this._name = name.slice(1, -1);
|
|
297
|
+
break;
|
|
298
|
+
default:
|
|
299
|
+
this.required = true;
|
|
300
|
+
this._name = name;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
if (this._name.endsWith("...")) {
|
|
304
|
+
this.variadic = true;
|
|
305
|
+
this._name = this._name.slice(0, -3);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
name() {
|
|
309
|
+
return this._name;
|
|
310
|
+
}
|
|
311
|
+
_collectValue(value, previous) {
|
|
312
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
313
|
+
return [value];
|
|
314
|
+
}
|
|
315
|
+
previous.push(value);
|
|
316
|
+
return previous;
|
|
317
|
+
}
|
|
318
|
+
default(value, description) {
|
|
319
|
+
this.defaultValue = value;
|
|
320
|
+
this.defaultValueDescription = description;
|
|
321
|
+
return this;
|
|
322
|
+
}
|
|
323
|
+
argParser(fn) {
|
|
324
|
+
this.parseArg = fn;
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
327
|
+
choices(values) {
|
|
328
|
+
this.argChoices = values.slice();
|
|
329
|
+
this.parseArg = (arg, previous) => {
|
|
330
|
+
if (!this.argChoices.includes(arg)) {
|
|
331
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
332
|
+
}
|
|
333
|
+
if (this.variadic) {
|
|
334
|
+
return this._collectValue(arg, previous);
|
|
335
|
+
}
|
|
336
|
+
return arg;
|
|
337
|
+
};
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
argRequired() {
|
|
341
|
+
this.required = true;
|
|
342
|
+
return this;
|
|
343
|
+
}
|
|
344
|
+
argOptional() {
|
|
345
|
+
this.required = false;
|
|
346
|
+
return this;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function humanReadableArgName(arg) {
|
|
350
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
351
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
352
|
+
}
|
|
353
|
+
exports.Argument = Argument;
|
|
354
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// ../../node_modules/commander/lib/help.js
|
|
358
|
+
var require_help = __commonJS((exports) => {
|
|
359
|
+
var { humanReadableArgName } = require_argument();
|
|
360
|
+
|
|
361
|
+
class Help {
|
|
362
|
+
constructor() {
|
|
363
|
+
this.helpWidth = undefined;
|
|
364
|
+
this.minWidthToWrap = 40;
|
|
365
|
+
this.sortSubcommands = false;
|
|
366
|
+
this.sortOptions = false;
|
|
367
|
+
this.showGlobalOptions = false;
|
|
368
|
+
}
|
|
369
|
+
prepareContext(contextOptions) {
|
|
370
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
371
|
+
}
|
|
372
|
+
visibleCommands(cmd) {
|
|
373
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
374
|
+
const helpCommand = cmd._getHelpCommand();
|
|
375
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
376
|
+
visibleCommands.push(helpCommand);
|
|
377
|
+
}
|
|
378
|
+
if (this.sortSubcommands) {
|
|
379
|
+
visibleCommands.sort((a, b) => {
|
|
380
|
+
return a.name().localeCompare(b.name());
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return visibleCommands;
|
|
384
|
+
}
|
|
385
|
+
compareOptions(a, b) {
|
|
386
|
+
const getSortKey = (option) => {
|
|
387
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
388
|
+
};
|
|
389
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
390
|
+
}
|
|
391
|
+
visibleOptions(cmd) {
|
|
392
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
393
|
+
const helpOption = cmd._getHelpOption();
|
|
394
|
+
if (helpOption && !helpOption.hidden) {
|
|
395
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
396
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
397
|
+
if (!removeShort && !removeLong) {
|
|
398
|
+
visibleOptions.push(helpOption);
|
|
399
|
+
} else if (helpOption.long && !removeLong) {
|
|
400
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
401
|
+
} else if (helpOption.short && !removeShort) {
|
|
402
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (this.sortOptions) {
|
|
406
|
+
visibleOptions.sort(this.compareOptions);
|
|
407
|
+
}
|
|
408
|
+
return visibleOptions;
|
|
409
|
+
}
|
|
410
|
+
visibleGlobalOptions(cmd) {
|
|
411
|
+
if (!this.showGlobalOptions)
|
|
412
|
+
return [];
|
|
413
|
+
const globalOptions = [];
|
|
414
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
415
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
416
|
+
globalOptions.push(...visibleOptions);
|
|
417
|
+
}
|
|
418
|
+
if (this.sortOptions) {
|
|
419
|
+
globalOptions.sort(this.compareOptions);
|
|
420
|
+
}
|
|
421
|
+
return globalOptions;
|
|
422
|
+
}
|
|
423
|
+
visibleArguments(cmd) {
|
|
424
|
+
if (cmd._argsDescription) {
|
|
425
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
426
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
430
|
+
return cmd.registeredArguments;
|
|
431
|
+
}
|
|
432
|
+
return [];
|
|
433
|
+
}
|
|
434
|
+
subcommandTerm(cmd) {
|
|
435
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
436
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
437
|
+
}
|
|
438
|
+
optionTerm(option) {
|
|
439
|
+
return option.flags;
|
|
440
|
+
}
|
|
441
|
+
argumentTerm(argument) {
|
|
442
|
+
return argument.name();
|
|
443
|
+
}
|
|
444
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
445
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
446
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
447
|
+
}, 0);
|
|
448
|
+
}
|
|
449
|
+
longestOptionTermLength(cmd, helper) {
|
|
450
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
451
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
452
|
+
}, 0);
|
|
453
|
+
}
|
|
454
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
455
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
456
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
457
|
+
}, 0);
|
|
458
|
+
}
|
|
459
|
+
longestArgumentTermLength(cmd, helper) {
|
|
460
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
461
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
462
|
+
}, 0);
|
|
463
|
+
}
|
|
464
|
+
commandUsage(cmd) {
|
|
465
|
+
let cmdName = cmd._name;
|
|
466
|
+
if (cmd._aliases[0]) {
|
|
467
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
468
|
+
}
|
|
469
|
+
let ancestorCmdNames = "";
|
|
470
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
471
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
472
|
+
}
|
|
473
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
474
|
+
}
|
|
475
|
+
commandDescription(cmd) {
|
|
476
|
+
return cmd.description();
|
|
477
|
+
}
|
|
478
|
+
subcommandDescription(cmd) {
|
|
479
|
+
return cmd.summary() || cmd.description();
|
|
480
|
+
}
|
|
481
|
+
optionDescription(option) {
|
|
482
|
+
const extraInfo = [];
|
|
483
|
+
if (option.argChoices) {
|
|
484
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
485
|
+
}
|
|
486
|
+
if (option.defaultValue !== undefined) {
|
|
487
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
488
|
+
if (showDefault) {
|
|
489
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
493
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
494
|
+
}
|
|
495
|
+
if (option.envVar !== undefined) {
|
|
496
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
497
|
+
}
|
|
498
|
+
if (extraInfo.length > 0) {
|
|
499
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
500
|
+
if (option.description) {
|
|
501
|
+
return `${option.description} ${extraDescription}`;
|
|
502
|
+
}
|
|
503
|
+
return extraDescription;
|
|
504
|
+
}
|
|
505
|
+
return option.description;
|
|
506
|
+
}
|
|
507
|
+
argumentDescription(argument) {
|
|
508
|
+
const extraInfo = [];
|
|
509
|
+
if (argument.argChoices) {
|
|
510
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
511
|
+
}
|
|
512
|
+
if (argument.defaultValue !== undefined) {
|
|
513
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
514
|
+
}
|
|
515
|
+
if (extraInfo.length > 0) {
|
|
516
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
517
|
+
if (argument.description) {
|
|
518
|
+
return `${argument.description} ${extraDescription}`;
|
|
519
|
+
}
|
|
520
|
+
return extraDescription;
|
|
521
|
+
}
|
|
522
|
+
return argument.description;
|
|
523
|
+
}
|
|
524
|
+
formatItemList(heading, items, helper) {
|
|
525
|
+
if (items.length === 0)
|
|
526
|
+
return [];
|
|
527
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
528
|
+
}
|
|
529
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
530
|
+
const result = new Map;
|
|
531
|
+
unsortedItems.forEach((item) => {
|
|
532
|
+
const group = getGroup(item);
|
|
533
|
+
if (!result.has(group))
|
|
534
|
+
result.set(group, []);
|
|
535
|
+
});
|
|
536
|
+
visibleItems.forEach((item) => {
|
|
537
|
+
const group = getGroup(item);
|
|
538
|
+
if (!result.has(group)) {
|
|
539
|
+
result.set(group, []);
|
|
540
|
+
}
|
|
541
|
+
result.get(group).push(item);
|
|
542
|
+
});
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
formatHelp(cmd, helper) {
|
|
546
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
547
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
548
|
+
function callFormatItem(term, description) {
|
|
549
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
550
|
+
}
|
|
551
|
+
let output = [
|
|
552
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
553
|
+
""
|
|
554
|
+
];
|
|
555
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
556
|
+
if (commandDescription.length > 0) {
|
|
557
|
+
output = output.concat([
|
|
558
|
+
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
559
|
+
""
|
|
560
|
+
]);
|
|
561
|
+
}
|
|
562
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
563
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
564
|
+
});
|
|
565
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
566
|
+
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
|
|
567
|
+
optionGroups.forEach((options, group) => {
|
|
568
|
+
const optionList = options.map((option) => {
|
|
569
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
570
|
+
});
|
|
571
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
572
|
+
});
|
|
573
|
+
if (helper.showGlobalOptions) {
|
|
574
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
575
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
576
|
+
});
|
|
577
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
578
|
+
}
|
|
579
|
+
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
|
|
580
|
+
commandGroups.forEach((commands, group) => {
|
|
581
|
+
const commandList = commands.map((sub) => {
|
|
582
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
583
|
+
});
|
|
584
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
585
|
+
});
|
|
586
|
+
return output.join(`
|
|
587
|
+
`);
|
|
588
|
+
}
|
|
589
|
+
displayWidth(str) {
|
|
590
|
+
return stripColor(str).length;
|
|
591
|
+
}
|
|
592
|
+
styleTitle(str) {
|
|
593
|
+
return str;
|
|
594
|
+
}
|
|
595
|
+
styleUsage(str) {
|
|
596
|
+
return str.split(" ").map((word) => {
|
|
597
|
+
if (word === "[options]")
|
|
598
|
+
return this.styleOptionText(word);
|
|
599
|
+
if (word === "[command]")
|
|
600
|
+
return this.styleSubcommandText(word);
|
|
601
|
+
if (word[0] === "[" || word[0] === "<")
|
|
602
|
+
return this.styleArgumentText(word);
|
|
603
|
+
return this.styleCommandText(word);
|
|
604
|
+
}).join(" ");
|
|
605
|
+
}
|
|
606
|
+
styleCommandDescription(str) {
|
|
607
|
+
return this.styleDescriptionText(str);
|
|
608
|
+
}
|
|
609
|
+
styleOptionDescription(str) {
|
|
610
|
+
return this.styleDescriptionText(str);
|
|
611
|
+
}
|
|
612
|
+
styleSubcommandDescription(str) {
|
|
613
|
+
return this.styleDescriptionText(str);
|
|
614
|
+
}
|
|
615
|
+
styleArgumentDescription(str) {
|
|
616
|
+
return this.styleDescriptionText(str);
|
|
617
|
+
}
|
|
618
|
+
styleDescriptionText(str) {
|
|
619
|
+
return str;
|
|
620
|
+
}
|
|
621
|
+
styleOptionTerm(str) {
|
|
622
|
+
return this.styleOptionText(str);
|
|
623
|
+
}
|
|
624
|
+
styleSubcommandTerm(str) {
|
|
625
|
+
return str.split(" ").map((word) => {
|
|
626
|
+
if (word === "[options]")
|
|
627
|
+
return this.styleOptionText(word);
|
|
628
|
+
if (word[0] === "[" || word[0] === "<")
|
|
629
|
+
return this.styleArgumentText(word);
|
|
630
|
+
return this.styleSubcommandText(word);
|
|
631
|
+
}).join(" ");
|
|
632
|
+
}
|
|
633
|
+
styleArgumentTerm(str) {
|
|
634
|
+
return this.styleArgumentText(str);
|
|
635
|
+
}
|
|
636
|
+
styleOptionText(str) {
|
|
637
|
+
return str;
|
|
638
|
+
}
|
|
639
|
+
styleArgumentText(str) {
|
|
640
|
+
return str;
|
|
641
|
+
}
|
|
642
|
+
styleSubcommandText(str) {
|
|
643
|
+
return str;
|
|
644
|
+
}
|
|
645
|
+
styleCommandText(str) {
|
|
646
|
+
return str;
|
|
647
|
+
}
|
|
648
|
+
padWidth(cmd, helper) {
|
|
649
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
650
|
+
}
|
|
651
|
+
preformatted(str) {
|
|
652
|
+
return /\n[^\S\r\n]/.test(str);
|
|
653
|
+
}
|
|
654
|
+
formatItem(term, termWidth, description, helper) {
|
|
655
|
+
const itemIndent = 2;
|
|
656
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
657
|
+
if (!description)
|
|
658
|
+
return itemIndentStr + term;
|
|
659
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
660
|
+
const spacerWidth = 2;
|
|
661
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
662
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
663
|
+
let formattedDescription;
|
|
664
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
665
|
+
formattedDescription = description;
|
|
666
|
+
} else {
|
|
667
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
668
|
+
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
669
|
+
` + " ".repeat(termWidth + spacerWidth));
|
|
670
|
+
}
|
|
671
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
672
|
+
${itemIndentStr}`);
|
|
673
|
+
}
|
|
674
|
+
boxWrap(str, width) {
|
|
675
|
+
if (width < this.minWidthToWrap)
|
|
676
|
+
return str;
|
|
677
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
678
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
679
|
+
const wrappedLines = [];
|
|
680
|
+
rawLines.forEach((line) => {
|
|
681
|
+
const chunks = line.match(chunkPattern);
|
|
682
|
+
if (chunks === null) {
|
|
683
|
+
wrappedLines.push("");
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
let sumChunks = [chunks.shift()];
|
|
687
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
688
|
+
chunks.forEach((chunk) => {
|
|
689
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
690
|
+
if (sumWidth + visibleWidth <= width) {
|
|
691
|
+
sumChunks.push(chunk);
|
|
692
|
+
sumWidth += visibleWidth;
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
wrappedLines.push(sumChunks.join(""));
|
|
696
|
+
const nextChunk = chunk.trimStart();
|
|
697
|
+
sumChunks = [nextChunk];
|
|
698
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
699
|
+
});
|
|
700
|
+
wrappedLines.push(sumChunks.join(""));
|
|
701
|
+
});
|
|
702
|
+
return wrappedLines.join(`
|
|
703
|
+
`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function stripColor(str) {
|
|
707
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
708
|
+
return str.replace(sgrPattern, "");
|
|
709
|
+
}
|
|
710
|
+
exports.Help = Help;
|
|
711
|
+
exports.stripColor = stripColor;
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
// ../../node_modules/commander/lib/option.js
|
|
715
|
+
var require_option = __commonJS((exports) => {
|
|
716
|
+
var { InvalidArgumentError } = require_error();
|
|
717
|
+
|
|
718
|
+
class Option {
|
|
719
|
+
constructor(flags, description) {
|
|
720
|
+
this.flags = flags;
|
|
721
|
+
this.description = description || "";
|
|
722
|
+
this.required = flags.includes("<");
|
|
723
|
+
this.optional = flags.includes("[");
|
|
724
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
725
|
+
this.mandatory = false;
|
|
726
|
+
const optionFlags = splitOptionFlags(flags);
|
|
727
|
+
this.short = optionFlags.shortFlag;
|
|
728
|
+
this.long = optionFlags.longFlag;
|
|
729
|
+
this.negate = false;
|
|
730
|
+
if (this.long) {
|
|
731
|
+
this.negate = this.long.startsWith("--no-");
|
|
732
|
+
}
|
|
733
|
+
this.defaultValue = undefined;
|
|
734
|
+
this.defaultValueDescription = undefined;
|
|
735
|
+
this.presetArg = undefined;
|
|
736
|
+
this.envVar = undefined;
|
|
737
|
+
this.parseArg = undefined;
|
|
738
|
+
this.hidden = false;
|
|
739
|
+
this.argChoices = undefined;
|
|
740
|
+
this.conflictsWith = [];
|
|
741
|
+
this.implied = undefined;
|
|
742
|
+
this.helpGroupHeading = undefined;
|
|
743
|
+
}
|
|
744
|
+
default(value, description) {
|
|
745
|
+
this.defaultValue = value;
|
|
746
|
+
this.defaultValueDescription = description;
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
preset(arg) {
|
|
750
|
+
this.presetArg = arg;
|
|
751
|
+
return this;
|
|
752
|
+
}
|
|
753
|
+
conflicts(names) {
|
|
754
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
755
|
+
return this;
|
|
756
|
+
}
|
|
757
|
+
implies(impliedOptionValues) {
|
|
758
|
+
let newImplied = impliedOptionValues;
|
|
759
|
+
if (typeof impliedOptionValues === "string") {
|
|
760
|
+
newImplied = { [impliedOptionValues]: true };
|
|
761
|
+
}
|
|
762
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
env(name) {
|
|
766
|
+
this.envVar = name;
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
argParser(fn) {
|
|
770
|
+
this.parseArg = fn;
|
|
771
|
+
return this;
|
|
772
|
+
}
|
|
773
|
+
makeOptionMandatory(mandatory = true) {
|
|
774
|
+
this.mandatory = !!mandatory;
|
|
775
|
+
return this;
|
|
776
|
+
}
|
|
777
|
+
hideHelp(hide = true) {
|
|
778
|
+
this.hidden = !!hide;
|
|
779
|
+
return this;
|
|
780
|
+
}
|
|
781
|
+
_collectValue(value, previous) {
|
|
782
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
783
|
+
return [value];
|
|
784
|
+
}
|
|
785
|
+
previous.push(value);
|
|
786
|
+
return previous;
|
|
787
|
+
}
|
|
788
|
+
choices(values) {
|
|
789
|
+
this.argChoices = values.slice();
|
|
790
|
+
this.parseArg = (arg, previous) => {
|
|
791
|
+
if (!this.argChoices.includes(arg)) {
|
|
792
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
793
|
+
}
|
|
794
|
+
if (this.variadic) {
|
|
795
|
+
return this._collectValue(arg, previous);
|
|
796
|
+
}
|
|
797
|
+
return arg;
|
|
798
|
+
};
|
|
799
|
+
return this;
|
|
800
|
+
}
|
|
801
|
+
name() {
|
|
802
|
+
if (this.long) {
|
|
803
|
+
return this.long.replace(/^--/, "");
|
|
804
|
+
}
|
|
805
|
+
return this.short.replace(/^-/, "");
|
|
806
|
+
}
|
|
807
|
+
attributeName() {
|
|
808
|
+
if (this.negate) {
|
|
809
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
810
|
+
}
|
|
811
|
+
return camelcase(this.name());
|
|
812
|
+
}
|
|
813
|
+
helpGroup(heading) {
|
|
814
|
+
this.helpGroupHeading = heading;
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
is(arg) {
|
|
818
|
+
return this.short === arg || this.long === arg;
|
|
819
|
+
}
|
|
820
|
+
isBoolean() {
|
|
821
|
+
return !this.required && !this.optional && !this.negate;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
class DualOptions {
|
|
826
|
+
constructor(options) {
|
|
827
|
+
this.positiveOptions = new Map;
|
|
828
|
+
this.negativeOptions = new Map;
|
|
829
|
+
this.dualOptions = new Set;
|
|
830
|
+
options.forEach((option) => {
|
|
831
|
+
if (option.negate) {
|
|
832
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
833
|
+
} else {
|
|
834
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
this.negativeOptions.forEach((value, key) => {
|
|
838
|
+
if (this.positiveOptions.has(key)) {
|
|
839
|
+
this.dualOptions.add(key);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
valueFromOption(value, option) {
|
|
844
|
+
const optionKey = option.attributeName();
|
|
845
|
+
if (!this.dualOptions.has(optionKey))
|
|
846
|
+
return true;
|
|
847
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
848
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
849
|
+
return option.negate === (negativeValue === value);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function camelcase(str) {
|
|
853
|
+
return str.split("-").reduce((str2, word) => {
|
|
854
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
function splitOptionFlags(flags) {
|
|
858
|
+
let shortFlag;
|
|
859
|
+
let longFlag;
|
|
860
|
+
const shortFlagExp = /^-[^-]$/;
|
|
861
|
+
const longFlagExp = /^--[^-]/;
|
|
862
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
863
|
+
if (shortFlagExp.test(flagParts[0]))
|
|
864
|
+
shortFlag = flagParts.shift();
|
|
865
|
+
if (longFlagExp.test(flagParts[0]))
|
|
866
|
+
longFlag = flagParts.shift();
|
|
867
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
868
|
+
shortFlag = flagParts.shift();
|
|
869
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
870
|
+
shortFlag = longFlag;
|
|
871
|
+
longFlag = flagParts.shift();
|
|
872
|
+
}
|
|
873
|
+
if (flagParts[0].startsWith("-")) {
|
|
874
|
+
const unsupportedFlag = flagParts[0];
|
|
875
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
876
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
877
|
+
throw new Error(`${baseError}
|
|
878
|
+
- a short flag is a single dash and a single character
|
|
879
|
+
- either use a single dash and a single character (for a short flag)
|
|
880
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
881
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
882
|
+
throw new Error(`${baseError}
|
|
883
|
+
- too many short flags`);
|
|
884
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
885
|
+
throw new Error(`${baseError}
|
|
886
|
+
- too many long flags`);
|
|
887
|
+
throw new Error(`${baseError}
|
|
888
|
+
- unrecognised flag format`);
|
|
889
|
+
}
|
|
890
|
+
if (shortFlag === undefined && longFlag === undefined)
|
|
891
|
+
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
892
|
+
return { shortFlag, longFlag };
|
|
893
|
+
}
|
|
894
|
+
exports.Option = Option;
|
|
895
|
+
exports.DualOptions = DualOptions;
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
// ../../node_modules/commander/lib/suggestSimilar.js
|
|
899
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
900
|
+
var maxDistance = 3;
|
|
901
|
+
function editDistance(a, b) {
|
|
902
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
903
|
+
return Math.max(a.length, b.length);
|
|
904
|
+
const d = [];
|
|
905
|
+
for (let i = 0;i <= a.length; i++) {
|
|
906
|
+
d[i] = [i];
|
|
907
|
+
}
|
|
908
|
+
for (let j = 0;j <= b.length; j++) {
|
|
909
|
+
d[0][j] = j;
|
|
910
|
+
}
|
|
911
|
+
for (let j = 1;j <= b.length; j++) {
|
|
912
|
+
for (let i = 1;i <= a.length; i++) {
|
|
913
|
+
let cost = 1;
|
|
914
|
+
if (a[i - 1] === b[j - 1]) {
|
|
915
|
+
cost = 0;
|
|
916
|
+
} else {
|
|
917
|
+
cost = 1;
|
|
918
|
+
}
|
|
919
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
920
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
921
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return d[a.length][b.length];
|
|
926
|
+
}
|
|
927
|
+
function suggestSimilar(word, candidates) {
|
|
928
|
+
if (!candidates || candidates.length === 0)
|
|
929
|
+
return "";
|
|
930
|
+
candidates = Array.from(new Set(candidates));
|
|
931
|
+
const searchingOptions = word.startsWith("--");
|
|
932
|
+
if (searchingOptions) {
|
|
933
|
+
word = word.slice(2);
|
|
934
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
935
|
+
}
|
|
936
|
+
let similar = [];
|
|
937
|
+
let bestDistance = maxDistance;
|
|
938
|
+
const minSimilarity = 0.4;
|
|
939
|
+
candidates.forEach((candidate) => {
|
|
940
|
+
if (candidate.length <= 1)
|
|
941
|
+
return;
|
|
942
|
+
const distance = editDistance(word, candidate);
|
|
943
|
+
const length = Math.max(word.length, candidate.length);
|
|
944
|
+
const similarity = (length - distance) / length;
|
|
945
|
+
if (similarity > minSimilarity) {
|
|
946
|
+
if (distance < bestDistance) {
|
|
947
|
+
bestDistance = distance;
|
|
948
|
+
similar = [candidate];
|
|
949
|
+
} else if (distance === bestDistance) {
|
|
950
|
+
similar.push(candidate);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
955
|
+
if (searchingOptions) {
|
|
956
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
957
|
+
}
|
|
958
|
+
if (similar.length > 1) {
|
|
959
|
+
return `
|
|
960
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
961
|
+
}
|
|
962
|
+
if (similar.length === 1) {
|
|
963
|
+
return `
|
|
964
|
+
(Did you mean ${similar[0]}?)`;
|
|
965
|
+
}
|
|
966
|
+
return "";
|
|
967
|
+
}
|
|
968
|
+
exports.suggestSimilar = suggestSimilar;
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
// ../../node_modules/commander/lib/command.js
|
|
972
|
+
var require_command = __commonJS((exports) => {
|
|
973
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
974
|
+
var childProcess = __require("node:child_process");
|
|
975
|
+
var path2 = __require("node:path");
|
|
976
|
+
var fs = __require("node:fs");
|
|
977
|
+
var process4 = __require("node:process");
|
|
978
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
979
|
+
var { CommanderError } = require_error();
|
|
980
|
+
var { Help, stripColor } = require_help();
|
|
981
|
+
var { Option, DualOptions } = require_option();
|
|
982
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
983
|
+
|
|
984
|
+
class Command extends EventEmitter {
|
|
985
|
+
constructor(name) {
|
|
986
|
+
super();
|
|
987
|
+
this.commands = [];
|
|
988
|
+
this.options = [];
|
|
989
|
+
this.parent = null;
|
|
990
|
+
this._allowUnknownOption = false;
|
|
991
|
+
this._allowExcessArguments = false;
|
|
992
|
+
this.registeredArguments = [];
|
|
993
|
+
this._args = this.registeredArguments;
|
|
994
|
+
this.args = [];
|
|
995
|
+
this.rawArgs = [];
|
|
996
|
+
this.processedArgs = [];
|
|
997
|
+
this._scriptPath = null;
|
|
998
|
+
this._name = name || "";
|
|
999
|
+
this._optionValues = {};
|
|
1000
|
+
this._optionValueSources = {};
|
|
1001
|
+
this._storeOptionsAsProperties = false;
|
|
1002
|
+
this._actionHandler = null;
|
|
1003
|
+
this._executableHandler = false;
|
|
1004
|
+
this._executableFile = null;
|
|
1005
|
+
this._executableDir = null;
|
|
1006
|
+
this._defaultCommandName = null;
|
|
1007
|
+
this._exitCallback = null;
|
|
1008
|
+
this._aliases = [];
|
|
1009
|
+
this._combineFlagAndOptionalValue = true;
|
|
1010
|
+
this._description = "";
|
|
1011
|
+
this._summary = "";
|
|
1012
|
+
this._argsDescription = undefined;
|
|
1013
|
+
this._enablePositionalOptions = false;
|
|
1014
|
+
this._passThroughOptions = false;
|
|
1015
|
+
this._lifeCycleHooks = {};
|
|
1016
|
+
this._showHelpAfterError = false;
|
|
1017
|
+
this._showSuggestionAfterError = true;
|
|
1018
|
+
this._savedState = null;
|
|
1019
|
+
this._outputConfiguration = {
|
|
1020
|
+
writeOut: (str) => process4.stdout.write(str),
|
|
1021
|
+
writeErr: (str) => process4.stderr.write(str),
|
|
1022
|
+
outputError: (str, write) => write(str),
|
|
1023
|
+
getOutHelpWidth: () => process4.stdout.isTTY ? process4.stdout.columns : undefined,
|
|
1024
|
+
getErrHelpWidth: () => process4.stderr.isTTY ? process4.stderr.columns : undefined,
|
|
1025
|
+
getOutHasColors: () => useColor() ?? (process4.stdout.isTTY && process4.stdout.hasColors?.()),
|
|
1026
|
+
getErrHasColors: () => useColor() ?? (process4.stderr.isTTY && process4.stderr.hasColors?.()),
|
|
1027
|
+
stripColor: (str) => stripColor(str)
|
|
1028
|
+
};
|
|
1029
|
+
this._hidden = false;
|
|
1030
|
+
this._helpOption = undefined;
|
|
1031
|
+
this._addImplicitHelpCommand = undefined;
|
|
1032
|
+
this._helpCommand = undefined;
|
|
1033
|
+
this._helpConfiguration = {};
|
|
1034
|
+
this._helpGroupHeading = undefined;
|
|
1035
|
+
this._defaultCommandGroup = undefined;
|
|
1036
|
+
this._defaultOptionGroup = undefined;
|
|
1037
|
+
}
|
|
1038
|
+
copyInheritedSettings(sourceCommand) {
|
|
1039
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1040
|
+
this._helpOption = sourceCommand._helpOption;
|
|
1041
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
1042
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1043
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
1044
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1045
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1046
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1047
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1048
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1049
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1050
|
+
return this;
|
|
1051
|
+
}
|
|
1052
|
+
_getCommandAndAncestors() {
|
|
1053
|
+
const result = [];
|
|
1054
|
+
for (let command = this;command; command = command.parent) {
|
|
1055
|
+
result.push(command);
|
|
1056
|
+
}
|
|
1057
|
+
return result;
|
|
1058
|
+
}
|
|
1059
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1060
|
+
let desc = actionOptsOrExecDesc;
|
|
1061
|
+
let opts = execOpts;
|
|
1062
|
+
if (typeof desc === "object" && desc !== null) {
|
|
1063
|
+
opts = desc;
|
|
1064
|
+
desc = null;
|
|
1065
|
+
}
|
|
1066
|
+
opts = opts || {};
|
|
1067
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1068
|
+
const cmd = this.createCommand(name);
|
|
1069
|
+
if (desc) {
|
|
1070
|
+
cmd.description(desc);
|
|
1071
|
+
cmd._executableHandler = true;
|
|
1072
|
+
}
|
|
1073
|
+
if (opts.isDefault)
|
|
1074
|
+
this._defaultCommandName = cmd._name;
|
|
1075
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1076
|
+
cmd._executableFile = opts.executableFile || null;
|
|
1077
|
+
if (args)
|
|
1078
|
+
cmd.arguments(args);
|
|
1079
|
+
this._registerCommand(cmd);
|
|
1080
|
+
cmd.parent = this;
|
|
1081
|
+
cmd.copyInheritedSettings(this);
|
|
1082
|
+
if (desc)
|
|
1083
|
+
return this;
|
|
1084
|
+
return cmd;
|
|
1085
|
+
}
|
|
1086
|
+
createCommand(name) {
|
|
1087
|
+
return new Command(name);
|
|
1088
|
+
}
|
|
1089
|
+
createHelp() {
|
|
1090
|
+
return Object.assign(new Help, this.configureHelp());
|
|
1091
|
+
}
|
|
1092
|
+
configureHelp(configuration) {
|
|
1093
|
+
if (configuration === undefined)
|
|
1094
|
+
return this._helpConfiguration;
|
|
1095
|
+
this._helpConfiguration = configuration;
|
|
1096
|
+
return this;
|
|
1097
|
+
}
|
|
1098
|
+
configureOutput(configuration) {
|
|
1099
|
+
if (configuration === undefined)
|
|
1100
|
+
return this._outputConfiguration;
|
|
1101
|
+
this._outputConfiguration = {
|
|
1102
|
+
...this._outputConfiguration,
|
|
1103
|
+
...configuration
|
|
1104
|
+
};
|
|
1105
|
+
return this;
|
|
1106
|
+
}
|
|
1107
|
+
showHelpAfterError(displayHelp = true) {
|
|
1108
|
+
if (typeof displayHelp !== "string")
|
|
1109
|
+
displayHelp = !!displayHelp;
|
|
1110
|
+
this._showHelpAfterError = displayHelp;
|
|
1111
|
+
return this;
|
|
1112
|
+
}
|
|
1113
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1114
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1115
|
+
return this;
|
|
1116
|
+
}
|
|
1117
|
+
addCommand(cmd, opts) {
|
|
1118
|
+
if (!cmd._name) {
|
|
1119
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
1120
|
+
- specify the name in Command constructor or using .name()`);
|
|
1121
|
+
}
|
|
1122
|
+
opts = opts || {};
|
|
1123
|
+
if (opts.isDefault)
|
|
1124
|
+
this._defaultCommandName = cmd._name;
|
|
1125
|
+
if (opts.noHelp || opts.hidden)
|
|
1126
|
+
cmd._hidden = true;
|
|
1127
|
+
this._registerCommand(cmd);
|
|
1128
|
+
cmd.parent = this;
|
|
1129
|
+
cmd._checkForBrokenPassThrough();
|
|
1130
|
+
return this;
|
|
1131
|
+
}
|
|
1132
|
+
createArgument(name, description) {
|
|
1133
|
+
return new Argument(name, description);
|
|
1134
|
+
}
|
|
1135
|
+
argument(name, description, parseArg, defaultValue) {
|
|
1136
|
+
const argument = this.createArgument(name, description);
|
|
1137
|
+
if (typeof parseArg === "function") {
|
|
1138
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
1139
|
+
} else {
|
|
1140
|
+
argument.default(parseArg);
|
|
1141
|
+
}
|
|
1142
|
+
this.addArgument(argument);
|
|
1143
|
+
return this;
|
|
1144
|
+
}
|
|
1145
|
+
arguments(names) {
|
|
1146
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
1147
|
+
this.argument(detail);
|
|
1148
|
+
});
|
|
1149
|
+
return this;
|
|
1150
|
+
}
|
|
1151
|
+
addArgument(argument) {
|
|
1152
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1153
|
+
if (previousArgument?.variadic) {
|
|
1154
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
1155
|
+
}
|
|
1156
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
1157
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
1158
|
+
}
|
|
1159
|
+
this.registeredArguments.push(argument);
|
|
1160
|
+
return this;
|
|
1161
|
+
}
|
|
1162
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
1163
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1164
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1165
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
1166
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
1167
|
+
}
|
|
1168
|
+
return this;
|
|
1169
|
+
}
|
|
1170
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1171
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1172
|
+
const helpDescription = description ?? "display help for command";
|
|
1173
|
+
const helpCommand = this.createCommand(helpName);
|
|
1174
|
+
helpCommand.helpOption(false);
|
|
1175
|
+
if (helpArgs)
|
|
1176
|
+
helpCommand.arguments(helpArgs);
|
|
1177
|
+
if (helpDescription)
|
|
1178
|
+
helpCommand.description(helpDescription);
|
|
1179
|
+
this._addImplicitHelpCommand = true;
|
|
1180
|
+
this._helpCommand = helpCommand;
|
|
1181
|
+
if (enableOrNameAndArgs || description)
|
|
1182
|
+
this._initCommandGroup(helpCommand);
|
|
1183
|
+
return this;
|
|
1184
|
+
}
|
|
1185
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1186
|
+
if (typeof helpCommand !== "object") {
|
|
1187
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1188
|
+
return this;
|
|
1189
|
+
}
|
|
1190
|
+
this._addImplicitHelpCommand = true;
|
|
1191
|
+
this._helpCommand = helpCommand;
|
|
1192
|
+
this._initCommandGroup(helpCommand);
|
|
1193
|
+
return this;
|
|
1194
|
+
}
|
|
1195
|
+
_getHelpCommand() {
|
|
1196
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
1197
|
+
if (hasImplicitHelpCommand) {
|
|
1198
|
+
if (this._helpCommand === undefined) {
|
|
1199
|
+
this.helpCommand(undefined, undefined);
|
|
1200
|
+
}
|
|
1201
|
+
return this._helpCommand;
|
|
1202
|
+
}
|
|
1203
|
+
return null;
|
|
1204
|
+
}
|
|
1205
|
+
hook(event, listener) {
|
|
1206
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1207
|
+
if (!allowedValues.includes(event)) {
|
|
1208
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1209
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1210
|
+
}
|
|
1211
|
+
if (this._lifeCycleHooks[event]) {
|
|
1212
|
+
this._lifeCycleHooks[event].push(listener);
|
|
1213
|
+
} else {
|
|
1214
|
+
this._lifeCycleHooks[event] = [listener];
|
|
1215
|
+
}
|
|
1216
|
+
return this;
|
|
1217
|
+
}
|
|
1218
|
+
exitOverride(fn) {
|
|
1219
|
+
if (fn) {
|
|
1220
|
+
this._exitCallback = fn;
|
|
1221
|
+
} else {
|
|
1222
|
+
this._exitCallback = (err) => {
|
|
1223
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1224
|
+
throw err;
|
|
1225
|
+
} else {}
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
return this;
|
|
1229
|
+
}
|
|
1230
|
+
_exit(exitCode, code, message) {
|
|
1231
|
+
if (this._exitCallback) {
|
|
1232
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
1233
|
+
}
|
|
1234
|
+
process4.exit(exitCode);
|
|
1235
|
+
}
|
|
1236
|
+
action(fn) {
|
|
1237
|
+
const listener = (args) => {
|
|
1238
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1239
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1240
|
+
if (this._storeOptionsAsProperties) {
|
|
1241
|
+
actionArgs[expectedArgsCount] = this;
|
|
1242
|
+
} else {
|
|
1243
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
1244
|
+
}
|
|
1245
|
+
actionArgs.push(this);
|
|
1246
|
+
return fn.apply(this, actionArgs);
|
|
1247
|
+
};
|
|
1248
|
+
this._actionHandler = listener;
|
|
1249
|
+
return this;
|
|
1250
|
+
}
|
|
1251
|
+
createOption(flags, description) {
|
|
1252
|
+
return new Option(flags, description);
|
|
1253
|
+
}
|
|
1254
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1255
|
+
try {
|
|
1256
|
+
return target.parseArg(value, previous);
|
|
1257
|
+
} catch (err) {
|
|
1258
|
+
if (err.code === "commander.invalidArgument") {
|
|
1259
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1260
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1261
|
+
}
|
|
1262
|
+
throw err;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
_registerOption(option) {
|
|
1266
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1267
|
+
if (matchingOption) {
|
|
1268
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1269
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1270
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1271
|
+
}
|
|
1272
|
+
this._initOptionGroup(option);
|
|
1273
|
+
this.options.push(option);
|
|
1274
|
+
}
|
|
1275
|
+
_registerCommand(command) {
|
|
1276
|
+
const knownBy = (cmd) => {
|
|
1277
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1278
|
+
};
|
|
1279
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
1280
|
+
if (alreadyUsed) {
|
|
1281
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1282
|
+
const newCmd = knownBy(command).join("|");
|
|
1283
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
1284
|
+
}
|
|
1285
|
+
this._initCommandGroup(command);
|
|
1286
|
+
this.commands.push(command);
|
|
1287
|
+
}
|
|
1288
|
+
addOption(option) {
|
|
1289
|
+
this._registerOption(option);
|
|
1290
|
+
const oname = option.name();
|
|
1291
|
+
const name = option.attributeName();
|
|
1292
|
+
if (option.negate) {
|
|
1293
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1294
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
1295
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
1296
|
+
}
|
|
1297
|
+
} else if (option.defaultValue !== undefined) {
|
|
1298
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1299
|
+
}
|
|
1300
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1301
|
+
if (val == null && option.presetArg !== undefined) {
|
|
1302
|
+
val = option.presetArg;
|
|
1303
|
+
}
|
|
1304
|
+
const oldValue = this.getOptionValue(name);
|
|
1305
|
+
if (val !== null && option.parseArg) {
|
|
1306
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1307
|
+
} else if (val !== null && option.variadic) {
|
|
1308
|
+
val = option._collectValue(val, oldValue);
|
|
1309
|
+
}
|
|
1310
|
+
if (val == null) {
|
|
1311
|
+
if (option.negate) {
|
|
1312
|
+
val = false;
|
|
1313
|
+
} else if (option.isBoolean() || option.optional) {
|
|
1314
|
+
val = true;
|
|
1315
|
+
} else {
|
|
1316
|
+
val = "";
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1320
|
+
};
|
|
1321
|
+
this.on("option:" + oname, (val) => {
|
|
1322
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1323
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1324
|
+
});
|
|
1325
|
+
if (option.envVar) {
|
|
1326
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
1327
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1328
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
return this;
|
|
1332
|
+
}
|
|
1333
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1334
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
1335
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1336
|
+
}
|
|
1337
|
+
const option = this.createOption(flags, description);
|
|
1338
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1339
|
+
if (typeof fn === "function") {
|
|
1340
|
+
option.default(defaultValue).argParser(fn);
|
|
1341
|
+
} else if (fn instanceof RegExp) {
|
|
1342
|
+
const regex = fn;
|
|
1343
|
+
fn = (val, def) => {
|
|
1344
|
+
const m = regex.exec(val);
|
|
1345
|
+
return m ? m[0] : def;
|
|
1346
|
+
};
|
|
1347
|
+
option.default(defaultValue).argParser(fn);
|
|
1348
|
+
} else {
|
|
1349
|
+
option.default(fn);
|
|
1350
|
+
}
|
|
1351
|
+
return this.addOption(option);
|
|
1352
|
+
}
|
|
1353
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1354
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1355
|
+
}
|
|
1356
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1357
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
1358
|
+
}
|
|
1359
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1360
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1361
|
+
return this;
|
|
1362
|
+
}
|
|
1363
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1364
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1367
|
+
allowExcessArguments(allowExcess = true) {
|
|
1368
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1369
|
+
return this;
|
|
1370
|
+
}
|
|
1371
|
+
enablePositionalOptions(positional = true) {
|
|
1372
|
+
this._enablePositionalOptions = !!positional;
|
|
1373
|
+
return this;
|
|
1374
|
+
}
|
|
1375
|
+
passThroughOptions(passThrough = true) {
|
|
1376
|
+
this._passThroughOptions = !!passThrough;
|
|
1377
|
+
this._checkForBrokenPassThrough();
|
|
1378
|
+
return this;
|
|
1379
|
+
}
|
|
1380
|
+
_checkForBrokenPassThrough() {
|
|
1381
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1382
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1386
|
+
if (this.options.length) {
|
|
1387
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1388
|
+
}
|
|
1389
|
+
if (Object.keys(this._optionValues).length) {
|
|
1390
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1391
|
+
}
|
|
1392
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1393
|
+
return this;
|
|
1394
|
+
}
|
|
1395
|
+
getOptionValue(key) {
|
|
1396
|
+
if (this._storeOptionsAsProperties) {
|
|
1397
|
+
return this[key];
|
|
1398
|
+
}
|
|
1399
|
+
return this._optionValues[key];
|
|
1400
|
+
}
|
|
1401
|
+
setOptionValue(key, value) {
|
|
1402
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1403
|
+
}
|
|
1404
|
+
setOptionValueWithSource(key, value, source) {
|
|
1405
|
+
if (this._storeOptionsAsProperties) {
|
|
1406
|
+
this[key] = value;
|
|
1407
|
+
} else {
|
|
1408
|
+
this._optionValues[key] = value;
|
|
1409
|
+
}
|
|
1410
|
+
this._optionValueSources[key] = source;
|
|
1411
|
+
return this;
|
|
1412
|
+
}
|
|
1413
|
+
getOptionValueSource(key) {
|
|
1414
|
+
return this._optionValueSources[key];
|
|
1415
|
+
}
|
|
1416
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1417
|
+
let source;
|
|
1418
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1419
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1420
|
+
source = cmd.getOptionValueSource(key);
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
return source;
|
|
1424
|
+
}
|
|
1425
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1426
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1427
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1428
|
+
}
|
|
1429
|
+
parseOptions = parseOptions || {};
|
|
1430
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1431
|
+
if (process4.versions?.electron) {
|
|
1432
|
+
parseOptions.from = "electron";
|
|
1433
|
+
}
|
|
1434
|
+
const execArgv = process4.execArgv ?? [];
|
|
1435
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1436
|
+
parseOptions.from = "eval";
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
if (argv === undefined) {
|
|
1440
|
+
argv = process4.argv;
|
|
1441
|
+
}
|
|
1442
|
+
this.rawArgs = argv.slice();
|
|
1443
|
+
let userArgs;
|
|
1444
|
+
switch (parseOptions.from) {
|
|
1445
|
+
case undefined:
|
|
1446
|
+
case "node":
|
|
1447
|
+
this._scriptPath = argv[1];
|
|
1448
|
+
userArgs = argv.slice(2);
|
|
1449
|
+
break;
|
|
1450
|
+
case "electron":
|
|
1451
|
+
if (process4.defaultApp) {
|
|
1452
|
+
this._scriptPath = argv[1];
|
|
1453
|
+
userArgs = argv.slice(2);
|
|
1454
|
+
} else {
|
|
1455
|
+
userArgs = argv.slice(1);
|
|
1456
|
+
}
|
|
1457
|
+
break;
|
|
1458
|
+
case "user":
|
|
1459
|
+
userArgs = argv.slice(0);
|
|
1460
|
+
break;
|
|
1461
|
+
case "eval":
|
|
1462
|
+
userArgs = argv.slice(1);
|
|
1463
|
+
break;
|
|
1464
|
+
default:
|
|
1465
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1466
|
+
}
|
|
1467
|
+
if (!this._name && this._scriptPath)
|
|
1468
|
+
this.nameFromFilename(this._scriptPath);
|
|
1469
|
+
this._name = this._name || "program";
|
|
1470
|
+
return userArgs;
|
|
1471
|
+
}
|
|
1472
|
+
parse(argv, parseOptions) {
|
|
1473
|
+
this._prepareForParse();
|
|
1474
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1475
|
+
this._parseCommand([], userArgs);
|
|
1476
|
+
return this;
|
|
1477
|
+
}
|
|
1478
|
+
async parseAsync(argv, parseOptions) {
|
|
1479
|
+
this._prepareForParse();
|
|
1480
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1481
|
+
await this._parseCommand([], userArgs);
|
|
1482
|
+
return this;
|
|
1483
|
+
}
|
|
1484
|
+
_prepareForParse() {
|
|
1485
|
+
if (this._savedState === null) {
|
|
1486
|
+
this.saveStateBeforeParse();
|
|
1487
|
+
} else {
|
|
1488
|
+
this.restoreStateBeforeParse();
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
saveStateBeforeParse() {
|
|
1492
|
+
this._savedState = {
|
|
1493
|
+
_name: this._name,
|
|
1494
|
+
_optionValues: { ...this._optionValues },
|
|
1495
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
restoreStateBeforeParse() {
|
|
1499
|
+
if (this._storeOptionsAsProperties)
|
|
1500
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
1501
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1502
|
+
this._name = this._savedState._name;
|
|
1503
|
+
this._scriptPath = null;
|
|
1504
|
+
this.rawArgs = [];
|
|
1505
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
1506
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
1507
|
+
this.args = [];
|
|
1508
|
+
this.processedArgs = [];
|
|
1509
|
+
}
|
|
1510
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1511
|
+
if (fs.existsSync(executableFile))
|
|
1512
|
+
return;
|
|
1513
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1514
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1515
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1516
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1517
|
+
- ${executableDirMessage}`;
|
|
1518
|
+
throw new Error(executableMissing);
|
|
1519
|
+
}
|
|
1520
|
+
_executeSubCommand(subcommand, args) {
|
|
1521
|
+
args = args.slice();
|
|
1522
|
+
let launchWithNode = false;
|
|
1523
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1524
|
+
function findFile(baseDir, baseName) {
|
|
1525
|
+
const localBin = path2.resolve(baseDir, baseName);
|
|
1526
|
+
if (fs.existsSync(localBin))
|
|
1527
|
+
return localBin;
|
|
1528
|
+
if (sourceExt.includes(path2.extname(baseName)))
|
|
1529
|
+
return;
|
|
1530
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1531
|
+
if (foundExt)
|
|
1532
|
+
return `${localBin}${foundExt}`;
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
this._checkForMissingMandatoryOptions();
|
|
1536
|
+
this._checkForConflictingOptions();
|
|
1537
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1538
|
+
let executableDir = this._executableDir || "";
|
|
1539
|
+
if (this._scriptPath) {
|
|
1540
|
+
let resolvedScriptPath;
|
|
1541
|
+
try {
|
|
1542
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1543
|
+
} catch {
|
|
1544
|
+
resolvedScriptPath = this._scriptPath;
|
|
1545
|
+
}
|
|
1546
|
+
executableDir = path2.resolve(path2.dirname(resolvedScriptPath), executableDir);
|
|
1547
|
+
}
|
|
1548
|
+
if (executableDir) {
|
|
1549
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1550
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1551
|
+
const legacyName = path2.basename(this._scriptPath, path2.extname(this._scriptPath));
|
|
1552
|
+
if (legacyName !== this._name) {
|
|
1553
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
executableFile = localFile || executableFile;
|
|
1557
|
+
}
|
|
1558
|
+
launchWithNode = sourceExt.includes(path2.extname(executableFile));
|
|
1559
|
+
let proc;
|
|
1560
|
+
if (process4.platform !== "win32") {
|
|
1561
|
+
if (launchWithNode) {
|
|
1562
|
+
args.unshift(executableFile);
|
|
1563
|
+
args = incrementNodeInspectorPort(process4.execArgv).concat(args);
|
|
1564
|
+
proc = childProcess.spawn(process4.argv[0], args, { stdio: "inherit" });
|
|
1565
|
+
} else {
|
|
1566
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1567
|
+
}
|
|
1568
|
+
} else {
|
|
1569
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1570
|
+
args.unshift(executableFile);
|
|
1571
|
+
args = incrementNodeInspectorPort(process4.execArgv).concat(args);
|
|
1572
|
+
proc = childProcess.spawn(process4.execPath, args, { stdio: "inherit" });
|
|
1573
|
+
}
|
|
1574
|
+
if (!proc.killed) {
|
|
1575
|
+
const signals2 = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1576
|
+
signals2.forEach((signal) => {
|
|
1577
|
+
process4.on(signal, () => {
|
|
1578
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1579
|
+
proc.kill(signal);
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
const exitCallback = this._exitCallback;
|
|
1585
|
+
proc.on("close", (code) => {
|
|
1586
|
+
code = code ?? 1;
|
|
1587
|
+
if (!exitCallback) {
|
|
1588
|
+
process4.exit(code);
|
|
1589
|
+
} else {
|
|
1590
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
proc.on("error", (err) => {
|
|
1594
|
+
if (err.code === "ENOENT") {
|
|
1595
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1596
|
+
} else if (err.code === "EACCES") {
|
|
1597
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1598
|
+
}
|
|
1599
|
+
if (!exitCallback) {
|
|
1600
|
+
process4.exit(1);
|
|
1601
|
+
} else {
|
|
1602
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1603
|
+
wrappedError.nestedError = err;
|
|
1604
|
+
exitCallback(wrappedError);
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
this.runningCommand = proc;
|
|
1608
|
+
}
|
|
1609
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1610
|
+
const subCommand = this._findCommand(commandName);
|
|
1611
|
+
if (!subCommand)
|
|
1612
|
+
this.help({ error: true });
|
|
1613
|
+
subCommand._prepareForParse();
|
|
1614
|
+
let promiseChain;
|
|
1615
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1616
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1617
|
+
if (subCommand._executableHandler) {
|
|
1618
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1619
|
+
} else {
|
|
1620
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
return promiseChain;
|
|
1624
|
+
}
|
|
1625
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1626
|
+
if (!subcommandName) {
|
|
1627
|
+
this.help();
|
|
1628
|
+
}
|
|
1629
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1630
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1631
|
+
subCommand.help();
|
|
1632
|
+
}
|
|
1633
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1634
|
+
}
|
|
1635
|
+
_checkNumberOfArguments() {
|
|
1636
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1637
|
+
if (arg.required && this.args[i] == null) {
|
|
1638
|
+
this.missingArgument(arg.name());
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1645
|
+
this._excessArguments(this.args);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
_processArguments() {
|
|
1649
|
+
const myParseArg = (argument, value, previous) => {
|
|
1650
|
+
let parsedValue = value;
|
|
1651
|
+
if (value !== null && argument.parseArg) {
|
|
1652
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1653
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1654
|
+
}
|
|
1655
|
+
return parsedValue;
|
|
1656
|
+
};
|
|
1657
|
+
this._checkNumberOfArguments();
|
|
1658
|
+
const processedArgs = [];
|
|
1659
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1660
|
+
let value = declaredArg.defaultValue;
|
|
1661
|
+
if (declaredArg.variadic) {
|
|
1662
|
+
if (index < this.args.length) {
|
|
1663
|
+
value = this.args.slice(index);
|
|
1664
|
+
if (declaredArg.parseArg) {
|
|
1665
|
+
value = value.reduce((processed, v) => {
|
|
1666
|
+
return myParseArg(declaredArg, v, processed);
|
|
1667
|
+
}, declaredArg.defaultValue);
|
|
1668
|
+
}
|
|
1669
|
+
} else if (value === undefined) {
|
|
1670
|
+
value = [];
|
|
1671
|
+
}
|
|
1672
|
+
} else if (index < this.args.length) {
|
|
1673
|
+
value = this.args[index];
|
|
1674
|
+
if (declaredArg.parseArg) {
|
|
1675
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
processedArgs[index] = value;
|
|
1679
|
+
});
|
|
1680
|
+
this.processedArgs = processedArgs;
|
|
1681
|
+
}
|
|
1682
|
+
_chainOrCall(promise, fn) {
|
|
1683
|
+
if (promise?.then && typeof promise.then === "function") {
|
|
1684
|
+
return promise.then(() => fn());
|
|
1685
|
+
}
|
|
1686
|
+
return fn();
|
|
1687
|
+
}
|
|
1688
|
+
_chainOrCallHooks(promise, event) {
|
|
1689
|
+
let result = promise;
|
|
1690
|
+
const hooks = [];
|
|
1691
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1692
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1693
|
+
hooks.push({ hookedCommand, callback });
|
|
1694
|
+
});
|
|
1695
|
+
});
|
|
1696
|
+
if (event === "postAction") {
|
|
1697
|
+
hooks.reverse();
|
|
1698
|
+
}
|
|
1699
|
+
hooks.forEach((hookDetail) => {
|
|
1700
|
+
result = this._chainOrCall(result, () => {
|
|
1701
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1702
|
+
});
|
|
1703
|
+
});
|
|
1704
|
+
return result;
|
|
1705
|
+
}
|
|
1706
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1707
|
+
let result = promise;
|
|
1708
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1709
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1710
|
+
result = this._chainOrCall(result, () => {
|
|
1711
|
+
return hook(this, subCommand);
|
|
1712
|
+
});
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
return result;
|
|
1716
|
+
}
|
|
1717
|
+
_parseCommand(operands, unknown) {
|
|
1718
|
+
const parsed = this.parseOptions(unknown);
|
|
1719
|
+
this._parseOptionsEnv();
|
|
1720
|
+
this._parseOptionsImplied();
|
|
1721
|
+
operands = operands.concat(parsed.operands);
|
|
1722
|
+
unknown = parsed.unknown;
|
|
1723
|
+
this.args = operands.concat(unknown);
|
|
1724
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1725
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1726
|
+
}
|
|
1727
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1728
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1729
|
+
}
|
|
1730
|
+
if (this._defaultCommandName) {
|
|
1731
|
+
this._outputHelpIfRequested(unknown);
|
|
1732
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1733
|
+
}
|
|
1734
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1735
|
+
this.help({ error: true });
|
|
1736
|
+
}
|
|
1737
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1738
|
+
this._checkForMissingMandatoryOptions();
|
|
1739
|
+
this._checkForConflictingOptions();
|
|
1740
|
+
const checkForUnknownOptions = () => {
|
|
1741
|
+
if (parsed.unknown.length > 0) {
|
|
1742
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
const commandEvent = `command:${this.name()}`;
|
|
1746
|
+
if (this._actionHandler) {
|
|
1747
|
+
checkForUnknownOptions();
|
|
1748
|
+
this._processArguments();
|
|
1749
|
+
let promiseChain;
|
|
1750
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1751
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1752
|
+
if (this.parent) {
|
|
1753
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1754
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1758
|
+
return promiseChain;
|
|
1759
|
+
}
|
|
1760
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
1761
|
+
checkForUnknownOptions();
|
|
1762
|
+
this._processArguments();
|
|
1763
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1764
|
+
} else if (operands.length) {
|
|
1765
|
+
if (this._findCommand("*")) {
|
|
1766
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1767
|
+
}
|
|
1768
|
+
if (this.listenerCount("command:*")) {
|
|
1769
|
+
this.emit("command:*", operands, unknown);
|
|
1770
|
+
} else if (this.commands.length) {
|
|
1771
|
+
this.unknownCommand();
|
|
1772
|
+
} else {
|
|
1773
|
+
checkForUnknownOptions();
|
|
1774
|
+
this._processArguments();
|
|
1775
|
+
}
|
|
1776
|
+
} else if (this.commands.length) {
|
|
1777
|
+
checkForUnknownOptions();
|
|
1778
|
+
this.help({ error: true });
|
|
1779
|
+
} else {
|
|
1780
|
+
checkForUnknownOptions();
|
|
1781
|
+
this._processArguments();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
_findCommand(name) {
|
|
1785
|
+
if (!name)
|
|
1786
|
+
return;
|
|
1787
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1788
|
+
}
|
|
1789
|
+
_findOption(arg) {
|
|
1790
|
+
return this.options.find((option) => option.is(arg));
|
|
1791
|
+
}
|
|
1792
|
+
_checkForMissingMandatoryOptions() {
|
|
1793
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1794
|
+
cmd.options.forEach((anOption) => {
|
|
1795
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1796
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
_checkForConflictingLocalOptions() {
|
|
1802
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1803
|
+
const optionKey = option.attributeName();
|
|
1804
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1805
|
+
return false;
|
|
1806
|
+
}
|
|
1807
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1808
|
+
});
|
|
1809
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1810
|
+
optionsWithConflicting.forEach((option) => {
|
|
1811
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1812
|
+
if (conflictingAndDefined) {
|
|
1813
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
_checkForConflictingOptions() {
|
|
1818
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1819
|
+
cmd._checkForConflictingLocalOptions();
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
parseOptions(args) {
|
|
1823
|
+
const operands = [];
|
|
1824
|
+
const unknown = [];
|
|
1825
|
+
let dest = operands;
|
|
1826
|
+
function maybeOption(arg) {
|
|
1827
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1828
|
+
}
|
|
1829
|
+
const negativeNumberArg = (arg) => {
|
|
1830
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
|
|
1831
|
+
return false;
|
|
1832
|
+
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
1833
|
+
};
|
|
1834
|
+
let activeVariadicOption = null;
|
|
1835
|
+
let activeGroup = null;
|
|
1836
|
+
let i = 0;
|
|
1837
|
+
while (i < args.length || activeGroup) {
|
|
1838
|
+
const arg = activeGroup ?? args[i++];
|
|
1839
|
+
activeGroup = null;
|
|
1840
|
+
if (arg === "--") {
|
|
1841
|
+
if (dest === unknown)
|
|
1842
|
+
dest.push(arg);
|
|
1843
|
+
dest.push(...args.slice(i));
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
1847
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1848
|
+
continue;
|
|
1849
|
+
}
|
|
1850
|
+
activeVariadicOption = null;
|
|
1851
|
+
if (maybeOption(arg)) {
|
|
1852
|
+
const option = this._findOption(arg);
|
|
1853
|
+
if (option) {
|
|
1854
|
+
if (option.required) {
|
|
1855
|
+
const value = args[i++];
|
|
1856
|
+
if (value === undefined)
|
|
1857
|
+
this.optionMissingArgument(option);
|
|
1858
|
+
this.emit(`option:${option.name()}`, value);
|
|
1859
|
+
} else if (option.optional) {
|
|
1860
|
+
let value = null;
|
|
1861
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
1862
|
+
value = args[i++];
|
|
1863
|
+
}
|
|
1864
|
+
this.emit(`option:${option.name()}`, value);
|
|
1865
|
+
} else {
|
|
1866
|
+
this.emit(`option:${option.name()}`);
|
|
1867
|
+
}
|
|
1868
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1873
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1874
|
+
if (option) {
|
|
1875
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1876
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1877
|
+
} else {
|
|
1878
|
+
this.emit(`option:${option.name()}`);
|
|
1879
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
1880
|
+
}
|
|
1881
|
+
continue;
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1885
|
+
const index = arg.indexOf("=");
|
|
1886
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1887
|
+
if (option && (option.required || option.optional)) {
|
|
1888
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1889
|
+
continue;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
1893
|
+
dest = unknown;
|
|
1894
|
+
}
|
|
1895
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1896
|
+
if (this._findCommand(arg)) {
|
|
1897
|
+
operands.push(arg);
|
|
1898
|
+
unknown.push(...args.slice(i));
|
|
1899
|
+
break;
|
|
1900
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1901
|
+
operands.push(arg, ...args.slice(i));
|
|
1902
|
+
break;
|
|
1903
|
+
} else if (this._defaultCommandName) {
|
|
1904
|
+
unknown.push(arg, ...args.slice(i));
|
|
1905
|
+
break;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
if (this._passThroughOptions) {
|
|
1909
|
+
dest.push(arg, ...args.slice(i));
|
|
1910
|
+
break;
|
|
1911
|
+
}
|
|
1912
|
+
dest.push(arg);
|
|
1913
|
+
}
|
|
1914
|
+
return { operands, unknown };
|
|
1915
|
+
}
|
|
1916
|
+
opts() {
|
|
1917
|
+
if (this._storeOptionsAsProperties) {
|
|
1918
|
+
const result = {};
|
|
1919
|
+
const len = this.options.length;
|
|
1920
|
+
for (let i = 0;i < len; i++) {
|
|
1921
|
+
const key = this.options[i].attributeName();
|
|
1922
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1923
|
+
}
|
|
1924
|
+
return result;
|
|
1925
|
+
}
|
|
1926
|
+
return this._optionValues;
|
|
1927
|
+
}
|
|
1928
|
+
optsWithGlobals() {
|
|
1929
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1930
|
+
}
|
|
1931
|
+
error(message, errorOptions) {
|
|
1932
|
+
this._outputConfiguration.outputError(`${message}
|
|
1933
|
+
`, this._outputConfiguration.writeErr);
|
|
1934
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1935
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1936
|
+
`);
|
|
1937
|
+
} else if (this._showHelpAfterError) {
|
|
1938
|
+
this._outputConfiguration.writeErr(`
|
|
1939
|
+
`);
|
|
1940
|
+
this.outputHelp({ error: true });
|
|
1941
|
+
}
|
|
1942
|
+
const config = errorOptions || {};
|
|
1943
|
+
const exitCode = config.exitCode || 1;
|
|
1944
|
+
const code = config.code || "commander.error";
|
|
1945
|
+
this._exit(exitCode, code, message);
|
|
1946
|
+
}
|
|
1947
|
+
_parseOptionsEnv() {
|
|
1948
|
+
this.options.forEach((option) => {
|
|
1949
|
+
if (option.envVar && option.envVar in process4.env) {
|
|
1950
|
+
const optionKey = option.attributeName();
|
|
1951
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1952
|
+
if (option.required || option.optional) {
|
|
1953
|
+
this.emit(`optionEnv:${option.name()}`, process4.env[option.envVar]);
|
|
1954
|
+
} else {
|
|
1955
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
_parseOptionsImplied() {
|
|
1962
|
+
const dualHelper = new DualOptions(this.options);
|
|
1963
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1964
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1965
|
+
};
|
|
1966
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1967
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1968
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1969
|
+
});
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
missingArgument(name) {
|
|
1973
|
+
const message = `error: missing required argument '${name}'`;
|
|
1974
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1975
|
+
}
|
|
1976
|
+
optionMissingArgument(option) {
|
|
1977
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1978
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1979
|
+
}
|
|
1980
|
+
missingMandatoryOptionValue(option) {
|
|
1981
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1982
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1983
|
+
}
|
|
1984
|
+
_conflictingOption(option, conflictingOption) {
|
|
1985
|
+
const findBestOptionFromValue = (option2) => {
|
|
1986
|
+
const optionKey = option2.attributeName();
|
|
1987
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1988
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1989
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1990
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1991
|
+
return negativeOption;
|
|
1992
|
+
}
|
|
1993
|
+
return positiveOption || option2;
|
|
1994
|
+
};
|
|
1995
|
+
const getErrorMessage = (option2) => {
|
|
1996
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1997
|
+
const optionKey = bestOption.attributeName();
|
|
1998
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1999
|
+
if (source === "env") {
|
|
2000
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
2001
|
+
}
|
|
2002
|
+
return `option '${bestOption.flags}'`;
|
|
2003
|
+
};
|
|
2004
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2005
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
2006
|
+
}
|
|
2007
|
+
unknownOption(flag) {
|
|
2008
|
+
if (this._allowUnknownOption)
|
|
2009
|
+
return;
|
|
2010
|
+
let suggestion = "";
|
|
2011
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
2012
|
+
let candidateFlags = [];
|
|
2013
|
+
let command = this;
|
|
2014
|
+
do {
|
|
2015
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
2016
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
2017
|
+
command = command.parent;
|
|
2018
|
+
} while (command && !command._enablePositionalOptions);
|
|
2019
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
2020
|
+
}
|
|
2021
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
2022
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
2023
|
+
}
|
|
2024
|
+
_excessArguments(receivedArgs) {
|
|
2025
|
+
if (this._allowExcessArguments)
|
|
2026
|
+
return;
|
|
2027
|
+
const expected = this.registeredArguments.length;
|
|
2028
|
+
const s = expected === 1 ? "" : "s";
|
|
2029
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
2030
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2031
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
2032
|
+
}
|
|
2033
|
+
unknownCommand() {
|
|
2034
|
+
const unknownName = this.args[0];
|
|
2035
|
+
let suggestion = "";
|
|
2036
|
+
if (this._showSuggestionAfterError) {
|
|
2037
|
+
const candidateNames = [];
|
|
2038
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
2039
|
+
candidateNames.push(command.name());
|
|
2040
|
+
if (command.alias())
|
|
2041
|
+
candidateNames.push(command.alias());
|
|
2042
|
+
});
|
|
2043
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2044
|
+
}
|
|
2045
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
2046
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
2047
|
+
}
|
|
2048
|
+
version(str, flags, description) {
|
|
2049
|
+
if (str === undefined)
|
|
2050
|
+
return this._version;
|
|
2051
|
+
this._version = str;
|
|
2052
|
+
flags = flags || "-V, --version";
|
|
2053
|
+
description = description || "output the version number";
|
|
2054
|
+
const versionOption = this.createOption(flags, description);
|
|
2055
|
+
this._versionOptionName = versionOption.attributeName();
|
|
2056
|
+
this._registerOption(versionOption);
|
|
2057
|
+
this.on("option:" + versionOption.name(), () => {
|
|
2058
|
+
this._outputConfiguration.writeOut(`${str}
|
|
2059
|
+
`);
|
|
2060
|
+
this._exit(0, "commander.version", str);
|
|
2061
|
+
});
|
|
2062
|
+
return this;
|
|
2063
|
+
}
|
|
2064
|
+
description(str, argsDescription) {
|
|
2065
|
+
if (str === undefined && argsDescription === undefined)
|
|
2066
|
+
return this._description;
|
|
2067
|
+
this._description = str;
|
|
2068
|
+
if (argsDescription) {
|
|
2069
|
+
this._argsDescription = argsDescription;
|
|
2070
|
+
}
|
|
2071
|
+
return this;
|
|
2072
|
+
}
|
|
2073
|
+
summary(str) {
|
|
2074
|
+
if (str === undefined)
|
|
2075
|
+
return this._summary;
|
|
2076
|
+
this._summary = str;
|
|
2077
|
+
return this;
|
|
2078
|
+
}
|
|
2079
|
+
alias(alias) {
|
|
2080
|
+
if (alias === undefined)
|
|
2081
|
+
return this._aliases[0];
|
|
2082
|
+
let command = this;
|
|
2083
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
2084
|
+
command = this.commands[this.commands.length - 1];
|
|
2085
|
+
}
|
|
2086
|
+
if (alias === command._name)
|
|
2087
|
+
throw new Error("Command alias can't be the same as its name");
|
|
2088
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
2089
|
+
if (matchingCommand) {
|
|
2090
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
2091
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
2092
|
+
}
|
|
2093
|
+
command._aliases.push(alias);
|
|
2094
|
+
return this;
|
|
2095
|
+
}
|
|
2096
|
+
aliases(aliases) {
|
|
2097
|
+
if (aliases === undefined)
|
|
2098
|
+
return this._aliases;
|
|
2099
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
2100
|
+
return this;
|
|
2101
|
+
}
|
|
2102
|
+
usage(str) {
|
|
2103
|
+
if (str === undefined) {
|
|
2104
|
+
if (this._usage)
|
|
2105
|
+
return this._usage;
|
|
2106
|
+
const args = this.registeredArguments.map((arg) => {
|
|
2107
|
+
return humanReadableArgName(arg);
|
|
2108
|
+
});
|
|
2109
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
2110
|
+
}
|
|
2111
|
+
this._usage = str;
|
|
2112
|
+
return this;
|
|
2113
|
+
}
|
|
2114
|
+
name(str) {
|
|
2115
|
+
if (str === undefined)
|
|
2116
|
+
return this._name;
|
|
2117
|
+
this._name = str;
|
|
2118
|
+
return this;
|
|
2119
|
+
}
|
|
2120
|
+
helpGroup(heading) {
|
|
2121
|
+
if (heading === undefined)
|
|
2122
|
+
return this._helpGroupHeading ?? "";
|
|
2123
|
+
this._helpGroupHeading = heading;
|
|
2124
|
+
return this;
|
|
2125
|
+
}
|
|
2126
|
+
commandsGroup(heading) {
|
|
2127
|
+
if (heading === undefined)
|
|
2128
|
+
return this._defaultCommandGroup ?? "";
|
|
2129
|
+
this._defaultCommandGroup = heading;
|
|
2130
|
+
return this;
|
|
2131
|
+
}
|
|
2132
|
+
optionsGroup(heading) {
|
|
2133
|
+
if (heading === undefined)
|
|
2134
|
+
return this._defaultOptionGroup ?? "";
|
|
2135
|
+
this._defaultOptionGroup = heading;
|
|
2136
|
+
return this;
|
|
2137
|
+
}
|
|
2138
|
+
_initOptionGroup(option) {
|
|
2139
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
2140
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
2141
|
+
}
|
|
2142
|
+
_initCommandGroup(cmd) {
|
|
2143
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
2144
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
2145
|
+
}
|
|
2146
|
+
nameFromFilename(filename) {
|
|
2147
|
+
this._name = path2.basename(filename, path2.extname(filename));
|
|
2148
|
+
return this;
|
|
2149
|
+
}
|
|
2150
|
+
executableDir(path3) {
|
|
2151
|
+
if (path3 === undefined)
|
|
2152
|
+
return this._executableDir;
|
|
2153
|
+
this._executableDir = path3;
|
|
2154
|
+
return this;
|
|
2155
|
+
}
|
|
2156
|
+
helpInformation(contextOptions) {
|
|
2157
|
+
const helper = this.createHelp();
|
|
2158
|
+
const context = this._getOutputContext(contextOptions);
|
|
2159
|
+
helper.prepareContext({
|
|
2160
|
+
error: context.error,
|
|
2161
|
+
helpWidth: context.helpWidth,
|
|
2162
|
+
outputHasColors: context.hasColors
|
|
2163
|
+
});
|
|
2164
|
+
const text = helper.formatHelp(this, helper);
|
|
2165
|
+
if (context.hasColors)
|
|
2166
|
+
return text;
|
|
2167
|
+
return this._outputConfiguration.stripColor(text);
|
|
2168
|
+
}
|
|
2169
|
+
_getOutputContext(contextOptions) {
|
|
2170
|
+
contextOptions = contextOptions || {};
|
|
2171
|
+
const error = !!contextOptions.error;
|
|
2172
|
+
let baseWrite;
|
|
2173
|
+
let hasColors;
|
|
2174
|
+
let helpWidth;
|
|
2175
|
+
if (error) {
|
|
2176
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
2177
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
2178
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
2179
|
+
} else {
|
|
2180
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
2181
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
2182
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
2183
|
+
}
|
|
2184
|
+
const write = (str) => {
|
|
2185
|
+
if (!hasColors)
|
|
2186
|
+
str = this._outputConfiguration.stripColor(str);
|
|
2187
|
+
return baseWrite(str);
|
|
2188
|
+
};
|
|
2189
|
+
return { error, write, hasColors, helpWidth };
|
|
2190
|
+
}
|
|
2191
|
+
outputHelp(contextOptions) {
|
|
2192
|
+
let deprecatedCallback;
|
|
2193
|
+
if (typeof contextOptions === "function") {
|
|
2194
|
+
deprecatedCallback = contextOptions;
|
|
2195
|
+
contextOptions = undefined;
|
|
2196
|
+
}
|
|
2197
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
2198
|
+
const eventContext = {
|
|
2199
|
+
error: outputContext.error,
|
|
2200
|
+
write: outputContext.write,
|
|
2201
|
+
command: this
|
|
2202
|
+
};
|
|
2203
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
2204
|
+
this.emit("beforeHelp", eventContext);
|
|
2205
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
2206
|
+
if (deprecatedCallback) {
|
|
2207
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
2208
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2209
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
outputContext.write(helpInformation);
|
|
2213
|
+
if (this._getHelpOption()?.long) {
|
|
2214
|
+
this.emit(this._getHelpOption().long);
|
|
2215
|
+
}
|
|
2216
|
+
this.emit("afterHelp", eventContext);
|
|
2217
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
2218
|
+
}
|
|
2219
|
+
helpOption(flags, description) {
|
|
2220
|
+
if (typeof flags === "boolean") {
|
|
2221
|
+
if (flags) {
|
|
2222
|
+
if (this._helpOption === null)
|
|
2223
|
+
this._helpOption = undefined;
|
|
2224
|
+
if (this._defaultOptionGroup) {
|
|
2225
|
+
this._initOptionGroup(this._getHelpOption());
|
|
2226
|
+
}
|
|
2227
|
+
} else {
|
|
2228
|
+
this._helpOption = null;
|
|
2229
|
+
}
|
|
2230
|
+
return this;
|
|
2231
|
+
}
|
|
2232
|
+
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
2233
|
+
if (flags || description)
|
|
2234
|
+
this._initOptionGroup(this._helpOption);
|
|
2235
|
+
return this;
|
|
2236
|
+
}
|
|
2237
|
+
_getHelpOption() {
|
|
2238
|
+
if (this._helpOption === undefined) {
|
|
2239
|
+
this.helpOption(undefined, undefined);
|
|
2240
|
+
}
|
|
2241
|
+
return this._helpOption;
|
|
2242
|
+
}
|
|
2243
|
+
addHelpOption(option) {
|
|
2244
|
+
this._helpOption = option;
|
|
2245
|
+
this._initOptionGroup(option);
|
|
2246
|
+
return this;
|
|
2247
|
+
}
|
|
2248
|
+
help(contextOptions) {
|
|
2249
|
+
this.outputHelp(contextOptions);
|
|
2250
|
+
let exitCode = Number(process4.exitCode ?? 0);
|
|
2251
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
2252
|
+
exitCode = 1;
|
|
2253
|
+
}
|
|
2254
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2255
|
+
}
|
|
2256
|
+
addHelpText(position, text) {
|
|
2257
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
2258
|
+
if (!allowedValues.includes(position)) {
|
|
2259
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
2260
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2261
|
+
}
|
|
2262
|
+
const helpEvent = `${position}Help`;
|
|
2263
|
+
this.on(helpEvent, (context) => {
|
|
2264
|
+
let helpStr;
|
|
2265
|
+
if (typeof text === "function") {
|
|
2266
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
2267
|
+
} else {
|
|
2268
|
+
helpStr = text;
|
|
2269
|
+
}
|
|
2270
|
+
if (helpStr) {
|
|
2271
|
+
context.write(`${helpStr}
|
|
2272
|
+
`);
|
|
2273
|
+
}
|
|
2274
|
+
});
|
|
2275
|
+
return this;
|
|
2276
|
+
}
|
|
2277
|
+
_outputHelpIfRequested(args) {
|
|
2278
|
+
const helpOption = this._getHelpOption();
|
|
2279
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
2280
|
+
if (helpRequested) {
|
|
2281
|
+
this.outputHelp();
|
|
2282
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
function incrementNodeInspectorPort(args) {
|
|
2287
|
+
return args.map((arg) => {
|
|
2288
|
+
if (!arg.startsWith("--inspect")) {
|
|
2289
|
+
return arg;
|
|
2290
|
+
}
|
|
2291
|
+
let debugOption;
|
|
2292
|
+
let debugHost = "127.0.0.1";
|
|
2293
|
+
let debugPort = "9229";
|
|
2294
|
+
let match;
|
|
2295
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
2296
|
+
debugOption = match[1];
|
|
2297
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
2298
|
+
debugOption = match[1];
|
|
2299
|
+
if (/^\d+$/.test(match[3])) {
|
|
2300
|
+
debugPort = match[3];
|
|
2301
|
+
} else {
|
|
2302
|
+
debugHost = match[3];
|
|
2303
|
+
}
|
|
2304
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
2305
|
+
debugOption = match[1];
|
|
2306
|
+
debugHost = match[3];
|
|
2307
|
+
debugPort = match[4];
|
|
2308
|
+
}
|
|
2309
|
+
if (debugOption && debugPort !== "0") {
|
|
2310
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
2311
|
+
}
|
|
2312
|
+
return arg;
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
function useColor() {
|
|
2316
|
+
if (process4.env.NO_COLOR || process4.env.FORCE_COLOR === "0" || process4.env.FORCE_COLOR === "false")
|
|
2317
|
+
return false;
|
|
2318
|
+
if (process4.env.FORCE_COLOR || process4.env.CLICOLOR_FORCE !== undefined)
|
|
2319
|
+
return true;
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
exports.Command = Command;
|
|
2323
|
+
exports.useColor = useColor;
|
|
2324
|
+
});
|
|
2325
|
+
|
|
2326
|
+
// ../../node_modules/commander/index.js
|
|
2327
|
+
var require_commander = __commonJS((exports) => {
|
|
2328
|
+
var { Argument } = require_argument();
|
|
2329
|
+
var { Command } = require_command();
|
|
2330
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
2331
|
+
var { Help } = require_help();
|
|
2332
|
+
var { Option } = require_option();
|
|
2333
|
+
exports.program = new Command;
|
|
2334
|
+
exports.createCommand = (name) => new Command(name);
|
|
2335
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
2336
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
2337
|
+
exports.Command = Command;
|
|
2338
|
+
exports.Option = Option;
|
|
2339
|
+
exports.Argument = Argument;
|
|
2340
|
+
exports.Help = Help;
|
|
2341
|
+
exports.CommanderError = CommanderError;
|
|
2342
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2343
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2344
|
+
});
|
|
2345
|
+
|
|
2346
|
+
// src/index.ts
|
|
2347
|
+
import fs3 from "fs";
|
|
2348
|
+
import path6 from "path";
|
|
2349
|
+
import { fileURLToPath } from "url";
|
|
2350
|
+
|
|
2351
|
+
// ../../node_modules/@inquirer/core/dist/lib/key.js
|
|
2352
|
+
var isUpKey = (key, keybindings = []) => key.name === "up" || keybindings.includes("vim") && key.name === "k" || keybindings.includes("emacs") && key.ctrl && key.name === "p";
|
|
2353
|
+
var isDownKey = (key, keybindings = []) => key.name === "down" || keybindings.includes("vim") && key.name === "j" || keybindings.includes("emacs") && key.ctrl && key.name === "n";
|
|
2354
|
+
var isSpaceKey = (key) => key.name === "space";
|
|
2355
|
+
var isBackspaceKey = (key) => key.name === "backspace";
|
|
2356
|
+
var isNumberKey = (key) => "1234567890".includes(key.name);
|
|
2357
|
+
var isEnterKey = (key) => key.name === "enter" || key.name === "return";
|
|
2358
|
+
// ../../node_modules/@inquirer/core/dist/lib/errors.js
|
|
2359
|
+
class AbortPromptError extends Error {
|
|
2360
|
+
name = "AbortPromptError";
|
|
2361
|
+
message = "Prompt was aborted";
|
|
2362
|
+
constructor(options) {
|
|
2363
|
+
super();
|
|
2364
|
+
this.cause = options?.cause;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
class CancelPromptError extends Error {
|
|
2369
|
+
name = "CancelPromptError";
|
|
2370
|
+
message = "Prompt was canceled";
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
class ExitPromptError extends Error {
|
|
2374
|
+
name = "ExitPromptError";
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
class HookError extends Error {
|
|
2378
|
+
name = "HookError";
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
class ValidationError extends Error {
|
|
2382
|
+
name = "ValidationError";
|
|
2383
|
+
}
|
|
2384
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-state.js
|
|
2385
|
+
import { AsyncResource as AsyncResource2 } from "node:async_hooks";
|
|
2386
|
+
|
|
2387
|
+
// ../../node_modules/@inquirer/core/dist/lib/hook-engine.js
|
|
2388
|
+
import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
|
|
2389
|
+
var hookStorage = new AsyncLocalStorage;
|
|
2390
|
+
function createStore(rl) {
|
|
2391
|
+
const store = {
|
|
2392
|
+
rl,
|
|
2393
|
+
hooks: [],
|
|
2394
|
+
hooksCleanup: [],
|
|
2395
|
+
hooksEffect: [],
|
|
2396
|
+
index: 0,
|
|
2397
|
+
handleChange() {}
|
|
2398
|
+
};
|
|
2399
|
+
return store;
|
|
2400
|
+
}
|
|
2401
|
+
function withHooks(rl, cb) {
|
|
2402
|
+
const store = createStore(rl);
|
|
2403
|
+
return hookStorage.run(store, () => {
|
|
2404
|
+
function cycle(render) {
|
|
2405
|
+
store.handleChange = () => {
|
|
2406
|
+
store.index = 0;
|
|
2407
|
+
render();
|
|
2408
|
+
};
|
|
2409
|
+
store.handleChange();
|
|
2410
|
+
}
|
|
2411
|
+
return cb(cycle);
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
function getStore() {
|
|
2415
|
+
const store = hookStorage.getStore();
|
|
2416
|
+
if (!store) {
|
|
2417
|
+
throw new HookError("[Inquirer] Hook functions can only be called from within a prompt");
|
|
2418
|
+
}
|
|
2419
|
+
return store;
|
|
2420
|
+
}
|
|
2421
|
+
function readline() {
|
|
2422
|
+
return getStore().rl;
|
|
2423
|
+
}
|
|
2424
|
+
function withUpdates(fn) {
|
|
2425
|
+
const wrapped = (...args) => {
|
|
2426
|
+
const store = getStore();
|
|
2427
|
+
let shouldUpdate = false;
|
|
2428
|
+
const oldHandleChange = store.handleChange;
|
|
2429
|
+
store.handleChange = () => {
|
|
2430
|
+
shouldUpdate = true;
|
|
2431
|
+
};
|
|
2432
|
+
const returnValue = fn(...args);
|
|
2433
|
+
if (shouldUpdate) {
|
|
2434
|
+
oldHandleChange();
|
|
2435
|
+
}
|
|
2436
|
+
store.handleChange = oldHandleChange;
|
|
2437
|
+
return returnValue;
|
|
2438
|
+
};
|
|
2439
|
+
return AsyncResource.bind(wrapped);
|
|
2440
|
+
}
|
|
2441
|
+
function withPointer(cb) {
|
|
2442
|
+
const store = getStore();
|
|
2443
|
+
const { index } = store;
|
|
2444
|
+
const pointer = {
|
|
2445
|
+
get() {
|
|
2446
|
+
return store.hooks[index];
|
|
2447
|
+
},
|
|
2448
|
+
set(value) {
|
|
2449
|
+
store.hooks[index] = value;
|
|
2450
|
+
},
|
|
2451
|
+
initialized: index in store.hooks
|
|
2452
|
+
};
|
|
2453
|
+
const returnValue = cb(pointer);
|
|
2454
|
+
store.index++;
|
|
2455
|
+
return returnValue;
|
|
2456
|
+
}
|
|
2457
|
+
function handleChange() {
|
|
2458
|
+
getStore().handleChange();
|
|
2459
|
+
}
|
|
2460
|
+
var effectScheduler = {
|
|
2461
|
+
queue(cb) {
|
|
2462
|
+
const store = getStore();
|
|
2463
|
+
const { index } = store;
|
|
2464
|
+
store.hooksEffect.push(() => {
|
|
2465
|
+
store.hooksCleanup[index]?.();
|
|
2466
|
+
const cleanFn = cb(readline());
|
|
2467
|
+
if (cleanFn != null && typeof cleanFn !== "function") {
|
|
2468
|
+
throw new ValidationError("useEffect return value must be a cleanup function or nothing.");
|
|
2469
|
+
}
|
|
2470
|
+
store.hooksCleanup[index] = cleanFn;
|
|
2471
|
+
});
|
|
2472
|
+
},
|
|
2473
|
+
run() {
|
|
2474
|
+
const store = getStore();
|
|
2475
|
+
withUpdates(() => {
|
|
2476
|
+
store.hooksEffect.forEach((effect) => {
|
|
2477
|
+
effect();
|
|
2478
|
+
});
|
|
2479
|
+
store.hooksEffect.length = 0;
|
|
2480
|
+
})();
|
|
2481
|
+
},
|
|
2482
|
+
clearAll() {
|
|
2483
|
+
const store = getStore();
|
|
2484
|
+
store.hooksCleanup.forEach((cleanFn) => {
|
|
2485
|
+
cleanFn?.();
|
|
2486
|
+
});
|
|
2487
|
+
store.hooksEffect.length = 0;
|
|
2488
|
+
store.hooksCleanup.length = 0;
|
|
2489
|
+
}
|
|
2490
|
+
};
|
|
2491
|
+
|
|
2492
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-state.js
|
|
2493
|
+
function isFactory(value) {
|
|
2494
|
+
return typeof value === "function";
|
|
2495
|
+
}
|
|
2496
|
+
function useState(defaultValue) {
|
|
2497
|
+
return withPointer((pointer) => {
|
|
2498
|
+
const setState = AsyncResource2.bind(function setState(newValue) {
|
|
2499
|
+
if (pointer.get() !== newValue) {
|
|
2500
|
+
pointer.set(newValue);
|
|
2501
|
+
handleChange();
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
if (pointer.initialized) {
|
|
2505
|
+
return [pointer.get(), setState];
|
|
2506
|
+
}
|
|
2507
|
+
const value = isFactory(defaultValue) ? defaultValue() : defaultValue;
|
|
2508
|
+
pointer.set(value);
|
|
2509
|
+
return [value, setState];
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-effect.js
|
|
2514
|
+
function useEffect(cb, depArray) {
|
|
2515
|
+
withPointer((pointer) => {
|
|
2516
|
+
const oldDeps = pointer.get();
|
|
2517
|
+
const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
2518
|
+
if (hasChanged) {
|
|
2519
|
+
effectScheduler.queue(cb);
|
|
2520
|
+
}
|
|
2521
|
+
pointer.set(depArray);
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
// ../../node_modules/@inquirer/core/dist/lib/theme.js
|
|
2526
|
+
import { styleText } from "node:util";
|
|
2527
|
+
|
|
2528
|
+
// ../../node_modules/@inquirer/figures/dist/index.js
|
|
2529
|
+
import process2 from "node:process";
|
|
2530
|
+
function isUnicodeSupported() {
|
|
2531
|
+
if (!process2.platform.startsWith("win")) {
|
|
2532
|
+
return process2.env["TERM"] !== "linux";
|
|
2533
|
+
}
|
|
2534
|
+
return Boolean(process2.env["CI"]) || Boolean(process2.env["WT_SESSION"]) || Boolean(process2.env["TERMINUS_SUBLIME"]) || process2.env["ConEmuTask"] === "{cmd::Cmder}" || process2.env["TERM_PROGRAM"] === "Terminus-Sublime" || process2.env["TERM_PROGRAM"] === "vscode" || process2.env["TERM"] === "xterm-256color" || process2.env["TERM"] === "alacritty" || process2.env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
|
|
2535
|
+
}
|
|
2536
|
+
var common = {
|
|
2537
|
+
circleQuestionMark: "(?)",
|
|
2538
|
+
questionMarkPrefix: "(?)",
|
|
2539
|
+
square: "█",
|
|
2540
|
+
squareDarkShade: "▓",
|
|
2541
|
+
squareMediumShade: "▒",
|
|
2542
|
+
squareLightShade: "░",
|
|
2543
|
+
squareTop: "▀",
|
|
2544
|
+
squareBottom: "▄",
|
|
2545
|
+
squareLeft: "▌",
|
|
2546
|
+
squareRight: "▐",
|
|
2547
|
+
squareCenter: "■",
|
|
2548
|
+
bullet: "●",
|
|
2549
|
+
dot: "․",
|
|
2550
|
+
ellipsis: "…",
|
|
2551
|
+
pointerSmall: "›",
|
|
2552
|
+
triangleUp: "▲",
|
|
2553
|
+
triangleUpSmall: "▴",
|
|
2554
|
+
triangleDown: "▼",
|
|
2555
|
+
triangleDownSmall: "▾",
|
|
2556
|
+
triangleLeftSmall: "◂",
|
|
2557
|
+
triangleRightSmall: "▸",
|
|
2558
|
+
home: "⌂",
|
|
2559
|
+
heart: "♥",
|
|
2560
|
+
musicNote: "♪",
|
|
2561
|
+
musicNoteBeamed: "♫",
|
|
2562
|
+
arrowUp: "↑",
|
|
2563
|
+
arrowDown: "↓",
|
|
2564
|
+
arrowLeft: "←",
|
|
2565
|
+
arrowRight: "→",
|
|
2566
|
+
arrowLeftRight: "↔",
|
|
2567
|
+
arrowUpDown: "↕",
|
|
2568
|
+
almostEqual: "≈",
|
|
2569
|
+
notEqual: "≠",
|
|
2570
|
+
lessOrEqual: "≤",
|
|
2571
|
+
greaterOrEqual: "≥",
|
|
2572
|
+
identical: "≡",
|
|
2573
|
+
infinity: "∞",
|
|
2574
|
+
subscriptZero: "₀",
|
|
2575
|
+
subscriptOne: "₁",
|
|
2576
|
+
subscriptTwo: "₂",
|
|
2577
|
+
subscriptThree: "₃",
|
|
2578
|
+
subscriptFour: "₄",
|
|
2579
|
+
subscriptFive: "₅",
|
|
2580
|
+
subscriptSix: "₆",
|
|
2581
|
+
subscriptSeven: "₇",
|
|
2582
|
+
subscriptEight: "₈",
|
|
2583
|
+
subscriptNine: "₉",
|
|
2584
|
+
oneHalf: "½",
|
|
2585
|
+
oneThird: "⅓",
|
|
2586
|
+
oneQuarter: "¼",
|
|
2587
|
+
oneFifth: "⅕",
|
|
2588
|
+
oneSixth: "⅙",
|
|
2589
|
+
oneEighth: "⅛",
|
|
2590
|
+
twoThirds: "⅔",
|
|
2591
|
+
twoFifths: "⅖",
|
|
2592
|
+
threeQuarters: "¾",
|
|
2593
|
+
threeFifths: "⅗",
|
|
2594
|
+
threeEighths: "⅜",
|
|
2595
|
+
fourFifths: "⅘",
|
|
2596
|
+
fiveSixths: "⅚",
|
|
2597
|
+
fiveEighths: "⅝",
|
|
2598
|
+
sevenEighths: "⅞",
|
|
2599
|
+
line: "─",
|
|
2600
|
+
lineBold: "━",
|
|
2601
|
+
lineDouble: "═",
|
|
2602
|
+
lineDashed0: "┄",
|
|
2603
|
+
lineDashed1: "┅",
|
|
2604
|
+
lineDashed2: "┈",
|
|
2605
|
+
lineDashed3: "┉",
|
|
2606
|
+
lineDashed4: "╌",
|
|
2607
|
+
lineDashed5: "╍",
|
|
2608
|
+
lineDashed6: "╴",
|
|
2609
|
+
lineDashed7: "╶",
|
|
2610
|
+
lineDashed8: "╸",
|
|
2611
|
+
lineDashed9: "╺",
|
|
2612
|
+
lineDashed10: "╼",
|
|
2613
|
+
lineDashed11: "╾",
|
|
2614
|
+
lineDashed12: "−",
|
|
2615
|
+
lineDashed13: "–",
|
|
2616
|
+
lineDashed14: "‐",
|
|
2617
|
+
lineDashed15: "⁃",
|
|
2618
|
+
lineVertical: "│",
|
|
2619
|
+
lineVerticalBold: "┃",
|
|
2620
|
+
lineVerticalDouble: "║",
|
|
2621
|
+
lineVerticalDashed0: "┆",
|
|
2622
|
+
lineVerticalDashed1: "┇",
|
|
2623
|
+
lineVerticalDashed2: "┊",
|
|
2624
|
+
lineVerticalDashed3: "┋",
|
|
2625
|
+
lineVerticalDashed4: "╎",
|
|
2626
|
+
lineVerticalDashed5: "╏",
|
|
2627
|
+
lineVerticalDashed6: "╵",
|
|
2628
|
+
lineVerticalDashed7: "╷",
|
|
2629
|
+
lineVerticalDashed8: "╹",
|
|
2630
|
+
lineVerticalDashed9: "╻",
|
|
2631
|
+
lineVerticalDashed10: "╽",
|
|
2632
|
+
lineVerticalDashed11: "╿",
|
|
2633
|
+
lineDownLeft: "┐",
|
|
2634
|
+
lineDownLeftArc: "╮",
|
|
2635
|
+
lineDownBoldLeftBold: "┓",
|
|
2636
|
+
lineDownBoldLeft: "┒",
|
|
2637
|
+
lineDownLeftBold: "┑",
|
|
2638
|
+
lineDownDoubleLeftDouble: "╗",
|
|
2639
|
+
lineDownDoubleLeft: "╖",
|
|
2640
|
+
lineDownLeftDouble: "╕",
|
|
2641
|
+
lineDownRight: "┌",
|
|
2642
|
+
lineDownRightArc: "╭",
|
|
2643
|
+
lineDownBoldRightBold: "┏",
|
|
2644
|
+
lineDownBoldRight: "┎",
|
|
2645
|
+
lineDownRightBold: "┍",
|
|
2646
|
+
lineDownDoubleRightDouble: "╔",
|
|
2647
|
+
lineDownDoubleRight: "╓",
|
|
2648
|
+
lineDownRightDouble: "╒",
|
|
2649
|
+
lineUpLeft: "┘",
|
|
2650
|
+
lineUpLeftArc: "╯",
|
|
2651
|
+
lineUpBoldLeftBold: "┛",
|
|
2652
|
+
lineUpBoldLeft: "┚",
|
|
2653
|
+
lineUpLeftBold: "┙",
|
|
2654
|
+
lineUpDoubleLeftDouble: "╝",
|
|
2655
|
+
lineUpDoubleLeft: "╜",
|
|
2656
|
+
lineUpLeftDouble: "╛",
|
|
2657
|
+
lineUpRight: "└",
|
|
2658
|
+
lineUpRightArc: "╰",
|
|
2659
|
+
lineUpBoldRightBold: "┗",
|
|
2660
|
+
lineUpBoldRight: "┖",
|
|
2661
|
+
lineUpRightBold: "┕",
|
|
2662
|
+
lineUpDoubleRightDouble: "╚",
|
|
2663
|
+
lineUpDoubleRight: "╙",
|
|
2664
|
+
lineUpRightDouble: "╘",
|
|
2665
|
+
lineUpDownLeft: "┤",
|
|
2666
|
+
lineUpBoldDownBoldLeftBold: "┫",
|
|
2667
|
+
lineUpBoldDownBoldLeft: "┨",
|
|
2668
|
+
lineUpDownLeftBold: "┥",
|
|
2669
|
+
lineUpBoldDownLeftBold: "┩",
|
|
2670
|
+
lineUpDownBoldLeftBold: "┪",
|
|
2671
|
+
lineUpDownBoldLeft: "┧",
|
|
2672
|
+
lineUpBoldDownLeft: "┦",
|
|
2673
|
+
lineUpDoubleDownDoubleLeftDouble: "╣",
|
|
2674
|
+
lineUpDoubleDownDoubleLeft: "╢",
|
|
2675
|
+
lineUpDownLeftDouble: "╡",
|
|
2676
|
+
lineUpDownRight: "├",
|
|
2677
|
+
lineUpBoldDownBoldRightBold: "┣",
|
|
2678
|
+
lineUpBoldDownBoldRight: "┠",
|
|
2679
|
+
lineUpDownRightBold: "┝",
|
|
2680
|
+
lineUpBoldDownRightBold: "┡",
|
|
2681
|
+
lineUpDownBoldRightBold: "┢",
|
|
2682
|
+
lineUpDownBoldRight: "┟",
|
|
2683
|
+
lineUpBoldDownRight: "┞",
|
|
2684
|
+
lineUpDoubleDownDoubleRightDouble: "╠",
|
|
2685
|
+
lineUpDoubleDownDoubleRight: "╟",
|
|
2686
|
+
lineUpDownRightDouble: "╞",
|
|
2687
|
+
lineDownLeftRight: "┬",
|
|
2688
|
+
lineDownBoldLeftBoldRightBold: "┳",
|
|
2689
|
+
lineDownLeftBoldRightBold: "┯",
|
|
2690
|
+
lineDownBoldLeftRight: "┰",
|
|
2691
|
+
lineDownBoldLeftBoldRight: "┱",
|
|
2692
|
+
lineDownBoldLeftRightBold: "┲",
|
|
2693
|
+
lineDownLeftRightBold: "┮",
|
|
2694
|
+
lineDownLeftBoldRight: "┭",
|
|
2695
|
+
lineDownDoubleLeftDoubleRightDouble: "╦",
|
|
2696
|
+
lineDownDoubleLeftRight: "╥",
|
|
2697
|
+
lineDownLeftDoubleRightDouble: "╤",
|
|
2698
|
+
lineUpLeftRight: "┴",
|
|
2699
|
+
lineUpBoldLeftBoldRightBold: "┻",
|
|
2700
|
+
lineUpLeftBoldRightBold: "┷",
|
|
2701
|
+
lineUpBoldLeftRight: "┸",
|
|
2702
|
+
lineUpBoldLeftBoldRight: "┹",
|
|
2703
|
+
lineUpBoldLeftRightBold: "┺",
|
|
2704
|
+
lineUpLeftRightBold: "┶",
|
|
2705
|
+
lineUpLeftBoldRight: "┵",
|
|
2706
|
+
lineUpDoubleLeftDoubleRightDouble: "╩",
|
|
2707
|
+
lineUpDoubleLeftRight: "╨",
|
|
2708
|
+
lineUpLeftDoubleRightDouble: "╧",
|
|
2709
|
+
lineUpDownLeftRight: "┼",
|
|
2710
|
+
lineUpBoldDownBoldLeftBoldRightBold: "╋",
|
|
2711
|
+
lineUpDownBoldLeftBoldRightBold: "╈",
|
|
2712
|
+
lineUpBoldDownLeftBoldRightBold: "╇",
|
|
2713
|
+
lineUpBoldDownBoldLeftRightBold: "╊",
|
|
2714
|
+
lineUpBoldDownBoldLeftBoldRight: "╉",
|
|
2715
|
+
lineUpBoldDownLeftRight: "╀",
|
|
2716
|
+
lineUpDownBoldLeftRight: "╁",
|
|
2717
|
+
lineUpDownLeftBoldRight: "┽",
|
|
2718
|
+
lineUpDownLeftRightBold: "┾",
|
|
2719
|
+
lineUpBoldDownBoldLeftRight: "╂",
|
|
2720
|
+
lineUpDownLeftBoldRightBold: "┿",
|
|
2721
|
+
lineUpBoldDownLeftBoldRight: "╃",
|
|
2722
|
+
lineUpBoldDownLeftRightBold: "╄",
|
|
2723
|
+
lineUpDownBoldLeftBoldRight: "╅",
|
|
2724
|
+
lineUpDownBoldLeftRightBold: "╆",
|
|
2725
|
+
lineUpDoubleDownDoubleLeftDoubleRightDouble: "╬",
|
|
2726
|
+
lineUpDoubleDownDoubleLeftRight: "╫",
|
|
2727
|
+
lineUpDownLeftDoubleRightDouble: "╪",
|
|
2728
|
+
lineCross: "╳",
|
|
2729
|
+
lineBackslash: "╲",
|
|
2730
|
+
lineSlash: "╱"
|
|
2731
|
+
};
|
|
2732
|
+
var specialMainSymbols = {
|
|
2733
|
+
tick: "✔",
|
|
2734
|
+
info: "ℹ",
|
|
2735
|
+
warning: "⚠",
|
|
2736
|
+
cross: "✘",
|
|
2737
|
+
squareSmall: "◻",
|
|
2738
|
+
squareSmallFilled: "◼",
|
|
2739
|
+
circle: "◯",
|
|
2740
|
+
circleFilled: "◉",
|
|
2741
|
+
circleDotted: "◌",
|
|
2742
|
+
circleDouble: "◎",
|
|
2743
|
+
circleCircle: "ⓞ",
|
|
2744
|
+
circleCross: "ⓧ",
|
|
2745
|
+
circlePipe: "Ⓘ",
|
|
2746
|
+
radioOn: "◉",
|
|
2747
|
+
radioOff: "◯",
|
|
2748
|
+
checkboxOn: "☒",
|
|
2749
|
+
checkboxOff: "☐",
|
|
2750
|
+
checkboxCircleOn: "ⓧ",
|
|
2751
|
+
checkboxCircleOff: "Ⓘ",
|
|
2752
|
+
pointer: "❯",
|
|
2753
|
+
triangleUpOutline: "△",
|
|
2754
|
+
triangleLeft: "◀",
|
|
2755
|
+
triangleRight: "▶",
|
|
2756
|
+
lozenge: "◆",
|
|
2757
|
+
lozengeOutline: "◇",
|
|
2758
|
+
hamburger: "☰",
|
|
2759
|
+
smiley: "㋡",
|
|
2760
|
+
mustache: "෴",
|
|
2761
|
+
star: "★",
|
|
2762
|
+
play: "▶",
|
|
2763
|
+
nodejs: "⬢",
|
|
2764
|
+
oneSeventh: "⅐",
|
|
2765
|
+
oneNinth: "⅑",
|
|
2766
|
+
oneTenth: "⅒"
|
|
2767
|
+
};
|
|
2768
|
+
var specialFallbackSymbols = {
|
|
2769
|
+
tick: "√",
|
|
2770
|
+
info: "i",
|
|
2771
|
+
warning: "‼",
|
|
2772
|
+
cross: "×",
|
|
2773
|
+
squareSmall: "□",
|
|
2774
|
+
squareSmallFilled: "■",
|
|
2775
|
+
circle: "( )",
|
|
2776
|
+
circleFilled: "(*)",
|
|
2777
|
+
circleDotted: "( )",
|
|
2778
|
+
circleDouble: "( )",
|
|
2779
|
+
circleCircle: "(○)",
|
|
2780
|
+
circleCross: "(×)",
|
|
2781
|
+
circlePipe: "(│)",
|
|
2782
|
+
radioOn: "(*)",
|
|
2783
|
+
radioOff: "( )",
|
|
2784
|
+
checkboxOn: "[×]",
|
|
2785
|
+
checkboxOff: "[ ]",
|
|
2786
|
+
checkboxCircleOn: "(×)",
|
|
2787
|
+
checkboxCircleOff: "( )",
|
|
2788
|
+
pointer: ">",
|
|
2789
|
+
triangleUpOutline: "∆",
|
|
2790
|
+
triangleLeft: "◄",
|
|
2791
|
+
triangleRight: "►",
|
|
2792
|
+
lozenge: "♦",
|
|
2793
|
+
lozengeOutline: "◊",
|
|
2794
|
+
hamburger: "≡",
|
|
2795
|
+
smiley: "☺",
|
|
2796
|
+
mustache: "┌─┐",
|
|
2797
|
+
star: "✶",
|
|
2798
|
+
play: "►",
|
|
2799
|
+
nodejs: "♦",
|
|
2800
|
+
oneSeventh: "1/7",
|
|
2801
|
+
oneNinth: "1/9",
|
|
2802
|
+
oneTenth: "1/10"
|
|
2803
|
+
};
|
|
2804
|
+
var mainSymbols = {
|
|
2805
|
+
...common,
|
|
2806
|
+
...specialMainSymbols
|
|
2807
|
+
};
|
|
2808
|
+
var fallbackSymbols = {
|
|
2809
|
+
...common,
|
|
2810
|
+
...specialFallbackSymbols
|
|
2811
|
+
};
|
|
2812
|
+
var shouldUseMain = isUnicodeSupported();
|
|
2813
|
+
var figures = shouldUseMain ? mainSymbols : fallbackSymbols;
|
|
2814
|
+
var dist_default = figures;
|
|
2815
|
+
var replacements = Object.entries(specialMainSymbols);
|
|
2816
|
+
|
|
2817
|
+
// ../../node_modules/@inquirer/core/dist/lib/theme.js
|
|
2818
|
+
var defaultTheme = {
|
|
2819
|
+
prefix: {
|
|
2820
|
+
idle: styleText("blue", "?"),
|
|
2821
|
+
done: styleText("green", dist_default.tick)
|
|
2822
|
+
},
|
|
2823
|
+
spinner: {
|
|
2824
|
+
interval: 80,
|
|
2825
|
+
frames: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].map((frame) => styleText("yellow", frame))
|
|
2826
|
+
},
|
|
2827
|
+
style: {
|
|
2828
|
+
answer: (text) => styleText("cyan", text),
|
|
2829
|
+
message: (text) => styleText("bold", text),
|
|
2830
|
+
error: (text) => styleText("red", `> ${text}`),
|
|
2831
|
+
defaultAnswer: (text) => styleText("dim", `(${text})`),
|
|
2832
|
+
help: (text) => styleText("dim", text),
|
|
2833
|
+
highlight: (text) => styleText("cyan", text),
|
|
2834
|
+
key: (text) => styleText("cyan", styleText("bold", `<${text}>`))
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
|
|
2838
|
+
// ../../node_modules/@inquirer/core/dist/lib/make-theme.js
|
|
2839
|
+
function isPlainObject(value) {
|
|
2840
|
+
if (typeof value !== "object" || value === null)
|
|
2841
|
+
return false;
|
|
2842
|
+
let proto = value;
|
|
2843
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
2844
|
+
proto = Object.getPrototypeOf(proto);
|
|
2845
|
+
}
|
|
2846
|
+
return Object.getPrototypeOf(value) === proto;
|
|
2847
|
+
}
|
|
2848
|
+
function deepMerge(...objects) {
|
|
2849
|
+
const output = {};
|
|
2850
|
+
for (const obj of objects) {
|
|
2851
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2852
|
+
const prevValue = output[key];
|
|
2853
|
+
output[key] = isPlainObject(prevValue) && isPlainObject(value) ? deepMerge(prevValue, value) : value;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
return output;
|
|
2857
|
+
}
|
|
2858
|
+
function makeTheme(...themes) {
|
|
2859
|
+
const themesToMerge = [
|
|
2860
|
+
defaultTheme,
|
|
2861
|
+
...themes.filter((theme) => theme != null)
|
|
2862
|
+
];
|
|
2863
|
+
return deepMerge(...themesToMerge);
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-prefix.js
|
|
2867
|
+
function usePrefix({ status = "idle", theme }) {
|
|
2868
|
+
const [showLoader, setShowLoader] = useState(false);
|
|
2869
|
+
const [tick, setTick] = useState(0);
|
|
2870
|
+
const { prefix, spinner } = makeTheme(theme);
|
|
2871
|
+
useEffect(() => {
|
|
2872
|
+
if (status === "loading") {
|
|
2873
|
+
let tickInterval;
|
|
2874
|
+
let inc = -1;
|
|
2875
|
+
const delayTimeout = setTimeout(() => {
|
|
2876
|
+
setShowLoader(true);
|
|
2877
|
+
tickInterval = setInterval(() => {
|
|
2878
|
+
inc = inc + 1;
|
|
2879
|
+
setTick(inc % spinner.frames.length);
|
|
2880
|
+
}, spinner.interval);
|
|
2881
|
+
}, 300);
|
|
2882
|
+
return () => {
|
|
2883
|
+
clearTimeout(delayTimeout);
|
|
2884
|
+
clearInterval(tickInterval);
|
|
2885
|
+
};
|
|
2886
|
+
} else {
|
|
2887
|
+
setShowLoader(false);
|
|
2888
|
+
}
|
|
2889
|
+
}, [status]);
|
|
2890
|
+
if (showLoader) {
|
|
2891
|
+
return spinner.frames[tick];
|
|
2892
|
+
}
|
|
2893
|
+
const iconName = status === "loading" ? "idle" : status;
|
|
2894
|
+
return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix["idle"];
|
|
2895
|
+
}
|
|
2896
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-memo.js
|
|
2897
|
+
function useMemo(fn, dependencies) {
|
|
2898
|
+
return withPointer((pointer) => {
|
|
2899
|
+
const prev = pointer.get();
|
|
2900
|
+
if (!prev || prev.dependencies.length !== dependencies.length || prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
|
|
2901
|
+
const value = fn();
|
|
2902
|
+
pointer.set({ value, dependencies });
|
|
2903
|
+
return value;
|
|
2904
|
+
}
|
|
2905
|
+
return prev.value;
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-ref.js
|
|
2909
|
+
function useRef(val) {
|
|
2910
|
+
return useState({ current: val })[0];
|
|
2911
|
+
}
|
|
2912
|
+
// ../../node_modules/@inquirer/core/dist/lib/use-keypress.js
|
|
2913
|
+
function useKeypress(userHandler) {
|
|
2914
|
+
const signal = useRef(userHandler);
|
|
2915
|
+
signal.current = userHandler;
|
|
2916
|
+
useEffect((rl) => {
|
|
2917
|
+
let ignore = false;
|
|
2918
|
+
const handler = withUpdates((_input, event) => {
|
|
2919
|
+
if (ignore)
|
|
2920
|
+
return;
|
|
2921
|
+
signal.current(event, rl);
|
|
2922
|
+
});
|
|
2923
|
+
rl.input.on("keypress", handler);
|
|
2924
|
+
return () => {
|
|
2925
|
+
ignore = true;
|
|
2926
|
+
rl.input.removeListener("keypress", handler);
|
|
2927
|
+
};
|
|
2928
|
+
}, []);
|
|
2929
|
+
}
|
|
2930
|
+
// ../../node_modules/@inquirer/core/dist/lib/utils.js
|
|
2931
|
+
var import_cli_width = __toESM(require_cli_width(), 1);
|
|
2932
|
+
|
|
2933
|
+
// ../../node_modules/fast-string-truncated-width/dist/utils.js
|
|
2934
|
+
var getCodePointsLength = (() => {
|
|
2935
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
2936
|
+
return (input) => {
|
|
2937
|
+
let surrogatePairsNr = 0;
|
|
2938
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
2939
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
2940
|
+
surrogatePairsNr += 1;
|
|
2941
|
+
}
|
|
2942
|
+
return input.length - surrogatePairsNr;
|
|
2943
|
+
};
|
|
2944
|
+
})();
|
|
2945
|
+
var isFullWidth = (x) => {
|
|
2946
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
2947
|
+
};
|
|
2948
|
+
var isWideNotCJKTNotEmoji = (x) => {
|
|
2949
|
+
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
2950
|
+
};
|
|
2951
|
+
|
|
2952
|
+
// ../../node_modules/fast-string-truncated-width/dist/index.js
|
|
2953
|
+
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
2954
|
+
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
2955
|
+
var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
|
|
2956
|
+
var TAB_RE = /\t{1,1000}/y;
|
|
2957
|
+
var EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
2958
|
+
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
2959
|
+
var MODIFIER_RE = /\p{M}+/gu;
|
|
2960
|
+
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
2961
|
+
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
2962
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
2963
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
2964
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
2965
|
+
const ANSI_WIDTH = 0;
|
|
2966
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
2967
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
2968
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
2969
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
2970
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
2971
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
2972
|
+
const PARSE_BLOCKS = [
|
|
2973
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
2974
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
2975
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
2976
|
+
[TAB_RE, TAB_WIDTH],
|
|
2977
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
2978
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
2979
|
+
];
|
|
2980
|
+
let indexPrev = 0;
|
|
2981
|
+
let index = 0;
|
|
2982
|
+
let length = input.length;
|
|
2983
|
+
let lengthExtra = 0;
|
|
2984
|
+
let truncationEnabled = false;
|
|
2985
|
+
let truncationIndex = length;
|
|
2986
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
2987
|
+
let unmatchedStart = 0;
|
|
2988
|
+
let unmatchedEnd = 0;
|
|
2989
|
+
let width = 0;
|
|
2990
|
+
let widthExtra = 0;
|
|
2991
|
+
outer:
|
|
2992
|
+
while (true) {
|
|
2993
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
2994
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
2995
|
+
lengthExtra = 0;
|
|
2996
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
2997
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
2998
|
+
if (isFullWidth(codePoint)) {
|
|
2999
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
3000
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
3001
|
+
widthExtra = WIDE_WIDTH;
|
|
3002
|
+
} else {
|
|
3003
|
+
widthExtra = REGULAR_WIDTH;
|
|
3004
|
+
}
|
|
3005
|
+
if (width + widthExtra > truncationLimit) {
|
|
3006
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
3007
|
+
}
|
|
3008
|
+
if (width + widthExtra > LIMIT) {
|
|
3009
|
+
truncationEnabled = true;
|
|
3010
|
+
break outer;
|
|
3011
|
+
}
|
|
3012
|
+
lengthExtra += char.length;
|
|
3013
|
+
width += widthExtra;
|
|
3014
|
+
}
|
|
3015
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
3016
|
+
}
|
|
3017
|
+
if (index >= length) {
|
|
3018
|
+
break outer;
|
|
3019
|
+
}
|
|
3020
|
+
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
3021
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
3022
|
+
BLOCK_RE.lastIndex = index;
|
|
3023
|
+
if (BLOCK_RE.test(input)) {
|
|
3024
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
3025
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
3026
|
+
if (width + widthExtra > truncationLimit) {
|
|
3027
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
3028
|
+
}
|
|
3029
|
+
if (width + widthExtra > LIMIT) {
|
|
3030
|
+
truncationEnabled = true;
|
|
3031
|
+
break outer;
|
|
3032
|
+
}
|
|
3033
|
+
width += widthExtra;
|
|
3034
|
+
unmatchedStart = indexPrev;
|
|
3035
|
+
unmatchedEnd = index;
|
|
3036
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
3037
|
+
continue outer;
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
index += 1;
|
|
3041
|
+
}
|
|
3042
|
+
return {
|
|
3043
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
3044
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
3045
|
+
truncated: truncationEnabled,
|
|
3046
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
3047
|
+
};
|
|
3048
|
+
};
|
|
3049
|
+
var dist_default2 = getStringTruncatedWidth;
|
|
3050
|
+
|
|
3051
|
+
// ../../node_modules/fast-string-width/dist/index.js
|
|
3052
|
+
var NO_TRUNCATION2 = {
|
|
3053
|
+
limit: Infinity,
|
|
3054
|
+
ellipsis: "",
|
|
3055
|
+
ellipsisWidth: 0
|
|
3056
|
+
};
|
|
3057
|
+
var fastStringWidth = (input, options = {}) => {
|
|
3058
|
+
return dist_default2(input, NO_TRUNCATION2, options).width;
|
|
3059
|
+
};
|
|
3060
|
+
var dist_default3 = fastStringWidth;
|
|
3061
|
+
|
|
3062
|
+
// ../../node_modules/fast-wrap-ansi/lib/main.js
|
|
3063
|
+
var ESC = "\x1B";
|
|
3064
|
+
var CSI = "";
|
|
3065
|
+
var END_CODE = 39;
|
|
3066
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
3067
|
+
var ANSI_CSI = "[";
|
|
3068
|
+
var ANSI_OSC = "]";
|
|
3069
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
3070
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
3071
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
3072
|
+
var getClosingCode = (openingCode) => {
|
|
3073
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
3074
|
+
return 39;
|
|
3075
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
3076
|
+
return 39;
|
|
3077
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
3078
|
+
return 49;
|
|
3079
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
3080
|
+
return 49;
|
|
3081
|
+
if (openingCode === 1 || openingCode === 2)
|
|
3082
|
+
return 22;
|
|
3083
|
+
if (openingCode === 3)
|
|
3084
|
+
return 23;
|
|
3085
|
+
if (openingCode === 4)
|
|
3086
|
+
return 24;
|
|
3087
|
+
if (openingCode === 7)
|
|
3088
|
+
return 27;
|
|
3089
|
+
if (openingCode === 8)
|
|
3090
|
+
return 28;
|
|
3091
|
+
if (openingCode === 9)
|
|
3092
|
+
return 29;
|
|
3093
|
+
if (openingCode === 0)
|
|
3094
|
+
return 0;
|
|
3095
|
+
return;
|
|
3096
|
+
};
|
|
3097
|
+
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
3098
|
+
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
3099
|
+
var wrapWord = (rows, word, columns) => {
|
|
3100
|
+
const characters = word[Symbol.iterator]();
|
|
3101
|
+
let isInsideEscape = false;
|
|
3102
|
+
let isInsideLinkEscape = false;
|
|
3103
|
+
let lastRow = rows.at(-1);
|
|
3104
|
+
let visible = lastRow === undefined ? 0 : dist_default3(lastRow);
|
|
3105
|
+
let currentCharacter = characters.next();
|
|
3106
|
+
let nextCharacter = characters.next();
|
|
3107
|
+
let rawCharacterIndex = 0;
|
|
3108
|
+
while (!currentCharacter.done) {
|
|
3109
|
+
const character = currentCharacter.value;
|
|
3110
|
+
const characterLength = dist_default3(character);
|
|
3111
|
+
if (visible + characterLength <= columns) {
|
|
3112
|
+
rows[rows.length - 1] += character;
|
|
3113
|
+
} else {
|
|
3114
|
+
rows.push(character);
|
|
3115
|
+
visible = 0;
|
|
3116
|
+
}
|
|
3117
|
+
if (character === ESC || character === CSI) {
|
|
3118
|
+
isInsideEscape = true;
|
|
3119
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
3120
|
+
}
|
|
3121
|
+
if (isInsideEscape) {
|
|
3122
|
+
if (isInsideLinkEscape) {
|
|
3123
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
3124
|
+
isInsideEscape = false;
|
|
3125
|
+
isInsideLinkEscape = false;
|
|
3126
|
+
}
|
|
3127
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
3128
|
+
isInsideEscape = false;
|
|
3129
|
+
}
|
|
3130
|
+
} else {
|
|
3131
|
+
visible += characterLength;
|
|
3132
|
+
if (visible === columns && !nextCharacter.done) {
|
|
3133
|
+
rows.push("");
|
|
3134
|
+
visible = 0;
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
currentCharacter = nextCharacter;
|
|
3138
|
+
nextCharacter = characters.next();
|
|
3139
|
+
rawCharacterIndex += character.length;
|
|
3140
|
+
}
|
|
3141
|
+
lastRow = rows.at(-1);
|
|
3142
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
3143
|
+
rows[rows.length - 2] += rows.pop();
|
|
3144
|
+
}
|
|
3145
|
+
};
|
|
3146
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
3147
|
+
const words = string.split(" ");
|
|
3148
|
+
let last = words.length;
|
|
3149
|
+
while (last) {
|
|
3150
|
+
if (dist_default3(words[last - 1])) {
|
|
3151
|
+
break;
|
|
3152
|
+
}
|
|
3153
|
+
last--;
|
|
3154
|
+
}
|
|
3155
|
+
if (last === words.length) {
|
|
3156
|
+
return string;
|
|
3157
|
+
}
|
|
3158
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
3159
|
+
};
|
|
3160
|
+
var exec = (string, columns, options = {}) => {
|
|
3161
|
+
if (options.trim !== false && string.trim() === "") {
|
|
3162
|
+
return "";
|
|
3163
|
+
}
|
|
3164
|
+
let returnValue = "";
|
|
3165
|
+
let escapeCode;
|
|
3166
|
+
let escapeUrl;
|
|
3167
|
+
const words = string.split(" ");
|
|
3168
|
+
let rows = [""];
|
|
3169
|
+
let rowLength = 0;
|
|
3170
|
+
for (let index = 0;index < words.length; index++) {
|
|
3171
|
+
const word = words[index];
|
|
3172
|
+
if (options.trim !== false) {
|
|
3173
|
+
const row = rows.at(-1) ?? "";
|
|
3174
|
+
const trimmed = row.trimStart();
|
|
3175
|
+
if (row.length !== trimmed.length) {
|
|
3176
|
+
rows[rows.length - 1] = trimmed;
|
|
3177
|
+
rowLength = dist_default3(trimmed);
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
if (index !== 0) {
|
|
3181
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
3182
|
+
rows.push("");
|
|
3183
|
+
rowLength = 0;
|
|
3184
|
+
}
|
|
3185
|
+
if (rowLength || options.trim === false) {
|
|
3186
|
+
rows[rows.length - 1] += " ";
|
|
3187
|
+
rowLength++;
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
const wordLength = dist_default3(word);
|
|
3191
|
+
if (options.hard && wordLength > columns) {
|
|
3192
|
+
const remainingColumns = columns - rowLength;
|
|
3193
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
3194
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
3195
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
3196
|
+
rows.push("");
|
|
3197
|
+
}
|
|
3198
|
+
wrapWord(rows, word, columns);
|
|
3199
|
+
rowLength = dist_default3(rows.at(-1) ?? "");
|
|
3200
|
+
continue;
|
|
3201
|
+
}
|
|
3202
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
3203
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
3204
|
+
wrapWord(rows, word, columns);
|
|
3205
|
+
rowLength = dist_default3(rows.at(-1) ?? "");
|
|
3206
|
+
continue;
|
|
3207
|
+
}
|
|
3208
|
+
rows.push("");
|
|
3209
|
+
rowLength = 0;
|
|
3210
|
+
}
|
|
3211
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
3212
|
+
wrapWord(rows, word, columns);
|
|
3213
|
+
rowLength = dist_default3(rows.at(-1) ?? "");
|
|
3214
|
+
continue;
|
|
3215
|
+
}
|
|
3216
|
+
rows[rows.length - 1] += word;
|
|
3217
|
+
rowLength += wordLength;
|
|
3218
|
+
}
|
|
3219
|
+
if (options.trim !== false) {
|
|
3220
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
3221
|
+
}
|
|
3222
|
+
const preString = rows.join(`
|
|
3223
|
+
`);
|
|
3224
|
+
let inSurrogate = false;
|
|
3225
|
+
for (let i = 0;i < preString.length; i++) {
|
|
3226
|
+
const character = preString[i];
|
|
3227
|
+
returnValue += character;
|
|
3228
|
+
if (!inSurrogate) {
|
|
3229
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
3230
|
+
if (inSurrogate) {
|
|
3231
|
+
continue;
|
|
3232
|
+
}
|
|
3233
|
+
} else {
|
|
3234
|
+
inSurrogate = false;
|
|
3235
|
+
}
|
|
3236
|
+
if (character === ESC || character === CSI) {
|
|
3237
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
3238
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
3239
|
+
const groups = groupsResult?.groups;
|
|
3240
|
+
if (groups?.code !== undefined) {
|
|
3241
|
+
const code = Number.parseFloat(groups.code);
|
|
3242
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
3243
|
+
} else if (groups?.uri !== undefined) {
|
|
3244
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
if (preString[i + 1] === `
|
|
3248
|
+
`) {
|
|
3249
|
+
if (escapeUrl) {
|
|
3250
|
+
returnValue += wrapAnsiHyperlink("");
|
|
3251
|
+
}
|
|
3252
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
3253
|
+
if (escapeCode && closingCode) {
|
|
3254
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
3255
|
+
}
|
|
3256
|
+
} else if (character === `
|
|
3257
|
+
`) {
|
|
3258
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
3259
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
3260
|
+
}
|
|
3261
|
+
if (escapeUrl) {
|
|
3262
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
return returnValue;
|
|
3267
|
+
};
|
|
3268
|
+
var CRLF_OR_LF = /\r?\n/;
|
|
3269
|
+
function wrapAnsi(string, columns, options) {
|
|
3270
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
3271
|
+
`);
|
|
3272
|
+
}
|
|
3273
|
+
|
|
3274
|
+
// ../../node_modules/@inquirer/core/dist/lib/utils.js
|
|
3275
|
+
function breakLines(content, width) {
|
|
3276
|
+
return content.split(`
|
|
3277
|
+
`).flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true }).split(`
|
|
3278
|
+
`).map((str) => str.trimEnd())).join(`
|
|
3279
|
+
`);
|
|
3280
|
+
}
|
|
3281
|
+
function readlineWidth() {
|
|
3282
|
+
return import_cli_width.default({ defaultWidth: 80, output: readline().output });
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
// ../../node_modules/@inquirer/core/dist/lib/pagination/use-pagination.js
|
|
3286
|
+
function usePointerPosition({ active, renderedItems, pageSize, loop }) {
|
|
3287
|
+
const state = useRef({
|
|
3288
|
+
lastPointer: active,
|
|
3289
|
+
lastActive: undefined
|
|
3290
|
+
});
|
|
3291
|
+
const { lastPointer, lastActive } = state.current;
|
|
3292
|
+
const middle = Math.floor(pageSize / 2);
|
|
3293
|
+
const renderedLength = renderedItems.reduce((acc, item) => acc + item.length, 0);
|
|
3294
|
+
const defaultPointerPosition = renderedItems.slice(0, active).reduce((acc, item) => acc + item.length, 0);
|
|
3295
|
+
let pointer = defaultPointerPosition;
|
|
3296
|
+
if (renderedLength > pageSize) {
|
|
3297
|
+
if (loop) {
|
|
3298
|
+
pointer = lastPointer;
|
|
3299
|
+
if (lastActive != null && lastActive < active && active - lastActive < pageSize) {
|
|
3300
|
+
pointer = Math.min(middle, Math.abs(active - lastActive) === 1 ? Math.min(lastPointer + (renderedItems[lastActive]?.length ?? 0), Math.max(defaultPointerPosition, lastPointer)) : lastPointer + active - lastActive);
|
|
3301
|
+
}
|
|
3302
|
+
} else {
|
|
3303
|
+
const spaceUnderActive = renderedItems.slice(active).reduce((acc, item) => acc + item.length, 0);
|
|
3304
|
+
pointer = spaceUnderActive < pageSize - middle ? pageSize - spaceUnderActive : Math.min(defaultPointerPosition, middle);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
state.current.lastPointer = pointer;
|
|
3308
|
+
state.current.lastActive = active;
|
|
3309
|
+
return pointer;
|
|
3310
|
+
}
|
|
3311
|
+
function usePagination({ items, active, renderItem, pageSize, loop = true }) {
|
|
3312
|
+
const width = readlineWidth();
|
|
3313
|
+
const bound = (num) => (num % items.length + items.length) % items.length;
|
|
3314
|
+
const renderedItems = items.map((item, index) => {
|
|
3315
|
+
if (item == null)
|
|
3316
|
+
return [];
|
|
3317
|
+
return breakLines(renderItem({ item, index, isActive: index === active }), width).split(`
|
|
3318
|
+
`);
|
|
3319
|
+
});
|
|
3320
|
+
const renderedLength = renderedItems.reduce((acc, item) => acc + item.length, 0);
|
|
3321
|
+
const renderItemAtIndex = (index) => renderedItems[index] ?? [];
|
|
3322
|
+
const pointer = usePointerPosition({ active, renderedItems, pageSize, loop });
|
|
3323
|
+
const activeItem = renderItemAtIndex(active).slice(0, pageSize);
|
|
3324
|
+
const activeItemPosition = pointer + activeItem.length <= pageSize ? pointer : pageSize - activeItem.length;
|
|
3325
|
+
const pageBuffer = Array.from({ length: pageSize });
|
|
3326
|
+
pageBuffer.splice(activeItemPosition, activeItem.length, ...activeItem);
|
|
3327
|
+
const itemVisited = new Set([active]);
|
|
3328
|
+
let bufferPointer = activeItemPosition + activeItem.length;
|
|
3329
|
+
let itemPointer = bound(active + 1);
|
|
3330
|
+
while (bufferPointer < pageSize && !itemVisited.has(itemPointer) && (loop && renderedLength > pageSize ? itemPointer !== active : itemPointer > active)) {
|
|
3331
|
+
const lines = renderItemAtIndex(itemPointer);
|
|
3332
|
+
const linesToAdd = lines.slice(0, pageSize - bufferPointer);
|
|
3333
|
+
pageBuffer.splice(bufferPointer, linesToAdd.length, ...linesToAdd);
|
|
3334
|
+
itemVisited.add(itemPointer);
|
|
3335
|
+
bufferPointer += linesToAdd.length;
|
|
3336
|
+
itemPointer = bound(itemPointer + 1);
|
|
3337
|
+
}
|
|
3338
|
+
bufferPointer = activeItemPosition - 1;
|
|
3339
|
+
itemPointer = bound(active - 1);
|
|
3340
|
+
while (bufferPointer >= 0 && !itemVisited.has(itemPointer) && (loop && renderedLength > pageSize ? itemPointer !== active : itemPointer < active)) {
|
|
3341
|
+
const lines = renderItemAtIndex(itemPointer);
|
|
3342
|
+
const linesToAdd = lines.slice(Math.max(0, lines.length - bufferPointer - 1));
|
|
3343
|
+
pageBuffer.splice(bufferPointer - linesToAdd.length + 1, linesToAdd.length, ...linesToAdd);
|
|
3344
|
+
itemVisited.add(itemPointer);
|
|
3345
|
+
bufferPointer -= linesToAdd.length;
|
|
3346
|
+
itemPointer = bound(itemPointer - 1);
|
|
3347
|
+
}
|
|
3348
|
+
return pageBuffer.filter((line) => typeof line === "string").join(`
|
|
3349
|
+
`);
|
|
3350
|
+
}
|
|
3351
|
+
// ../../node_modules/@inquirer/core/dist/lib/create-prompt.js
|
|
3352
|
+
var import_mute_stream = __toESM(require_lib(), 1);
|
|
3353
|
+
import * as readline2 from "node:readline";
|
|
3354
|
+
import { AsyncResource as AsyncResource3 } from "node:async_hooks";
|
|
3355
|
+
|
|
3356
|
+
// ../../node_modules/signal-exit/dist/mjs/signals.js
|
|
3357
|
+
var signals = [];
|
|
3358
|
+
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
3359
|
+
if (process.platform !== "win32") {
|
|
3360
|
+
signals.push("SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
|
|
3361
|
+
}
|
|
3362
|
+
if (process.platform === "linux") {
|
|
3363
|
+
signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3366
|
+
// ../../node_modules/signal-exit/dist/mjs/index.js
|
|
3367
|
+
var processOk = (process3) => !!process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
|
|
3368
|
+
var kExitEmitter = Symbol.for("signal-exit emitter");
|
|
3369
|
+
var global = globalThis;
|
|
3370
|
+
var ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
3371
|
+
|
|
3372
|
+
class Emitter {
|
|
3373
|
+
emitted = {
|
|
3374
|
+
afterExit: false,
|
|
3375
|
+
exit: false
|
|
3376
|
+
};
|
|
3377
|
+
listeners = {
|
|
3378
|
+
afterExit: [],
|
|
3379
|
+
exit: []
|
|
3380
|
+
};
|
|
3381
|
+
count = 0;
|
|
3382
|
+
id = Math.random();
|
|
3383
|
+
constructor() {
|
|
3384
|
+
if (global[kExitEmitter]) {
|
|
3385
|
+
return global[kExitEmitter];
|
|
3386
|
+
}
|
|
3387
|
+
ObjectDefineProperty(global, kExitEmitter, {
|
|
3388
|
+
value: this,
|
|
3389
|
+
writable: false,
|
|
3390
|
+
enumerable: false,
|
|
3391
|
+
configurable: false
|
|
3392
|
+
});
|
|
3393
|
+
}
|
|
3394
|
+
on(ev, fn) {
|
|
3395
|
+
this.listeners[ev].push(fn);
|
|
3396
|
+
}
|
|
3397
|
+
removeListener(ev, fn) {
|
|
3398
|
+
const list = this.listeners[ev];
|
|
3399
|
+
const i = list.indexOf(fn);
|
|
3400
|
+
if (i === -1) {
|
|
3401
|
+
return;
|
|
3402
|
+
}
|
|
3403
|
+
if (i === 0 && list.length === 1) {
|
|
3404
|
+
list.length = 0;
|
|
3405
|
+
} else {
|
|
3406
|
+
list.splice(i, 1);
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
emit(ev, code, signal) {
|
|
3410
|
+
if (this.emitted[ev]) {
|
|
3411
|
+
return false;
|
|
3412
|
+
}
|
|
3413
|
+
this.emitted[ev] = true;
|
|
3414
|
+
let ret = false;
|
|
3415
|
+
for (const fn of this.listeners[ev]) {
|
|
3416
|
+
ret = fn(code, signal) === true || ret;
|
|
3417
|
+
}
|
|
3418
|
+
if (ev === "exit") {
|
|
3419
|
+
ret = this.emit("afterExit", code, signal) || ret;
|
|
3420
|
+
}
|
|
3421
|
+
return ret;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
class SignalExitBase {
|
|
3426
|
+
}
|
|
3427
|
+
var signalExitWrap = (handler) => {
|
|
3428
|
+
return {
|
|
3429
|
+
onExit(cb, opts) {
|
|
3430
|
+
return handler.onExit(cb, opts);
|
|
3431
|
+
},
|
|
3432
|
+
load() {
|
|
3433
|
+
return handler.load();
|
|
3434
|
+
},
|
|
3435
|
+
unload() {
|
|
3436
|
+
return handler.unload();
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
};
|
|
3440
|
+
|
|
3441
|
+
class SignalExitFallback extends SignalExitBase {
|
|
3442
|
+
onExit() {
|
|
3443
|
+
return () => {};
|
|
3444
|
+
}
|
|
3445
|
+
load() {}
|
|
3446
|
+
unload() {}
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
class SignalExit extends SignalExitBase {
|
|
3450
|
+
#hupSig = process3.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
3451
|
+
#emitter = new Emitter;
|
|
3452
|
+
#process;
|
|
3453
|
+
#originalProcessEmit;
|
|
3454
|
+
#originalProcessReallyExit;
|
|
3455
|
+
#sigListeners = {};
|
|
3456
|
+
#loaded = false;
|
|
3457
|
+
constructor(process3) {
|
|
3458
|
+
super();
|
|
3459
|
+
this.#process = process3;
|
|
3460
|
+
this.#sigListeners = {};
|
|
3461
|
+
for (const sig of signals) {
|
|
3462
|
+
this.#sigListeners[sig] = () => {
|
|
3463
|
+
const listeners = this.#process.listeners(sig);
|
|
3464
|
+
let { count } = this.#emitter;
|
|
3465
|
+
const p = process3;
|
|
3466
|
+
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
|
|
3467
|
+
count += p.__signal_exit_emitter__.count;
|
|
3468
|
+
}
|
|
3469
|
+
if (listeners.length === count) {
|
|
3470
|
+
this.unload();
|
|
3471
|
+
const ret = this.#emitter.emit("exit", null, sig);
|
|
3472
|
+
const s = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
3473
|
+
if (!ret)
|
|
3474
|
+
process3.kill(process3.pid, s);
|
|
3475
|
+
}
|
|
3476
|
+
};
|
|
3477
|
+
}
|
|
3478
|
+
this.#originalProcessReallyExit = process3.reallyExit;
|
|
3479
|
+
this.#originalProcessEmit = process3.emit;
|
|
3480
|
+
}
|
|
3481
|
+
onExit(cb, opts) {
|
|
3482
|
+
if (!processOk(this.#process)) {
|
|
3483
|
+
return () => {};
|
|
3484
|
+
}
|
|
3485
|
+
if (this.#loaded === false) {
|
|
3486
|
+
this.load();
|
|
3487
|
+
}
|
|
3488
|
+
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
3489
|
+
this.#emitter.on(ev, cb);
|
|
3490
|
+
return () => {
|
|
3491
|
+
this.#emitter.removeListener(ev, cb);
|
|
3492
|
+
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) {
|
|
3493
|
+
this.unload();
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
load() {
|
|
3498
|
+
if (this.#loaded) {
|
|
3499
|
+
return;
|
|
3500
|
+
}
|
|
3501
|
+
this.#loaded = true;
|
|
3502
|
+
this.#emitter.count += 1;
|
|
3503
|
+
for (const sig of signals) {
|
|
3504
|
+
try {
|
|
3505
|
+
const fn = this.#sigListeners[sig];
|
|
3506
|
+
if (fn)
|
|
3507
|
+
this.#process.on(sig, fn);
|
|
3508
|
+
} catch (_) {}
|
|
3509
|
+
}
|
|
3510
|
+
this.#process.emit = (ev, ...a) => {
|
|
3511
|
+
return this.#processEmit(ev, ...a);
|
|
3512
|
+
};
|
|
3513
|
+
this.#process.reallyExit = (code) => {
|
|
3514
|
+
return this.#processReallyExit(code);
|
|
3515
|
+
};
|
|
3516
|
+
}
|
|
3517
|
+
unload() {
|
|
3518
|
+
if (!this.#loaded) {
|
|
3519
|
+
return;
|
|
3520
|
+
}
|
|
3521
|
+
this.#loaded = false;
|
|
3522
|
+
signals.forEach((sig) => {
|
|
3523
|
+
const listener = this.#sigListeners[sig];
|
|
3524
|
+
if (!listener) {
|
|
3525
|
+
throw new Error("Listener not defined for signal: " + sig);
|
|
3526
|
+
}
|
|
3527
|
+
try {
|
|
3528
|
+
this.#process.removeListener(sig, listener);
|
|
3529
|
+
} catch (_) {}
|
|
3530
|
+
});
|
|
3531
|
+
this.#process.emit = this.#originalProcessEmit;
|
|
3532
|
+
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
3533
|
+
this.#emitter.count -= 1;
|
|
3534
|
+
}
|
|
3535
|
+
#processReallyExit(code) {
|
|
3536
|
+
if (!processOk(this.#process)) {
|
|
3537
|
+
return 0;
|
|
3538
|
+
}
|
|
3539
|
+
this.#process.exitCode = code || 0;
|
|
3540
|
+
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
3541
|
+
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
3542
|
+
}
|
|
3543
|
+
#processEmit(ev, ...args) {
|
|
3544
|
+
const og = this.#originalProcessEmit;
|
|
3545
|
+
if (ev === "exit" && processOk(this.#process)) {
|
|
3546
|
+
if (typeof args[0] === "number") {
|
|
3547
|
+
this.#process.exitCode = args[0];
|
|
3548
|
+
}
|
|
3549
|
+
const ret = og.call(this.#process, ev, ...args);
|
|
3550
|
+
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
3551
|
+
return ret;
|
|
3552
|
+
} else {
|
|
3553
|
+
return og.call(this.#process, ev, ...args);
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
var process3 = globalThis.process;
|
|
3558
|
+
var {
|
|
3559
|
+
onExit,
|
|
3560
|
+
load,
|
|
3561
|
+
unload
|
|
3562
|
+
} = signalExitWrap(processOk(process3) ? new SignalExit(process3) : new SignalExitFallback);
|
|
3563
|
+
|
|
3564
|
+
// ../../node_modules/@inquirer/core/dist/lib/screen-manager.js
|
|
3565
|
+
import { stripVTControlCharacters } from "node:util";
|
|
3566
|
+
|
|
3567
|
+
// ../../node_modules/@inquirer/ansi/dist/index.js
|
|
3568
|
+
var ESC2 = "\x1B[";
|
|
3569
|
+
var cursorLeft = ESC2 + "G";
|
|
3570
|
+
var cursorHide = ESC2 + "?25l";
|
|
3571
|
+
var cursorShow = ESC2 + "?25h";
|
|
3572
|
+
var cursorUp = (rows = 1) => rows > 0 ? `${ESC2}${rows}A` : "";
|
|
3573
|
+
var cursorDown = (rows = 1) => rows > 0 ? `${ESC2}${rows}B` : "";
|
|
3574
|
+
var cursorTo = (x, y) => {
|
|
3575
|
+
if (typeof y === "number" && !Number.isNaN(y)) {
|
|
3576
|
+
return `${ESC2}${y + 1};${x + 1}H`;
|
|
3577
|
+
}
|
|
3578
|
+
return `${ESC2}${x + 1}G`;
|
|
3579
|
+
};
|
|
3580
|
+
var eraseLine = ESC2 + "2K";
|
|
3581
|
+
var eraseLines = (lines) => lines > 0 ? (eraseLine + cursorUp(1)).repeat(lines - 1) + eraseLine + cursorLeft : "";
|
|
3582
|
+
|
|
3583
|
+
// ../../node_modules/@inquirer/core/dist/lib/screen-manager.js
|
|
3584
|
+
var height = (content) => content.split(`
|
|
3585
|
+
`).length;
|
|
3586
|
+
var lastLine = (content) => content.split(`
|
|
3587
|
+
`).pop() ?? "";
|
|
3588
|
+
|
|
3589
|
+
class ScreenManager {
|
|
3590
|
+
height = 0;
|
|
3591
|
+
extraLinesUnderPrompt = 0;
|
|
3592
|
+
cursorPos;
|
|
3593
|
+
rl;
|
|
3594
|
+
constructor(rl) {
|
|
3595
|
+
this.rl = rl;
|
|
3596
|
+
this.cursorPos = rl.getCursorPos();
|
|
3597
|
+
}
|
|
3598
|
+
write(content) {
|
|
3599
|
+
this.rl.output.unmute();
|
|
3600
|
+
this.rl.output.write(content);
|
|
3601
|
+
this.rl.output.mute();
|
|
3602
|
+
}
|
|
3603
|
+
render(content, bottomContent = "") {
|
|
3604
|
+
const promptLine = lastLine(content);
|
|
3605
|
+
const rawPromptLine = stripVTControlCharacters(promptLine);
|
|
3606
|
+
let prompt = rawPromptLine;
|
|
3607
|
+
if (this.rl.line.length > 0) {
|
|
3608
|
+
prompt = prompt.slice(0, -this.rl.line.length);
|
|
3609
|
+
}
|
|
3610
|
+
this.rl.setPrompt(prompt);
|
|
3611
|
+
this.cursorPos = this.rl.getCursorPos();
|
|
3612
|
+
const width = readlineWidth();
|
|
3613
|
+
content = breakLines(content, width);
|
|
3614
|
+
bottomContent = breakLines(bottomContent, width);
|
|
3615
|
+
if (rawPromptLine.length % width === 0) {
|
|
3616
|
+
content += `
|
|
3617
|
+
`;
|
|
3618
|
+
}
|
|
3619
|
+
let output = content + (bottomContent ? `
|
|
3620
|
+
` + bottomContent : "");
|
|
3621
|
+
const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
|
|
3622
|
+
const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
|
3623
|
+
if (bottomContentHeight > 0)
|
|
3624
|
+
output += cursorUp(bottomContentHeight);
|
|
3625
|
+
output += cursorTo(this.cursorPos.cols);
|
|
3626
|
+
this.write(cursorDown(this.extraLinesUnderPrompt) + eraseLines(this.height) + output);
|
|
3627
|
+
this.extraLinesUnderPrompt = bottomContentHeight;
|
|
3628
|
+
this.height = height(output);
|
|
3629
|
+
}
|
|
3630
|
+
checkCursorPos() {
|
|
3631
|
+
const cursorPos = this.rl.getCursorPos();
|
|
3632
|
+
if (cursorPos.cols !== this.cursorPos.cols) {
|
|
3633
|
+
this.write(cursorTo(cursorPos.cols));
|
|
3634
|
+
this.cursorPos = cursorPos;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
done({ clearContent }) {
|
|
3638
|
+
this.rl.setPrompt("");
|
|
3639
|
+
let output = cursorDown(this.extraLinesUnderPrompt);
|
|
3640
|
+
output += clearContent ? eraseLines(this.height) : `
|
|
3641
|
+
`;
|
|
3642
|
+
output += cursorShow;
|
|
3643
|
+
this.write(output);
|
|
3644
|
+
this.rl.close();
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
|
|
3648
|
+
// ../../node_modules/@inquirer/core/dist/lib/promise-polyfill.js
|
|
3649
|
+
class PromisePolyfill extends Promise {
|
|
3650
|
+
static withResolver() {
|
|
3651
|
+
let resolve;
|
|
3652
|
+
let reject;
|
|
3653
|
+
const promise = new Promise((res, rej) => {
|
|
3654
|
+
resolve = res;
|
|
3655
|
+
reject = rej;
|
|
3656
|
+
});
|
|
3657
|
+
return { promise, resolve, reject };
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
// ../../node_modules/@inquirer/core/dist/lib/create-prompt.js
|
|
3662
|
+
import path from "node:path";
|
|
3663
|
+
var nativeSetImmediate = globalThis.setImmediate;
|
|
3664
|
+
function getCallSites() {
|
|
3665
|
+
const _prepareStackTrace = Error.prepareStackTrace;
|
|
3666
|
+
let result = [];
|
|
3667
|
+
try {
|
|
3668
|
+
Error.prepareStackTrace = (_, callSites) => {
|
|
3669
|
+
const callSitesWithoutCurrent = callSites.slice(1);
|
|
3670
|
+
result = callSitesWithoutCurrent;
|
|
3671
|
+
return callSitesWithoutCurrent;
|
|
3672
|
+
};
|
|
3673
|
+
new Error().stack;
|
|
3674
|
+
} catch {
|
|
3675
|
+
return result;
|
|
3676
|
+
}
|
|
3677
|
+
Error.prepareStackTrace = _prepareStackTrace;
|
|
3678
|
+
return result;
|
|
3679
|
+
}
|
|
3680
|
+
function createPrompt(view) {
|
|
3681
|
+
const callSites = getCallSites();
|
|
3682
|
+
const prompt = (config, context = {}) => {
|
|
3683
|
+
const { input = process.stdin, signal } = context;
|
|
3684
|
+
const cleanups = new Set;
|
|
3685
|
+
const output = new import_mute_stream.default;
|
|
3686
|
+
output.pipe(context.output ?? process.stdout);
|
|
3687
|
+
const rl = readline2.createInterface({
|
|
3688
|
+
terminal: true,
|
|
3689
|
+
input,
|
|
3690
|
+
output
|
|
3691
|
+
});
|
|
3692
|
+
output.mute();
|
|
3693
|
+
const screen = new ScreenManager(rl);
|
|
3694
|
+
const { promise, resolve, reject } = PromisePolyfill.withResolver();
|
|
3695
|
+
const cancel = () => reject(new CancelPromptError);
|
|
3696
|
+
if (signal) {
|
|
3697
|
+
const abort = () => reject(new AbortPromptError({ cause: signal.reason }));
|
|
3698
|
+
if (signal.aborted) {
|
|
3699
|
+
abort();
|
|
3700
|
+
return Object.assign(promise, { cancel });
|
|
3701
|
+
}
|
|
3702
|
+
signal.addEventListener("abort", abort);
|
|
3703
|
+
cleanups.add(() => signal.removeEventListener("abort", abort));
|
|
3704
|
+
}
|
|
3705
|
+
cleanups.add(onExit((code, signal2) => {
|
|
3706
|
+
reject(new ExitPromptError(`User force closed the prompt with ${code} ${signal2}`));
|
|
3707
|
+
}));
|
|
3708
|
+
const sigint = () => reject(new ExitPromptError(`User force closed the prompt with SIGINT`));
|
|
3709
|
+
rl.on("SIGINT", sigint);
|
|
3710
|
+
cleanups.add(() => rl.removeListener("SIGINT", sigint));
|
|
3711
|
+
return withHooks(rl, (cycle) => {
|
|
3712
|
+
const hooksCleanup = AsyncResource3.bind(() => effectScheduler.clearAll());
|
|
3713
|
+
rl.on("close", hooksCleanup);
|
|
3714
|
+
cleanups.add(() => rl.removeListener("close", hooksCleanup));
|
|
3715
|
+
const startCycle = () => {
|
|
3716
|
+
const checkCursorPos = () => screen.checkCursorPos();
|
|
3717
|
+
rl.input.on("keypress", checkCursorPos);
|
|
3718
|
+
cleanups.add(() => rl.input.removeListener("keypress", checkCursorPos));
|
|
3719
|
+
let pendingDone = null;
|
|
3720
|
+
cycle(() => {
|
|
3721
|
+
let effectsSettled = false;
|
|
3722
|
+
try {
|
|
3723
|
+
const nextView = view(config, (value) => {
|
|
3724
|
+
if (effectsSettled) {
|
|
3725
|
+
resolve(value);
|
|
3726
|
+
} else {
|
|
3727
|
+
pendingDone = { value };
|
|
3728
|
+
}
|
|
3729
|
+
});
|
|
3730
|
+
if (nextView === undefined) {
|
|
3731
|
+
let callerFilename = callSites[1]?.getFileName();
|
|
3732
|
+
if (callerFilename && !callerFilename.startsWith("file://")) {
|
|
3733
|
+
callerFilename = path.resolve(callerFilename);
|
|
3734
|
+
}
|
|
3735
|
+
throw new Error(`Prompt functions must return a string.
|
|
3736
|
+
at ${callerFilename}`);
|
|
3737
|
+
}
|
|
3738
|
+
const [content, bottomContent] = typeof nextView === "string" ? [nextView] : nextView;
|
|
3739
|
+
screen.render(content, bottomContent);
|
|
3740
|
+
effectScheduler.run();
|
|
3741
|
+
} catch (error) {
|
|
3742
|
+
reject(error);
|
|
3743
|
+
}
|
|
3744
|
+
effectsSettled = true;
|
|
3745
|
+
if (pendingDone !== null) {
|
|
3746
|
+
const { value } = pendingDone;
|
|
3747
|
+
pendingDone = null;
|
|
3748
|
+
resolve(value);
|
|
3749
|
+
}
|
|
3750
|
+
});
|
|
3751
|
+
};
|
|
3752
|
+
if ("readableFlowing" in input) {
|
|
3753
|
+
nativeSetImmediate(startCycle);
|
|
3754
|
+
} else {
|
|
3755
|
+
startCycle();
|
|
3756
|
+
}
|
|
3757
|
+
return Object.assign(promise.then((answer) => {
|
|
3758
|
+
effectScheduler.clearAll();
|
|
3759
|
+
return answer;
|
|
3760
|
+
}, (error) => {
|
|
3761
|
+
effectScheduler.clearAll();
|
|
3762
|
+
throw error;
|
|
3763
|
+
}).finally(() => {
|
|
3764
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
3765
|
+
screen.done({ clearContent: Boolean(context.clearPromptOnDone) });
|
|
3766
|
+
output.end();
|
|
3767
|
+
}).then(() => promise), { cancel });
|
|
3768
|
+
});
|
|
3769
|
+
};
|
|
3770
|
+
return prompt;
|
|
3771
|
+
}
|
|
3772
|
+
// ../../node_modules/@inquirer/core/dist/lib/Separator.js
|
|
3773
|
+
import { styleText as styleText2 } from "node:util";
|
|
3774
|
+
class Separator {
|
|
3775
|
+
separator = styleText2("dim", Array.from({ length: 15 }).join(dist_default.line));
|
|
3776
|
+
type = "separator";
|
|
3777
|
+
constructor(separator) {
|
|
3778
|
+
if (separator) {
|
|
3779
|
+
this.separator = separator;
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
static isSeparator(choice) {
|
|
3783
|
+
return Boolean(choice && typeof choice === "object" && "type" in choice && choice.type === "separator");
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
// ../../node_modules/@inquirer/checkbox/dist/index.js
|
|
3787
|
+
import { styleText as styleText3 } from "node:util";
|
|
3788
|
+
var checkboxTheme = {
|
|
3789
|
+
icon: {
|
|
3790
|
+
checked: styleText3("green", dist_default.circleFilled),
|
|
3791
|
+
unchecked: dist_default.circle,
|
|
3792
|
+
cursor: dist_default.pointer,
|
|
3793
|
+
disabledChecked: styleText3("green", dist_default.circleDouble),
|
|
3794
|
+
disabledUnchecked: "-"
|
|
3795
|
+
},
|
|
3796
|
+
style: {
|
|
3797
|
+
disabled: (text) => styleText3("dim", text),
|
|
3798
|
+
renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(", "),
|
|
3799
|
+
description: (text) => styleText3("cyan", text),
|
|
3800
|
+
keysHelpTip: (keys) => keys.map(([key, action]) => `${styleText3("bold", key)} ${styleText3("dim", action)}`).join(styleText3("dim", " • "))
|
|
3801
|
+
},
|
|
3802
|
+
i18n: { disabledError: "This option is disabled and cannot be toggled." },
|
|
3803
|
+
keybindings: []
|
|
3804
|
+
};
|
|
3805
|
+
function isSelectable(item) {
|
|
3806
|
+
return !Separator.isSeparator(item) && !item.disabled;
|
|
3807
|
+
}
|
|
3808
|
+
function isNavigable(item) {
|
|
3809
|
+
return !Separator.isSeparator(item);
|
|
3810
|
+
}
|
|
3811
|
+
function isChecked(item) {
|
|
3812
|
+
return !Separator.isSeparator(item) && item.checked;
|
|
3813
|
+
}
|
|
3814
|
+
function toggle(item) {
|
|
3815
|
+
return isSelectable(item) ? { ...item, checked: !item.checked } : item;
|
|
3816
|
+
}
|
|
3817
|
+
function check(checked) {
|
|
3818
|
+
return function(item) {
|
|
3819
|
+
return isSelectable(item) ? { ...item, checked } : item;
|
|
3820
|
+
};
|
|
3821
|
+
}
|
|
3822
|
+
function normalizeChoices(choices) {
|
|
3823
|
+
return choices.map((choice) => {
|
|
3824
|
+
if (Separator.isSeparator(choice))
|
|
3825
|
+
return choice;
|
|
3826
|
+
if (typeof choice !== "object" || choice === null || !("value" in choice)) {
|
|
3827
|
+
const name2 = String(choice);
|
|
3828
|
+
return {
|
|
3829
|
+
value: choice,
|
|
3830
|
+
name: name2,
|
|
3831
|
+
short: name2,
|
|
3832
|
+
checkedName: name2,
|
|
3833
|
+
disabled: false,
|
|
3834
|
+
checked: false
|
|
3835
|
+
};
|
|
3836
|
+
}
|
|
3837
|
+
const name = choice.name ?? String(choice.value);
|
|
3838
|
+
const normalizedChoice = {
|
|
3839
|
+
value: choice.value,
|
|
3840
|
+
name,
|
|
3841
|
+
short: choice.short ?? name,
|
|
3842
|
+
checkedName: choice.checkedName ?? name,
|
|
3843
|
+
disabled: choice.disabled ?? false,
|
|
3844
|
+
checked: choice.checked ?? false
|
|
3845
|
+
};
|
|
3846
|
+
if (choice.description) {
|
|
3847
|
+
normalizedChoice.description = choice.description;
|
|
3848
|
+
}
|
|
3849
|
+
return normalizedChoice;
|
|
3850
|
+
});
|
|
3851
|
+
}
|
|
3852
|
+
var dist_default4 = createPrompt((config, done) => {
|
|
3853
|
+
const { pageSize = 7, loop = true, required, validate = () => true } = config;
|
|
3854
|
+
const shortcuts = { all: "a", invert: "i", ...config.shortcuts };
|
|
3855
|
+
const theme = makeTheme(checkboxTheme, config.theme);
|
|
3856
|
+
const { keybindings } = theme;
|
|
3857
|
+
const [status, setStatus] = useState("idle");
|
|
3858
|
+
const prefix = usePrefix({ status, theme });
|
|
3859
|
+
const [items, setItems] = useState(normalizeChoices(config.choices));
|
|
3860
|
+
const bounds = useMemo(() => {
|
|
3861
|
+
const first = items.findIndex(isNavigable);
|
|
3862
|
+
const last = items.findLastIndex(isNavigable);
|
|
3863
|
+
if (first === -1) {
|
|
3864
|
+
throw new ValidationError("[checkbox prompt] No selectable choices. All choices are disabled.");
|
|
3865
|
+
}
|
|
3866
|
+
return { first, last };
|
|
3867
|
+
}, [items]);
|
|
3868
|
+
const [active, setActive] = useState(bounds.first);
|
|
3869
|
+
const [errorMsg, setError] = useState();
|
|
3870
|
+
useKeypress(async (key) => {
|
|
3871
|
+
if (isEnterKey(key)) {
|
|
3872
|
+
const selection = items.filter(isChecked);
|
|
3873
|
+
const isValid = await validate([...selection]);
|
|
3874
|
+
if (required && !selection.length) {
|
|
3875
|
+
setError("At least one choice must be selected");
|
|
3876
|
+
} else if (isValid === true) {
|
|
3877
|
+
setStatus("done");
|
|
3878
|
+
done(selection.map((choice) => choice.value));
|
|
3879
|
+
} else {
|
|
3880
|
+
setError(isValid || "You must select a valid value");
|
|
3881
|
+
}
|
|
3882
|
+
} else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
|
|
3883
|
+
if (errorMsg) {
|
|
3884
|
+
setError(undefined);
|
|
3885
|
+
}
|
|
3886
|
+
if (loop || isUpKey(key, keybindings) && active !== bounds.first || isDownKey(key, keybindings) && active !== bounds.last) {
|
|
3887
|
+
const offset = isUpKey(key, keybindings) ? -1 : 1;
|
|
3888
|
+
let next = active;
|
|
3889
|
+
do {
|
|
3890
|
+
next = (next + offset + items.length) % items.length;
|
|
3891
|
+
} while (!isNavigable(items[next]));
|
|
3892
|
+
setActive(next);
|
|
3893
|
+
}
|
|
3894
|
+
} else if (isSpaceKey(key)) {
|
|
3895
|
+
const activeItem = items[active];
|
|
3896
|
+
if (activeItem && !Separator.isSeparator(activeItem)) {
|
|
3897
|
+
if (activeItem.disabled) {
|
|
3898
|
+
setError(theme.i18n.disabledError);
|
|
3899
|
+
} else {
|
|
3900
|
+
setError(undefined);
|
|
3901
|
+
setItems(items.map((choice, i) => i === active ? toggle(choice) : choice));
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
} else if (key.name === shortcuts.all) {
|
|
3905
|
+
const selectAll = items.some((choice) => isSelectable(choice) && !choice.checked);
|
|
3906
|
+
setItems(items.map(check(selectAll)));
|
|
3907
|
+
} else if (key.name === shortcuts.invert) {
|
|
3908
|
+
setItems(items.map(toggle));
|
|
3909
|
+
} else if (isNumberKey(key)) {
|
|
3910
|
+
const selectedIndex = Number(key.name) - 1;
|
|
3911
|
+
let selectableIndex = -1;
|
|
3912
|
+
const position = items.findIndex((item) => {
|
|
3913
|
+
if (Separator.isSeparator(item))
|
|
3914
|
+
return false;
|
|
3915
|
+
selectableIndex++;
|
|
3916
|
+
return selectableIndex === selectedIndex;
|
|
3917
|
+
});
|
|
3918
|
+
const selectedItem = items[position];
|
|
3919
|
+
if (selectedItem && isSelectable(selectedItem)) {
|
|
3920
|
+
setActive(position);
|
|
3921
|
+
setItems(items.map((choice, i) => i === position ? toggle(choice) : choice));
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
});
|
|
3925
|
+
const message = theme.style.message(config.message, status);
|
|
3926
|
+
let description;
|
|
3927
|
+
const page = usePagination({
|
|
3928
|
+
items,
|
|
3929
|
+
active,
|
|
3930
|
+
renderItem({ item, isActive }) {
|
|
3931
|
+
if (Separator.isSeparator(item)) {
|
|
3932
|
+
return ` ${item.separator}`;
|
|
3933
|
+
}
|
|
3934
|
+
const cursor = isActive ? theme.icon.cursor : " ";
|
|
3935
|
+
if (item.disabled) {
|
|
3936
|
+
const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
|
|
3937
|
+
const checkbox2 = item.checked ? theme.icon.disabledChecked : theme.icon.disabledUnchecked;
|
|
3938
|
+
return theme.style.disabled(`${cursor}${checkbox2} ${item.name} ${disabledLabel}`);
|
|
3939
|
+
}
|
|
3940
|
+
if (isActive) {
|
|
3941
|
+
description = item.description;
|
|
3942
|
+
}
|
|
3943
|
+
const checkbox = item.checked ? theme.icon.checked : theme.icon.unchecked;
|
|
3944
|
+
const name = item.checked ? item.checkedName : item.name;
|
|
3945
|
+
const color = isActive ? theme.style.highlight : (x) => x;
|
|
3946
|
+
return color(`${cursor}${checkbox} ${name}`);
|
|
3947
|
+
},
|
|
3948
|
+
pageSize,
|
|
3949
|
+
loop
|
|
3950
|
+
});
|
|
3951
|
+
if (status === "done") {
|
|
3952
|
+
const selection = items.filter(isChecked);
|
|
3953
|
+
const answer = theme.style.answer(theme.style.renderSelectedChoices(selection, items));
|
|
3954
|
+
return [prefix, message, answer].filter(Boolean).join(" ");
|
|
3955
|
+
}
|
|
3956
|
+
const keys = [
|
|
3957
|
+
["↑↓", "navigate"],
|
|
3958
|
+
["space", "select"]
|
|
3959
|
+
];
|
|
3960
|
+
if (shortcuts.all)
|
|
3961
|
+
keys.push([shortcuts.all, "all"]);
|
|
3962
|
+
if (shortcuts.invert)
|
|
3963
|
+
keys.push([shortcuts.invert, "invert"]);
|
|
3964
|
+
keys.push(["⏎", "submit"]);
|
|
3965
|
+
const helpLine = theme.style.keysHelpTip(keys);
|
|
3966
|
+
const lines = [
|
|
3967
|
+
[prefix, message].filter(Boolean).join(" "),
|
|
3968
|
+
page,
|
|
3969
|
+
" ",
|
|
3970
|
+
description ? theme.style.description(description) : "",
|
|
3971
|
+
errorMsg ? theme.style.error(errorMsg) : "",
|
|
3972
|
+
helpLine
|
|
3973
|
+
].filter(Boolean).join(`
|
|
3974
|
+
`).trimEnd();
|
|
3975
|
+
return `${lines}${cursorHide}`;
|
|
3976
|
+
});
|
|
3977
|
+
// ../../node_modules/@inquirer/select/dist/index.js
|
|
3978
|
+
import { styleText as styleText4 } from "node:util";
|
|
3979
|
+
var selectTheme = {
|
|
3980
|
+
icon: { cursor: dist_default.pointer },
|
|
3981
|
+
style: {
|
|
3982
|
+
disabled: (text) => styleText4("dim", text),
|
|
3983
|
+
description: (text) => styleText4("cyan", text),
|
|
3984
|
+
keysHelpTip: (keys) => keys.map(([key, action]) => `${styleText4("bold", key)} ${styleText4("dim", action)}`).join(styleText4("dim", " • "))
|
|
3985
|
+
},
|
|
3986
|
+
i18n: { disabledError: "This option is disabled and cannot be selected." },
|
|
3987
|
+
indexMode: "hidden",
|
|
3988
|
+
keybindings: []
|
|
3989
|
+
};
|
|
3990
|
+
function isSelectable2(item) {
|
|
3991
|
+
return !Separator.isSeparator(item) && !item.disabled;
|
|
3992
|
+
}
|
|
3993
|
+
function isNavigable2(item) {
|
|
3994
|
+
return !Separator.isSeparator(item);
|
|
3995
|
+
}
|
|
3996
|
+
function normalizeChoices2(choices) {
|
|
3997
|
+
return choices.map((choice) => {
|
|
3998
|
+
if (Separator.isSeparator(choice))
|
|
3999
|
+
return choice;
|
|
4000
|
+
if (typeof choice !== "object" || choice === null || !("value" in choice)) {
|
|
4001
|
+
const name2 = String(choice);
|
|
4002
|
+
return {
|
|
4003
|
+
value: choice,
|
|
4004
|
+
name: name2,
|
|
4005
|
+
short: name2,
|
|
4006
|
+
disabled: false
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
4009
|
+
const name = choice.name ?? String(choice.value);
|
|
4010
|
+
const normalizedChoice = {
|
|
4011
|
+
value: choice.value,
|
|
4012
|
+
name,
|
|
4013
|
+
short: choice.short ?? name,
|
|
4014
|
+
disabled: choice.disabled ?? false
|
|
4015
|
+
};
|
|
4016
|
+
if (choice.description) {
|
|
4017
|
+
normalizedChoice.description = choice.description;
|
|
4018
|
+
}
|
|
4019
|
+
return normalizedChoice;
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
4022
|
+
var dist_default5 = createPrompt((config, done) => {
|
|
4023
|
+
const { loop = true, pageSize = 7 } = config;
|
|
4024
|
+
const theme = makeTheme(selectTheme, config.theme);
|
|
4025
|
+
const { keybindings } = theme;
|
|
4026
|
+
const [status, setStatus] = useState("idle");
|
|
4027
|
+
const prefix = usePrefix({ status, theme });
|
|
4028
|
+
const searchTimeoutRef = useRef();
|
|
4029
|
+
const searchEnabled = !keybindings.includes("vim");
|
|
4030
|
+
const items = useMemo(() => normalizeChoices2(config.choices), [config.choices]);
|
|
4031
|
+
const bounds = useMemo(() => {
|
|
4032
|
+
const first = items.findIndex(isNavigable2);
|
|
4033
|
+
const last = items.findLastIndex(isNavigable2);
|
|
4034
|
+
if (first === -1) {
|
|
4035
|
+
throw new ValidationError("[select prompt] No selectable choices. All choices are disabled.");
|
|
4036
|
+
}
|
|
4037
|
+
return { first, last };
|
|
4038
|
+
}, [items]);
|
|
4039
|
+
const defaultItemIndex = useMemo(() => {
|
|
4040
|
+
if (!("default" in config))
|
|
4041
|
+
return -1;
|
|
4042
|
+
return items.findIndex((item) => isSelectable2(item) && item.value === config.default);
|
|
4043
|
+
}, [config.default, items]);
|
|
4044
|
+
const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
|
|
4045
|
+
const selectedChoice = items[active];
|
|
4046
|
+
if (selectedChoice == null || Separator.isSeparator(selectedChoice)) {
|
|
4047
|
+
throw new Error("Active index does not point to a choice");
|
|
4048
|
+
}
|
|
4049
|
+
const [errorMsg, setError] = useState();
|
|
4050
|
+
useKeypress((key, rl) => {
|
|
4051
|
+
clearTimeout(searchTimeoutRef.current);
|
|
4052
|
+
if (errorMsg) {
|
|
4053
|
+
setError(undefined);
|
|
4054
|
+
}
|
|
4055
|
+
if (isEnterKey(key)) {
|
|
4056
|
+
if (selectedChoice.disabled) {
|
|
4057
|
+
setError(theme.i18n.disabledError);
|
|
4058
|
+
} else {
|
|
4059
|
+
setStatus("done");
|
|
4060
|
+
done(selectedChoice.value);
|
|
4061
|
+
}
|
|
4062
|
+
} else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
|
|
4063
|
+
rl.clearLine(0);
|
|
4064
|
+
if (loop || isUpKey(key, keybindings) && active !== bounds.first || isDownKey(key, keybindings) && active !== bounds.last) {
|
|
4065
|
+
const offset = isUpKey(key, keybindings) ? -1 : 1;
|
|
4066
|
+
let next = active;
|
|
4067
|
+
do {
|
|
4068
|
+
next = (next + offset + items.length) % items.length;
|
|
4069
|
+
} while (!isNavigable2(items[next]));
|
|
4070
|
+
setActive(next);
|
|
4071
|
+
}
|
|
4072
|
+
} else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
|
|
4073
|
+
const selectedIndex = Number(rl.line) - 1;
|
|
4074
|
+
let selectableIndex = -1;
|
|
4075
|
+
const position = items.findIndex((item2) => {
|
|
4076
|
+
if (Separator.isSeparator(item2))
|
|
4077
|
+
return false;
|
|
4078
|
+
selectableIndex++;
|
|
4079
|
+
return selectableIndex === selectedIndex;
|
|
4080
|
+
});
|
|
4081
|
+
const item = items[position];
|
|
4082
|
+
if (item != null && isSelectable2(item)) {
|
|
4083
|
+
setActive(position);
|
|
4084
|
+
}
|
|
4085
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
4086
|
+
rl.clearLine(0);
|
|
4087
|
+
}, 700);
|
|
4088
|
+
} else if (isBackspaceKey(key)) {
|
|
4089
|
+
rl.clearLine(0);
|
|
4090
|
+
} else if (searchEnabled) {
|
|
4091
|
+
const searchTerm = rl.line.toLowerCase();
|
|
4092
|
+
const matchIndex = items.findIndex((item) => {
|
|
4093
|
+
if (Separator.isSeparator(item) || !isSelectable2(item))
|
|
4094
|
+
return false;
|
|
4095
|
+
return item.name.toLowerCase().startsWith(searchTerm);
|
|
4096
|
+
});
|
|
4097
|
+
if (matchIndex !== -1) {
|
|
4098
|
+
setActive(matchIndex);
|
|
4099
|
+
}
|
|
4100
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
4101
|
+
rl.clearLine(0);
|
|
4102
|
+
}, 700);
|
|
4103
|
+
}
|
|
4104
|
+
});
|
|
4105
|
+
useEffect(() => () => {
|
|
4106
|
+
clearTimeout(searchTimeoutRef.current);
|
|
4107
|
+
}, []);
|
|
4108
|
+
const message = theme.style.message(config.message, status);
|
|
4109
|
+
const helpLine = theme.style.keysHelpTip([
|
|
4110
|
+
["↑↓", "navigate"],
|
|
4111
|
+
["⏎", "select"]
|
|
4112
|
+
]);
|
|
4113
|
+
let separatorCount = 0;
|
|
4114
|
+
const page = usePagination({
|
|
4115
|
+
items,
|
|
4116
|
+
active,
|
|
4117
|
+
renderItem({ item, isActive, index }) {
|
|
4118
|
+
if (Separator.isSeparator(item)) {
|
|
4119
|
+
separatorCount++;
|
|
4120
|
+
return ` ${item.separator}`;
|
|
4121
|
+
}
|
|
4122
|
+
const cursor = isActive ? theme.icon.cursor : " ";
|
|
4123
|
+
const indexLabel = theme.indexMode === "number" ? `${index + 1 - separatorCount}. ` : "";
|
|
4124
|
+
if (item.disabled) {
|
|
4125
|
+
const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
|
|
4126
|
+
const disabledCursor = isActive ? theme.icon.cursor : "-";
|
|
4127
|
+
return theme.style.disabled(`${disabledCursor} ${indexLabel}${item.name} ${disabledLabel}`);
|
|
4128
|
+
}
|
|
4129
|
+
const color = isActive ? theme.style.highlight : (x) => x;
|
|
4130
|
+
return color(`${cursor} ${indexLabel}${item.name}`);
|
|
4131
|
+
},
|
|
4132
|
+
pageSize,
|
|
4133
|
+
loop
|
|
4134
|
+
});
|
|
4135
|
+
if (status === "done") {
|
|
4136
|
+
return [prefix, message, theme.style.answer(selectedChoice.short)].filter(Boolean).join(" ");
|
|
4137
|
+
}
|
|
4138
|
+
const { description } = selectedChoice;
|
|
4139
|
+
const lines = [
|
|
4140
|
+
[prefix, message].filter(Boolean).join(" "),
|
|
4141
|
+
page,
|
|
4142
|
+
" ",
|
|
4143
|
+
description ? theme.style.description(description) : "",
|
|
4144
|
+
errorMsg ? theme.style.error(errorMsg) : "",
|
|
4145
|
+
helpLine
|
|
4146
|
+
].filter(Boolean).join(`
|
|
4147
|
+
`).trimEnd();
|
|
4148
|
+
return `${lines}${cursorHide}`;
|
|
4149
|
+
});
|
|
4150
|
+
// src/index.ts
|
|
4151
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
4152
|
+
|
|
4153
|
+
// ../../node_modules/commander/esm.mjs
|
|
4154
|
+
var import__ = __toESM(require_commander(), 1);
|
|
4155
|
+
var {
|
|
4156
|
+
program,
|
|
4157
|
+
createCommand,
|
|
4158
|
+
createArgument,
|
|
4159
|
+
createOption,
|
|
4160
|
+
CommanderError,
|
|
4161
|
+
InvalidArgumentError,
|
|
4162
|
+
InvalidOptionArgumentError,
|
|
4163
|
+
Command,
|
|
4164
|
+
Argument,
|
|
4165
|
+
Option,
|
|
4166
|
+
Help
|
|
4167
|
+
} = import__.default;
|
|
4168
|
+
|
|
4169
|
+
// src/constants.ts
|
|
4170
|
+
var ALL_ROLES = [
|
|
4171
|
+
"project-manager",
|
|
4172
|
+
"architect",
|
|
4173
|
+
"product-manager",
|
|
4174
|
+
"prompt-engineer",
|
|
4175
|
+
"fullstack-dev",
|
|
4176
|
+
"fullstack-dev-2",
|
|
4177
|
+
"frontend-dev",
|
|
4178
|
+
"qc-specialist",
|
|
4179
|
+
"qc-specialist-2",
|
|
4180
|
+
"qc-specialist-3",
|
|
4181
|
+
"qa-engineer",
|
|
4182
|
+
"ops-engineer",
|
|
4183
|
+
"writing-specialist"
|
|
4184
|
+
];
|
|
4185
|
+
var ROLE_GROUPS = {
|
|
4186
|
+
strategic: ["architect", "product-manager", "prompt-engineer"],
|
|
4187
|
+
dev: ["fullstack-dev", "fullstack-dev-2", "frontend-dev"],
|
|
4188
|
+
qc: ["qc-specialist", "qc-specialist-2", "qc-specialist-3"]
|
|
4189
|
+
};
|
|
4190
|
+
|
|
4191
|
+
// src/assignment.ts
|
|
4192
|
+
function parseSelection(rawValues, models, maxCount, singleOnly = false) {
|
|
4193
|
+
const picked = (rawValues || []).map((item) => item.trim()).filter(Boolean);
|
|
4194
|
+
if (!picked.length)
|
|
4195
|
+
return { ok: false, reason: "empty" };
|
|
4196
|
+
if (singleOnly && picked.length !== 1)
|
|
4197
|
+
return { ok: false, reason: "single_required" };
|
|
4198
|
+
if (picked.length > maxCount)
|
|
4199
|
+
return { ok: false, reason: "too_many" };
|
|
4200
|
+
const invalid = picked.filter((id) => !models.includes(id));
|
|
4201
|
+
if (invalid.length)
|
|
4202
|
+
return { ok: false, reason: "invalid", invalid };
|
|
4203
|
+
return { ok: true, value: picked };
|
|
4204
|
+
}
|
|
4205
|
+
function requireValidatedSelection(label, rawValues, models, maxCount, singleOnly = false) {
|
|
4206
|
+
const parsed = parseSelection(rawValues, models, maxCount, singleOnly);
|
|
4207
|
+
if (parsed.ok)
|
|
4208
|
+
return parsed.value;
|
|
4209
|
+
if (parsed.reason === "empty")
|
|
4210
|
+
throw new Error(`Missing option for ${label}.`);
|
|
4211
|
+
if (parsed.reason === "single_required")
|
|
4212
|
+
throw new Error(`${label} requires exactly one model.`);
|
|
4213
|
+
if (parsed.reason === "too_many")
|
|
4214
|
+
throw new Error(`${label} allows at most ${maxCount} model(s).`);
|
|
4215
|
+
throw new Error(`${label} contains invalid model(s): ${parsed.invalid.join(", ")}`);
|
|
4216
|
+
}
|
|
4217
|
+
function pickByOrder(roleIds, selectedModels) {
|
|
4218
|
+
const assignments = {};
|
|
4219
|
+
for (let i = 0;i < roleIds.length; i += 1) {
|
|
4220
|
+
assignments[roleIds[i]] = selectedModels[i % selectedModels.length];
|
|
4221
|
+
}
|
|
4222
|
+
return assignments;
|
|
4223
|
+
}
|
|
4224
|
+
function pickRandom(roleIds, selectedModels) {
|
|
4225
|
+
const assignments = {};
|
|
4226
|
+
for (const roleId of roleIds) {
|
|
4227
|
+
assignments[roleId] = selectedModels[Math.floor(Math.random() * selectedModels.length)];
|
|
4228
|
+
}
|
|
4229
|
+
return assignments;
|
|
4230
|
+
}
|
|
4231
|
+
function buildModelAssignments(selections) {
|
|
4232
|
+
const assignments = {
|
|
4233
|
+
"project-manager": selections.pm[0],
|
|
4234
|
+
...pickByOrder(ROLE_GROUPS.strategic, selections.strategic),
|
|
4235
|
+
...pickByOrder(ROLE_GROUPS.dev, selections.dev),
|
|
4236
|
+
...pickByOrder(ROLE_GROUPS.qc, selections.qc)
|
|
4237
|
+
};
|
|
4238
|
+
const assigned = new Set(Object.keys(assignments));
|
|
4239
|
+
const others = ALL_ROLES.filter((role) => !assigned.has(role));
|
|
4240
|
+
return { ...assignments, ...pickRandom(others, selections.others) };
|
|
4241
|
+
}
|
|
4242
|
+
|
|
4243
|
+
// src/adapters/cursor.ts
|
|
4244
|
+
import fs from "node:fs";
|
|
4245
|
+
import os from "node:os";
|
|
4246
|
+
import path3 from "node:path";
|
|
4247
|
+
import { execFileSync } from "node:child_process";
|
|
4248
|
+
|
|
4249
|
+
// src/utils.ts
|
|
4250
|
+
import path2 from "node:path";
|
|
4251
|
+
function normalizeModelList(raw) {
|
|
4252
|
+
return raw.split(`
|
|
4253
|
+
`).map((line) => line.trim()).filter(Boolean);
|
|
4254
|
+
}
|
|
4255
|
+
function ensureObject(value) {
|
|
4256
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
4257
|
+
return value;
|
|
4258
|
+
return {};
|
|
4259
|
+
}
|
|
4260
|
+
function resolveProjectRoot() {
|
|
4261
|
+
const candidate = process.env.MSTAR_CLI_PROJECT_ROOT || process.env.INIT_CWD || process.env.PWD;
|
|
4262
|
+
if (candidate && candidate.trim())
|
|
4263
|
+
return path2.resolve(candidate);
|
|
4264
|
+
return process.cwd();
|
|
4265
|
+
}
|
|
4266
|
+
|
|
4267
|
+
// src/adapters/cursor.ts
|
|
4268
|
+
var REPO_URL = "https://github.com/btspoony/mstar-harness.git";
|
|
4269
|
+
var CURSOR_PLUGIN_NAME = "mstar-harness";
|
|
4270
|
+
var CURSOR_PLUGIN_MARKER = ".cursor-plugin/plugin.json";
|
|
4271
|
+
function globalInstallPath() {
|
|
4272
|
+
return path3.join(os.homedir(), ".cursor", "plugins", "local", CURSOR_PLUGIN_NAME);
|
|
4273
|
+
}
|
|
4274
|
+
function projectInstallPath() {
|
|
4275
|
+
return path3.join(resolveProjectRoot(), ".cursor", "plugins", CURSOR_PLUGIN_NAME);
|
|
4276
|
+
}
|
|
4277
|
+
function ensureDir(dirPath, dryRun) {
|
|
4278
|
+
if (dryRun)
|
|
4279
|
+
return;
|
|
4280
|
+
if (!fs.existsSync(dirPath))
|
|
4281
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
4282
|
+
}
|
|
4283
|
+
function runCommand(command, cwd, dryRun) {
|
|
4284
|
+
if (dryRun)
|
|
4285
|
+
return;
|
|
4286
|
+
execFileSync(command[0], command.slice(1), { cwd, stdio: "pipe", encoding: "utf8" });
|
|
4287
|
+
}
|
|
4288
|
+
function globalInit(dryRun) {
|
|
4289
|
+
const location = globalInstallPath();
|
|
4290
|
+
const notes = [];
|
|
4291
|
+
if (fs.existsSync(location)) {
|
|
4292
|
+
notes.push(`Plugin already exists at ${location}`);
|
|
4293
|
+
return { location, notes };
|
|
4294
|
+
}
|
|
4295
|
+
ensureDir(path3.dirname(location), dryRun);
|
|
4296
|
+
runCommand(["git", "clone", REPO_URL, location], path3.dirname(location), dryRun);
|
|
4297
|
+
notes.push(`Cloned ${REPO_URL} to ${location}`);
|
|
4298
|
+
return { location, notes };
|
|
4299
|
+
}
|
|
4300
|
+
function projectInit(dryRun) {
|
|
4301
|
+
const projectRoot = resolveProjectRoot();
|
|
4302
|
+
const location = projectInstallPath();
|
|
4303
|
+
const notes = [];
|
|
4304
|
+
if (fs.existsSync(location)) {
|
|
4305
|
+
notes.push(`Submodule path already exists at ${location}`);
|
|
4306
|
+
return { location, notes };
|
|
4307
|
+
}
|
|
4308
|
+
runCommand(["git", "rev-parse", "--is-inside-work-tree"], projectRoot, dryRun);
|
|
4309
|
+
ensureDir(path3.join(projectRoot, ".cursor", "plugins"), dryRun);
|
|
4310
|
+
runCommand(["git", "submodule", "add", REPO_URL, ".cursor/plugins/mstar-harness"], projectRoot, dryRun);
|
|
4311
|
+
notes.push("Added mstar-harness as git submodule at .cursor/plugins/mstar-harness");
|
|
4312
|
+
return { location, notes };
|
|
4313
|
+
}
|
|
4314
|
+
function globalDoctor() {
|
|
4315
|
+
const location = globalInstallPath();
|
|
4316
|
+
const errors2 = [];
|
|
4317
|
+
if (!fs.existsSync(location)) {
|
|
4318
|
+
errors2.push(`Missing plugin directory: ${location}`);
|
|
4319
|
+
return { location, errors: errors2 };
|
|
4320
|
+
}
|
|
4321
|
+
const marker = path3.join(location, CURSOR_PLUGIN_MARKER);
|
|
4322
|
+
if (!fs.existsSync(marker)) {
|
|
4323
|
+
errors2.push(`Missing Cursor plugin marker file: ${marker}`);
|
|
4324
|
+
}
|
|
4325
|
+
return { location, errors: errors2 };
|
|
4326
|
+
}
|
|
4327
|
+
function projectDoctor() {
|
|
4328
|
+
const projectRoot = resolveProjectRoot();
|
|
4329
|
+
const location = projectInstallPath();
|
|
4330
|
+
const errors2 = [];
|
|
4331
|
+
if (!fs.existsSync(location)) {
|
|
4332
|
+
errors2.push(`Missing submodule directory: ${location}`);
|
|
4333
|
+
}
|
|
4334
|
+
const gitmodulesPath = path3.join(projectRoot, ".gitmodules");
|
|
4335
|
+
if (!fs.existsSync(gitmodulesPath)) {
|
|
4336
|
+
errors2.push("Missing .gitmodules (expected cursor plugin submodule entry).");
|
|
4337
|
+
return { location, errors: errors2 };
|
|
4338
|
+
}
|
|
4339
|
+
const gitmodules = fs.readFileSync(gitmodulesPath, "utf8");
|
|
4340
|
+
if (!gitmodules.includes("path = .cursor/plugins/mstar-harness")) {
|
|
4341
|
+
errors2.push("Missing .cursor/plugins/mstar-harness entry in .gitmodules.");
|
|
4342
|
+
}
|
|
4343
|
+
return { location, errors: errors2 };
|
|
4344
|
+
}
|
|
4345
|
+
var cursorAdapter = {
|
|
4346
|
+
target: "cursor",
|
|
4347
|
+
mode: "install",
|
|
4348
|
+
runInstallInit: (scope, dryRun) => {
|
|
4349
|
+
if (scope === "global")
|
|
4350
|
+
return globalInit(dryRun);
|
|
4351
|
+
return projectInit(dryRun);
|
|
4352
|
+
},
|
|
4353
|
+
runInstallDoctor: (scope) => {
|
|
4354
|
+
if (scope === "global")
|
|
4355
|
+
return globalDoctor();
|
|
4356
|
+
return projectDoctor();
|
|
4357
|
+
}
|
|
4358
|
+
};
|
|
4359
|
+
|
|
4360
|
+
// src/adapters/opencode.ts
|
|
4361
|
+
import os2 from "node:os";
|
|
4362
|
+
import path4 from "node:path";
|
|
4363
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
4364
|
+
var OPENCODE_CONFIG_SCHEMA = "https://opencode.ai/config.json";
|
|
4365
|
+
var MSTAR_OPENCODE_PLUGIN = "@mstar-harness/opencode@latest";
|
|
4366
|
+
function isLegacyMorningStarGitPlugin(plugin) {
|
|
4367
|
+
const raw = plugin.trim();
|
|
4368
|
+
const match = /^morning-star@git\+(.+)$/i.exec(raw);
|
|
4369
|
+
if (!match)
|
|
4370
|
+
return false;
|
|
4371
|
+
const spec = match[1].split("#")[0].trim().toLowerCase();
|
|
4372
|
+
return /^https?:\/\/github\.com\/btspoony\/mstar-harness(\.git)?(\/.*)?$/.test(spec) || /^ssh:\/\/git@github\.com\/btspoony\/mstar-harness(\.git)?(\/.*)?$/.test(spec) || /^git@github\.com:btspoony\/mstar-harness(\.git)?$/.test(spec);
|
|
4373
|
+
}
|
|
4374
|
+
function isMstarHarnessOpencodePlugin(plugin) {
|
|
4375
|
+
const p = plugin.trim();
|
|
4376
|
+
return p === "@mstar-harness/opencode" || p.startsWith("@mstar-harness/opencode@");
|
|
4377
|
+
}
|
|
4378
|
+
function isAnyMstarHarnessOpencodeSlot(plugin) {
|
|
4379
|
+
return isLegacyMorningStarGitPlugin(plugin) || isMstarHarnessOpencodePlugin(plugin);
|
|
4380
|
+
}
|
|
4381
|
+
function getOpencodeModels() {
|
|
4382
|
+
const raw = execFileSync2("opencode", ["models"], { encoding: "utf8" });
|
|
4383
|
+
const models = normalizeModelList(raw);
|
|
4384
|
+
if (!models.length)
|
|
4385
|
+
throw new Error("`opencode models` returned no model entries.");
|
|
4386
|
+
return models;
|
|
4387
|
+
}
|
|
4388
|
+
function resolveOpencodeConfigPath(scope, outputPath) {
|
|
4389
|
+
if (outputPath && outputPath.trim()) {
|
|
4390
|
+
const raw = outputPath.trim();
|
|
4391
|
+
return path4.isAbsolute(raw) ? raw : path4.join(resolveProjectRoot(), raw);
|
|
4392
|
+
}
|
|
4393
|
+
if (scope === "global")
|
|
4394
|
+
return path4.join(os2.homedir(), ".config", "opencode", "opencode.json");
|
|
4395
|
+
return path4.join(resolveProjectRoot(), "opencode.json");
|
|
4396
|
+
}
|
|
4397
|
+
function ensureConfigSchema(config) {
|
|
4398
|
+
const next = ensureObject(config);
|
|
4399
|
+
next.$schema = OPENCODE_CONFIG_SCHEMA;
|
|
4400
|
+
return next;
|
|
4401
|
+
}
|
|
4402
|
+
function updatePluginList(config) {
|
|
4403
|
+
const next = ensureObject(config);
|
|
4404
|
+
const existing = Array.isArray(next.plugin) ? next.plugin : [];
|
|
4405
|
+
const result = [];
|
|
4406
|
+
for (const item of existing) {
|
|
4407
|
+
if (typeof item !== "string")
|
|
4408
|
+
continue;
|
|
4409
|
+
const plugin = item.trim();
|
|
4410
|
+
if (!plugin)
|
|
4411
|
+
continue;
|
|
4412
|
+
if (isAnyMstarHarnessOpencodeSlot(plugin))
|
|
4413
|
+
continue;
|
|
4414
|
+
if (!result.includes(plugin))
|
|
4415
|
+
result.push(plugin);
|
|
4416
|
+
}
|
|
4417
|
+
if (!result.includes(MSTAR_OPENCODE_PLUGIN))
|
|
4418
|
+
result.push(MSTAR_OPENCODE_PLUGIN);
|
|
4419
|
+
next.plugin = result;
|
|
4420
|
+
return next;
|
|
4421
|
+
}
|
|
4422
|
+
function applyAssignments(config, assignments) {
|
|
4423
|
+
const next = ensureObject(config);
|
|
4424
|
+
const agent = ensureObject(next.agent);
|
|
4425
|
+
next.agent = agent;
|
|
4426
|
+
for (const [roleId, modelId] of Object.entries(assignments)) {
|
|
4427
|
+
const roleConfig = ensureObject(agent[roleId]);
|
|
4428
|
+
roleConfig.model = modelId;
|
|
4429
|
+
agent[roleId] = roleConfig;
|
|
4430
|
+
}
|
|
4431
|
+
return next;
|
|
4432
|
+
}
|
|
4433
|
+
function validateSetup(config) {
|
|
4434
|
+
const errors2 = [];
|
|
4435
|
+
if (config.$schema !== OPENCODE_CONFIG_SCHEMA) {
|
|
4436
|
+
errors2.push(`Missing or invalid $schema (expected: ${OPENCODE_CONFIG_SCHEMA}).`);
|
|
4437
|
+
}
|
|
4438
|
+
const plugins = Array.isArray(config.plugin) ? config.plugin : [];
|
|
4439
|
+
const hasMstarOpencode = plugins.some((item) => typeof item === "string" && isAnyMstarHarnessOpencodeSlot(item.trim()));
|
|
4440
|
+
if (!hasMstarOpencode)
|
|
4441
|
+
errors2.push("Missing @mstar-harness/opencode plugin entry in `plugin` (or legacy morning-star git plugin).");
|
|
4442
|
+
const agent = ensureObject(config.agent);
|
|
4443
|
+
for (const roleId of ALL_ROLES) {
|
|
4444
|
+
const role = ensureObject(agent[roleId]);
|
|
4445
|
+
if (typeof role.model !== "string" || !role.model.trim()) {
|
|
4446
|
+
errors2.push(`Missing model for role: ${roleId}`);
|
|
4447
|
+
}
|
|
4448
|
+
}
|
|
4449
|
+
return errors2;
|
|
4450
|
+
}
|
|
4451
|
+
function getDoctorWarnings(config) {
|
|
4452
|
+
const plugins = Array.isArray(config.plugin) ? config.plugin : [];
|
|
4453
|
+
const strings = plugins.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean);
|
|
4454
|
+
const hasNpm = strings.some(isMstarHarnessOpencodePlugin);
|
|
4455
|
+
const hasLegacy = strings.some(isLegacyMorningStarGitPlugin);
|
|
4456
|
+
if (hasLegacy && !hasNpm) {
|
|
4457
|
+
return [
|
|
4458
|
+
"Plugin list uses legacy `morning-star@git+…` for this harness; run `mstar-harness init --target opencode` (or `--yes` with model flags) to rewrite to `@mstar-harness/opencode@latest`."
|
|
4459
|
+
];
|
|
4460
|
+
}
|
|
4461
|
+
if (hasLegacy && hasNpm) {
|
|
4462
|
+
return [
|
|
4463
|
+
"Both legacy `morning-star@git+…` and `@mstar-harness/opencode` appear in `plugin`; run `init` again to dedupe and keep a single npm plugin line."
|
|
4464
|
+
];
|
|
4465
|
+
}
|
|
4466
|
+
return [];
|
|
4467
|
+
}
|
|
4468
|
+
var opencodeAdapter = {
|
|
4469
|
+
target: "opencode",
|
|
4470
|
+
mode: "config",
|
|
4471
|
+
getAvailableModels: () => getOpencodeModels(),
|
|
4472
|
+
resolveConfigPath: (scope, outputPath) => resolveOpencodeConfigPath(scope, outputPath),
|
|
4473
|
+
mutateConfigForInit: (config, assignments) => {
|
|
4474
|
+
const withSchema = ensureConfigSchema(config);
|
|
4475
|
+
const withPlugin = updatePluginList(withSchema);
|
|
4476
|
+
return applyAssignments(withPlugin, assignments);
|
|
4477
|
+
},
|
|
4478
|
+
validateConfig: (config) => validateSetup(config),
|
|
4479
|
+
getDoctorWarnings: (config) => getDoctorWarnings(config),
|
|
4480
|
+
printPostSetupSummary: () => {
|
|
4481
|
+
console.log(`Schema: ${OPENCODE_CONFIG_SCHEMA} (ensured)`);
|
|
4482
|
+
console.log(`Plugin: ${MSTAR_OPENCODE_PLUGIN} (ensured; legacy git morning-star entries removed)`);
|
|
4483
|
+
}
|
|
4484
|
+
};
|
|
4485
|
+
|
|
4486
|
+
// src/adapters/index.ts
|
|
4487
|
+
var adapters = {
|
|
4488
|
+
opencode: opencodeAdapter,
|
|
4489
|
+
cursor: cursorAdapter
|
|
4490
|
+
};
|
|
4491
|
+
function getAdapter(target) {
|
|
4492
|
+
const adapter = adapters[target];
|
|
4493
|
+
if (!adapter)
|
|
4494
|
+
throw new Error(`Unsupported target: ${target}`);
|
|
4495
|
+
return adapter;
|
|
4496
|
+
}
|
|
4497
|
+
|
|
4498
|
+
// src/types.ts
|
|
4499
|
+
var SUPPORTED_TARGETS = ["opencode", "cursor"];
|
|
4500
|
+
|
|
4501
|
+
// src/utils.ts
|
|
4502
|
+
import fs2 from "node:fs";
|
|
4503
|
+
import path5 from "node:path";
|
|
4504
|
+
function parseCsv(raw) {
|
|
4505
|
+
if (!raw)
|
|
4506
|
+
return;
|
|
4507
|
+
return raw.split(",").map((item) => item.trim()).filter(Boolean);
|
|
4508
|
+
}
|
|
4509
|
+
function readJson(filePath) {
|
|
4510
|
+
if (!fs2.existsSync(filePath))
|
|
4511
|
+
return {};
|
|
4512
|
+
const content = fs2.readFileSync(filePath, "utf8").trim();
|
|
4513
|
+
if (!content)
|
|
4514
|
+
return {};
|
|
4515
|
+
try {
|
|
4516
|
+
return JSON.parse(content);
|
|
4517
|
+
} catch (error) {
|
|
4518
|
+
throw new Error(`Invalid JSON in ${filePath}: ${error.message}`);
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
function writeJson(filePath, value) {
|
|
4522
|
+
const parent = path5.dirname(filePath);
|
|
4523
|
+
if (!fs2.existsSync(parent))
|
|
4524
|
+
fs2.mkdirSync(parent, { recursive: true });
|
|
4525
|
+
fs2.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}
|
|
4526
|
+
`, "utf8");
|
|
4527
|
+
}
|
|
4528
|
+
|
|
4529
|
+
// src/index.ts
|
|
4530
|
+
var packageJsonPath = path6.resolve(path6.dirname(fileURLToPath(import.meta.url)), "../package.json");
|
|
4531
|
+
var packageVersion = (() => {
|
|
4532
|
+
try {
|
|
4533
|
+
const parsed = JSON.parse(fs3.readFileSync(packageJsonPath, "utf8"));
|
|
4534
|
+
return parsed.version || "0.0.0";
|
|
4535
|
+
} catch {
|
|
4536
|
+
return "0.0.0";
|
|
4537
|
+
}
|
|
4538
|
+
})();
|
|
4539
|
+
var program2 = new Command;
|
|
4540
|
+
function logStep(message) {
|
|
4541
|
+
console.log(import_picocolors.default.cyan(message));
|
|
4542
|
+
}
|
|
4543
|
+
async function pickTargetInteractive() {
|
|
4544
|
+
return dist_default5({
|
|
4545
|
+
message: "Select install target",
|
|
4546
|
+
choices: SUPPORTED_TARGETS.map((target) => ({ name: target, value: target }))
|
|
4547
|
+
});
|
|
4548
|
+
}
|
|
4549
|
+
async function pickModelsInteractive(params) {
|
|
4550
|
+
const choices = params.models.map((model) => ({ name: model, value: model }));
|
|
4551
|
+
if (params.single) {
|
|
4552
|
+
const picked = await dist_default5({ message: `${params.title} (${params.hint})`, choices });
|
|
4553
|
+
return [picked];
|
|
4554
|
+
}
|
|
4555
|
+
return dist_default4({
|
|
4556
|
+
message: `${params.title} (${params.hint})`,
|
|
4557
|
+
choices,
|
|
4558
|
+
validate: (picked) => {
|
|
4559
|
+
if (picked.length < 1)
|
|
4560
|
+
return "Pick at least one model.";
|
|
4561
|
+
if (picked.length > params.maxCount)
|
|
4562
|
+
return `Pick at most ${params.maxCount} models.`;
|
|
4563
|
+
return true;
|
|
4564
|
+
}
|
|
4565
|
+
});
|
|
4566
|
+
}
|
|
4567
|
+
async function resolveSelections(options, models) {
|
|
4568
|
+
if (options.yes) {
|
|
4569
|
+
return {
|
|
4570
|
+
pm: requireValidatedSelection("pm-model", options.pmModel ? [options.pmModel] : undefined, models, 1, true),
|
|
4571
|
+
strategic: requireValidatedSelection("strategic-models", parseCsv(options.strategicModels), models, 3),
|
|
4572
|
+
dev: requireValidatedSelection("dev-models", parseCsv(options.devModels), models, 3),
|
|
4573
|
+
qc: requireValidatedSelection("qc-models", parseCsv(options.qcModels), models, 3),
|
|
4574
|
+
others: requireValidatedSelection("other-models", parseCsv(options.otherModels), models, 3)
|
|
4575
|
+
};
|
|
4576
|
+
}
|
|
4577
|
+
logStep("Step 4/7 - Configure models by role group");
|
|
4578
|
+
return {
|
|
4579
|
+
pm: await pickModelsInteractive({
|
|
4580
|
+
title: "1) project-manager",
|
|
4581
|
+
hint: "orchestrator role, prefer strong agentic model",
|
|
4582
|
+
models,
|
|
4583
|
+
maxCount: 1,
|
|
4584
|
+
single: true
|
|
4585
|
+
}),
|
|
4586
|
+
strategic: await pickModelsInteractive({
|
|
4587
|
+
title: "2) architect / product-manager / prompt-engineer",
|
|
4588
|
+
hint: "decision-heavy roles, prefer high intelligence",
|
|
4589
|
+
models,
|
|
4590
|
+
maxCount: 3
|
|
4591
|
+
}),
|
|
4592
|
+
dev: await pickModelsInteractive({
|
|
4593
|
+
title: "3) fullstack-dev / fullstack-dev-2 / frontend-dev",
|
|
4594
|
+
hint: "prefer coding-focused models",
|
|
4595
|
+
models,
|
|
4596
|
+
maxCount: 3
|
|
4597
|
+
}),
|
|
4598
|
+
qc: await pickModelsInteractive({
|
|
4599
|
+
title: "4) qc-specialist / qc-specialist-2 / qc-specialist-3",
|
|
4600
|
+
hint: "prefer three distinct models",
|
|
4601
|
+
models,
|
|
4602
|
+
maxCount: 3
|
|
4603
|
+
}),
|
|
4604
|
+
others: await pickModelsInteractive({
|
|
4605
|
+
title: "5) other roles",
|
|
4606
|
+
hint: "up to 3 models, random assignment",
|
|
4607
|
+
models,
|
|
4608
|
+
maxCount: 3
|
|
4609
|
+
})
|
|
4610
|
+
};
|
|
4611
|
+
}
|
|
4612
|
+
async function runInit(options) {
|
|
4613
|
+
const target = options.target || (options.yes ? "opencode" : await pickTargetInteractive());
|
|
4614
|
+
const scope = options.scope || "project";
|
|
4615
|
+
const adapter = getAdapter(target);
|
|
4616
|
+
if (!options.scope && !options.yes) {
|
|
4617
|
+
console.log(import_picocolors.default.dim("Scope not provided; defaulting to project."));
|
|
4618
|
+
}
|
|
4619
|
+
if (adapter.mode === "install") {
|
|
4620
|
+
logStep("Step 2/2 - Run target install flow");
|
|
4621
|
+
const installResult = adapter.runInstallInit?.(scope, !!options.dryRun);
|
|
4622
|
+
if (!installResult) {
|
|
4623
|
+
throw new Error(`Adapter ${target} does not implement install init flow.`);
|
|
4624
|
+
}
|
|
4625
|
+
console.log(import_picocolors.default.green(`Status: ${options.dryRun ? "ready (dry-run)" : "configured"} (${scope})`));
|
|
4626
|
+
console.log(`Target: ${target}`);
|
|
4627
|
+
console.log(`Install location: ${installResult.location}`);
|
|
4628
|
+
for (const note of installResult.notes) {
|
|
4629
|
+
console.log(` - ${note}`);
|
|
4630
|
+
}
|
|
4631
|
+
return;
|
|
4632
|
+
}
|
|
4633
|
+
logStep(`Step 3/7 - Fetch available models from ${adapter.target}`);
|
|
4634
|
+
const models = adapter.getAvailableModels?.();
|
|
4635
|
+
if (!models)
|
|
4636
|
+
throw new Error(`Adapter ${target} does not implement model discovery.`);
|
|
4637
|
+
const selections = await resolveSelections(options, models);
|
|
4638
|
+
logStep("Step 5/7 - Build role model assignments");
|
|
4639
|
+
const assignments = buildModelAssignments(selections);
|
|
4640
|
+
logStep("Step 6/7 - Update config");
|
|
4641
|
+
const configPath = adapter.resolveConfigPath?.(scope, options.output);
|
|
4642
|
+
if (!configPath)
|
|
4643
|
+
throw new Error(`Adapter ${target} does not implement config path resolution.`);
|
|
4644
|
+
const current = readJson(configPath);
|
|
4645
|
+
const updated = adapter.mutateConfigForInit?.(current, assignments);
|
|
4646
|
+
if (!updated)
|
|
4647
|
+
throw new Error(`Adapter ${target} does not implement init mutation.`);
|
|
4648
|
+
logStep("Step 7/7 - Self-check");
|
|
4649
|
+
const checkErrors = adapter.validateConfig?.(updated) || [];
|
|
4650
|
+
if (checkErrors.length) {
|
|
4651
|
+
throw new Error(`Configuration verification failed:
|
|
4652
|
+
- ${checkErrors.join(`
|
|
4653
|
+
- `)}`);
|
|
4654
|
+
}
|
|
4655
|
+
if (!options.dryRun) {
|
|
4656
|
+
writeJson(configPath, updated);
|
|
4657
|
+
const persistedErrors = adapter.validateConfig?.(readJson(configPath)) || [];
|
|
4658
|
+
if (persistedErrors.length) {
|
|
4659
|
+
throw new Error(`Post-write verification failed:
|
|
4660
|
+
- ${persistedErrors.join(`
|
|
4661
|
+
- `)}`);
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
console.log(import_picocolors.default.green(`Status: ${options.dryRun ? "ready (dry-run)" : "configured"} (${scope})`));
|
|
4665
|
+
console.log(`Target: ${target}`);
|
|
4666
|
+
console.log(`Config file: ${configPath}`);
|
|
4667
|
+
if (adapter.printPostSetupSummary)
|
|
4668
|
+
adapter.printPostSetupSummary(updated);
|
|
4669
|
+
console.log("Assigned roles:");
|
|
4670
|
+
for (const [roleId, modelId] of Object.entries(assignments)) {
|
|
4671
|
+
console.log(` - ${roleId}: ${modelId}`);
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
function runDoctor(options) {
|
|
4675
|
+
const target = options.target || "opencode";
|
|
4676
|
+
const adapter = getAdapter(target);
|
|
4677
|
+
const scope = options.scope || "project";
|
|
4678
|
+
console.log(`Target: ${target}`);
|
|
4679
|
+
if (adapter.mode === "install") {
|
|
4680
|
+
const result = adapter.runInstallDoctor?.(scope);
|
|
4681
|
+
if (!result) {
|
|
4682
|
+
throw new Error(`Adapter ${target} does not implement install doctor flow.`);
|
|
4683
|
+
}
|
|
4684
|
+
console.log(`Install location: ${result.location}`);
|
|
4685
|
+
if (!result.errors.length) {
|
|
4686
|
+
console.log(import_picocolors.default.green("Doctor result: healthy"));
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
console.log(import_picocolors.default.red(`Doctor result: ${result.errors.length} issue(s)`));
|
|
4690
|
+
for (const issue of result.errors)
|
|
4691
|
+
console.log(` - ${issue}`);
|
|
4692
|
+
process.exitCode = 1;
|
|
4693
|
+
return;
|
|
4694
|
+
}
|
|
4695
|
+
const configPath = adapter.resolveConfigPath?.(scope, options.output);
|
|
4696
|
+
if (!configPath) {
|
|
4697
|
+
throw new Error(`Adapter ${target} does not implement config doctor flow.`);
|
|
4698
|
+
}
|
|
4699
|
+
const config = readJson(configPath);
|
|
4700
|
+
const errors2 = adapter.validateConfig?.(config) || [];
|
|
4701
|
+
console.log(`Config file: ${configPath}`);
|
|
4702
|
+
if (!errors2.length) {
|
|
4703
|
+
const warnings = adapter.getDoctorWarnings?.(config) || [];
|
|
4704
|
+
if (warnings.length) {
|
|
4705
|
+
console.log(import_picocolors.default.yellow(`Doctor: ${warnings.length} recommendation(s) (still healthy):`));
|
|
4706
|
+
for (const line of warnings)
|
|
4707
|
+
console.log(` - ${line}`);
|
|
4708
|
+
}
|
|
4709
|
+
console.log(import_picocolors.default.green("Doctor result: healthy"));
|
|
4710
|
+
return;
|
|
4711
|
+
}
|
|
4712
|
+
console.log(import_picocolors.default.red(`Doctor result: ${errors2.length} issue(s)`));
|
|
4713
|
+
for (const issue of errors2)
|
|
4714
|
+
console.log(` - ${issue}`);
|
|
4715
|
+
process.exitCode = 1;
|
|
4716
|
+
}
|
|
4717
|
+
program2.name("mstar-harness").description("Morning Star harness CLI for target-based agent bootstrap").version(packageVersion);
|
|
4718
|
+
program2.command("init").description("Interactive/non-interactive setup for target agent bootstrap").option("-y, --yes", "Non-interactive mode").option("--target <target>", "Install target", "opencode").option("--scope <scope>", "Config scope: global|project (default: project)").option("--output <path>", "Config file path override, relative to project root").option("--dry-run", "Preview result without writing config").option("--pm-model <model>", "Model for project-manager").option("--strategic-models <a,b,c>", "Models for architect/product-manager/prompt-engineer").option("--dev-models <a,b,c>", "Models for fullstack-dev/fullstack-dev-2/frontend-dev").option("--qc-models <a,b,c>", "Models for qc trio").option("--other-models <a,b,c>", "Models for random assignment to remaining roles").action(async (options) => {
|
|
4719
|
+
await runInit(options);
|
|
4720
|
+
});
|
|
4721
|
+
program2.command("doctor").description("Validate Morning Star setup for a target agent config").option("--target <target>", "Target agent for doctor checks", "opencode").option("--scope <scope>", "Config scope: global|project", "project").option("--output <path>", "Config file path override, relative to project root").action((options) => {
|
|
4722
|
+
runDoctor(options);
|
|
4723
|
+
});
|
|
4724
|
+
program2.parseAsync(process.argv).catch((error) => {
|
|
4725
|
+
console.error(import_picocolors.default.red(`Setup failed: ${error.message}`));
|
|
4726
|
+
process.exit(1);
|
|
4727
|
+
});
|