@parix/cli 0.1.8 → 0.1.9
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/cli.cjs +4296 -35
- package/package.json +2 -2
- package/dist/cli.d.cts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -36
- package/dist/commands/api.cjs +0 -81
- package/dist/commands/api.d.cts +0 -2
- package/dist/commands/api.d.ts +0 -2
- package/dist/commands/api.js +0 -78
- package/dist/commands/auth.cjs +0 -131
- package/dist/commands/auth.d.cts +0 -2
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -128
- package/dist/commands/database.cjs +0 -259
- package/dist/commands/database.d.cts +0 -2
- package/dist/commands/database.d.ts +0 -2
- package/dist/commands/database.js +0 -256
- package/dist/commands/skill-content.cjs +0 -77
- package/dist/commands/skill-content.d.cts +0 -1
- package/dist/commands/skill-content.d.ts +0 -1
- package/dist/commands/skill-content.js +0 -74
- package/dist/commands/skill.cjs +0 -10
- package/dist/commands/skill.d.cts +0 -2
- package/dist/commands/skill.d.ts +0 -2
- package/dist/commands/skill.js +0 -7
- package/dist/commands/tb.cjs +0 -254
- package/dist/commands/tb.d.cts +0 -2
- package/dist/commands/tb.d.ts +0 -2
- package/dist/commands/tb.js +0 -251
- package/dist/lib/api-client.cjs +0 -44
- package/dist/lib/api-client.d.cts +0 -10
- package/dist/lib/api-client.d.ts +0 -10
- package/dist/lib/api-client.js +0 -40
- package/dist/lib/config.cjs +0 -24
- package/dist/lib/config.d.cts +0 -10
- package/dist/lib/config.d.ts +0 -10
- package/dist/lib/config.js +0 -18
- package/dist/lib/loopback-server.cjs +0 -180
- package/dist/lib/loopback-server.d.cts +0 -20
- package/dist/lib/loopback-server.d.ts +0 -20
- package/dist/lib/loopback-server.js +0 -177
- package/dist/lib/oauth-api.cjs +0 -73
- package/dist/lib/oauth-api.d.cts +0 -31
- package/dist/lib/oauth-api.d.ts +0 -31
- package/dist/lib/oauth-api.js +0 -68
- package/dist/lib/oauth-session.cjs +0 -108
- package/dist/lib/oauth-session.d.cts +0 -32
- package/dist/lib/oauth-session.d.ts +0 -32
- package/dist/lib/oauth-session.js +0 -103
- package/dist/lib/oauth.cjs +0 -58
- package/dist/lib/oauth.d.cts +0 -19
- package/dist/lib/oauth.d.ts +0 -19
- package/dist/lib/oauth.js +0 -49
- package/dist/lib/open-url.cjs +0 -38
- package/dist/lib/open-url.d.cts +0 -1
- package/dist/lib/open-url.d.ts +0 -1
- package/dist/lib/open-url.js +0 -32
- package/dist/lib/output.cjs +0 -20
- package/dist/lib/output.d.cts +0 -6
- package/dist/lib/output.d.ts +0 -6
- package/dist/lib/output.js +0 -15
- package/dist/lib/parix-api.cjs +0 -59
- package/dist/lib/parix-api.d.cts +0 -12
- package/dist/lib/parix-api.d.ts +0 -12
- package/dist/lib/parix-api.js +0 -55
- package/dist/lib/session.cjs +0 -80
- package/dist/lib/session.d.cts +0 -28
- package/dist/lib/session.d.ts +0 -28
- package/dist/lib/session.js +0 -74
- package/dist/lib/tb-payloads.cjs +0 -258
- package/dist/lib/tb-payloads.d.cts +0 -66
- package/dist/lib/tb-payloads.d.ts +0 -66
- package/dist/lib/tb-payloads.js +0 -249
package/dist/cli.cjs
CHANGED
|
@@ -1,38 +1,4299 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
|
|
34
|
+
// node_modules/sisteransi/src/index.js
|
|
35
|
+
var require_src = __commonJS((exports2, module2) => {
|
|
36
|
+
var ESC = "\x1B";
|
|
37
|
+
var CSI = `${ESC}[`;
|
|
38
|
+
var beep = "\x07";
|
|
39
|
+
var cursor = {
|
|
40
|
+
to(x, y) {
|
|
41
|
+
if (!y)
|
|
42
|
+
return `${CSI}${x + 1}G`;
|
|
43
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
44
|
+
},
|
|
45
|
+
move(x, y) {
|
|
46
|
+
let ret = "";
|
|
47
|
+
if (x < 0)
|
|
48
|
+
ret += `${CSI}${-x}D`;
|
|
49
|
+
else if (x > 0)
|
|
50
|
+
ret += `${CSI}${x}C`;
|
|
51
|
+
if (y < 0)
|
|
52
|
+
ret += `${CSI}${-y}A`;
|
|
53
|
+
else if (y > 0)
|
|
54
|
+
ret += `${CSI}${y}B`;
|
|
55
|
+
return ret;
|
|
56
|
+
},
|
|
57
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
58
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
59
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
60
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
61
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
62
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
63
|
+
left: `${CSI}G`,
|
|
64
|
+
hide: `${CSI}?25l`,
|
|
65
|
+
show: `${CSI}?25h`,
|
|
66
|
+
save: `${ESC}7`,
|
|
67
|
+
restore: `${ESC}8`
|
|
68
|
+
};
|
|
69
|
+
var scroll = {
|
|
70
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
71
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
72
|
+
};
|
|
73
|
+
var erase = {
|
|
74
|
+
screen: `${CSI}2J`,
|
|
75
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
76
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
77
|
+
line: `${CSI}2K`,
|
|
78
|
+
lineEnd: `${CSI}K`,
|
|
79
|
+
lineStart: `${CSI}1K`,
|
|
80
|
+
lines(count) {
|
|
81
|
+
let clear = "";
|
|
82
|
+
for (let i = 0;i < count; i++)
|
|
83
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
84
|
+
if (count)
|
|
85
|
+
clear += cursor.left;
|
|
86
|
+
return clear;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
module2.exports = { cursor, scroll, erase, beep };
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// node_modules/picocolors/picocolors.js
|
|
93
|
+
var require_picocolors = __commonJS((exports2, module2) => {
|
|
94
|
+
var p = process || {};
|
|
95
|
+
var argv = p.argv || [];
|
|
96
|
+
var env = p.env || {};
|
|
97
|
+
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);
|
|
98
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
99
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
100
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
101
|
+
};
|
|
102
|
+
var replaceClose = (string, close, replace, index) => {
|
|
103
|
+
let result = "", cursor = 0;
|
|
104
|
+
do {
|
|
105
|
+
result += string.substring(cursor, index) + replace;
|
|
106
|
+
cursor = index + close.length;
|
|
107
|
+
index = string.indexOf(close, cursor);
|
|
108
|
+
} while (~index);
|
|
109
|
+
return result + string.substring(cursor);
|
|
110
|
+
};
|
|
111
|
+
var createColors = (enabled = isColorSupported) => {
|
|
112
|
+
let f = enabled ? formatter : () => String;
|
|
113
|
+
return {
|
|
114
|
+
isColorSupported: enabled,
|
|
115
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
116
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
117
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
118
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
119
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
120
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
121
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
122
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
123
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
124
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
125
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
126
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
127
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
128
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
129
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
130
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
131
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
132
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
133
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
134
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
135
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
136
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
137
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
138
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
139
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
140
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
141
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
142
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
143
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
144
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
145
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
146
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
147
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
148
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
149
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
150
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
151
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
152
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
153
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
154
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
155
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
module2.exports = createColors();
|
|
159
|
+
module2.exports.createColors = createColors;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// node_modules/commander/lib/error.js
|
|
163
|
+
var require_error = __commonJS((exports2) => {
|
|
164
|
+
class CommanderError extends Error {
|
|
165
|
+
constructor(exitCode, code, message) {
|
|
166
|
+
super(message);
|
|
167
|
+
Error.captureStackTrace(this, this.constructor);
|
|
168
|
+
this.name = this.constructor.name;
|
|
169
|
+
this.code = code;
|
|
170
|
+
this.exitCode = exitCode;
|
|
171
|
+
this.nestedError = undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
class InvalidArgumentError extends CommanderError {
|
|
176
|
+
constructor(message) {
|
|
177
|
+
super(1, "commander.invalidArgument", message);
|
|
178
|
+
Error.captureStackTrace(this, this.constructor);
|
|
179
|
+
this.name = this.constructor.name;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports2.CommanderError = CommanderError;
|
|
183
|
+
exports2.InvalidArgumentError = InvalidArgumentError;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// node_modules/commander/lib/argument.js
|
|
187
|
+
var require_argument = __commonJS((exports2) => {
|
|
188
|
+
var { InvalidArgumentError } = require_error();
|
|
189
|
+
|
|
190
|
+
class Argument {
|
|
191
|
+
constructor(name, description) {
|
|
192
|
+
this.description = description || "";
|
|
193
|
+
this.variadic = false;
|
|
194
|
+
this.parseArg = undefined;
|
|
195
|
+
this.defaultValue = undefined;
|
|
196
|
+
this.defaultValueDescription = undefined;
|
|
197
|
+
this.argChoices = undefined;
|
|
198
|
+
switch (name[0]) {
|
|
199
|
+
case "<":
|
|
200
|
+
this.required = true;
|
|
201
|
+
this._name = name.slice(1, -1);
|
|
202
|
+
break;
|
|
203
|
+
case "[":
|
|
204
|
+
this.required = false;
|
|
205
|
+
this._name = name.slice(1, -1);
|
|
206
|
+
break;
|
|
207
|
+
default:
|
|
208
|
+
this.required = true;
|
|
209
|
+
this._name = name;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
if (this._name.endsWith("...")) {
|
|
213
|
+
this.variadic = true;
|
|
214
|
+
this._name = this._name.slice(0, -3);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
name() {
|
|
218
|
+
return this._name;
|
|
219
|
+
}
|
|
220
|
+
_collectValue(value, previous) {
|
|
221
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
222
|
+
return [value];
|
|
223
|
+
}
|
|
224
|
+
previous.push(value);
|
|
225
|
+
return previous;
|
|
226
|
+
}
|
|
227
|
+
default(value, description) {
|
|
228
|
+
this.defaultValue = value;
|
|
229
|
+
this.defaultValueDescription = description;
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
argParser(fn) {
|
|
233
|
+
this.parseArg = fn;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
choices(values) {
|
|
237
|
+
this.argChoices = values.slice();
|
|
238
|
+
this.parseArg = (arg, previous) => {
|
|
239
|
+
if (!this.argChoices.includes(arg)) {
|
|
240
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
241
|
+
}
|
|
242
|
+
if (this.variadic) {
|
|
243
|
+
return this._collectValue(arg, previous);
|
|
244
|
+
}
|
|
245
|
+
return arg;
|
|
246
|
+
};
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
argRequired() {
|
|
250
|
+
this.required = true;
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
argOptional() {
|
|
254
|
+
this.required = false;
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function humanReadableArgName(arg) {
|
|
259
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
260
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
261
|
+
}
|
|
262
|
+
exports2.Argument = Argument;
|
|
263
|
+
exports2.humanReadableArgName = humanReadableArgName;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// node_modules/commander/lib/help.js
|
|
267
|
+
var require_help = __commonJS((exports2) => {
|
|
268
|
+
var { humanReadableArgName } = require_argument();
|
|
269
|
+
|
|
270
|
+
class Help {
|
|
271
|
+
constructor() {
|
|
272
|
+
this.helpWidth = undefined;
|
|
273
|
+
this.minWidthToWrap = 40;
|
|
274
|
+
this.sortSubcommands = false;
|
|
275
|
+
this.sortOptions = false;
|
|
276
|
+
this.showGlobalOptions = false;
|
|
277
|
+
}
|
|
278
|
+
prepareContext(contextOptions) {
|
|
279
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
280
|
+
}
|
|
281
|
+
visibleCommands(cmd) {
|
|
282
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
283
|
+
const helpCommand = cmd._getHelpCommand();
|
|
284
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
285
|
+
visibleCommands.push(helpCommand);
|
|
286
|
+
}
|
|
287
|
+
if (this.sortSubcommands) {
|
|
288
|
+
visibleCommands.sort((a3, b3) => {
|
|
289
|
+
return a3.name().localeCompare(b3.name());
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return visibleCommands;
|
|
293
|
+
}
|
|
294
|
+
compareOptions(a3, b3) {
|
|
295
|
+
const getSortKey = (option) => {
|
|
296
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
297
|
+
};
|
|
298
|
+
return getSortKey(a3).localeCompare(getSortKey(b3));
|
|
299
|
+
}
|
|
300
|
+
visibleOptions(cmd) {
|
|
301
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
302
|
+
const helpOption = cmd._getHelpOption();
|
|
303
|
+
if (helpOption && !helpOption.hidden) {
|
|
304
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
305
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
306
|
+
if (!removeShort && !removeLong) {
|
|
307
|
+
visibleOptions.push(helpOption);
|
|
308
|
+
} else if (helpOption.long && !removeLong) {
|
|
309
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
310
|
+
} else if (helpOption.short && !removeShort) {
|
|
311
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (this.sortOptions) {
|
|
315
|
+
visibleOptions.sort(this.compareOptions);
|
|
316
|
+
}
|
|
317
|
+
return visibleOptions;
|
|
318
|
+
}
|
|
319
|
+
visibleGlobalOptions(cmd) {
|
|
320
|
+
if (!this.showGlobalOptions)
|
|
321
|
+
return [];
|
|
322
|
+
const globalOptions = [];
|
|
323
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
324
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
325
|
+
globalOptions.push(...visibleOptions);
|
|
326
|
+
}
|
|
327
|
+
if (this.sortOptions) {
|
|
328
|
+
globalOptions.sort(this.compareOptions);
|
|
329
|
+
}
|
|
330
|
+
return globalOptions;
|
|
331
|
+
}
|
|
332
|
+
visibleArguments(cmd) {
|
|
333
|
+
if (cmd._argsDescription) {
|
|
334
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
335
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
339
|
+
return cmd.registeredArguments;
|
|
340
|
+
}
|
|
341
|
+
return [];
|
|
342
|
+
}
|
|
343
|
+
subcommandTerm(cmd) {
|
|
344
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
345
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
346
|
+
}
|
|
347
|
+
optionTerm(option) {
|
|
348
|
+
return option.flags;
|
|
349
|
+
}
|
|
350
|
+
argumentTerm(argument) {
|
|
351
|
+
return argument.name();
|
|
352
|
+
}
|
|
353
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
354
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
355
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
356
|
+
}, 0);
|
|
357
|
+
}
|
|
358
|
+
longestOptionTermLength(cmd, helper) {
|
|
359
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
360
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
361
|
+
}, 0);
|
|
362
|
+
}
|
|
363
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
364
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
365
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
366
|
+
}, 0);
|
|
367
|
+
}
|
|
368
|
+
longestArgumentTermLength(cmd, helper) {
|
|
369
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
370
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
371
|
+
}, 0);
|
|
372
|
+
}
|
|
373
|
+
commandUsage(cmd) {
|
|
374
|
+
let cmdName = cmd._name;
|
|
375
|
+
if (cmd._aliases[0]) {
|
|
376
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
377
|
+
}
|
|
378
|
+
let ancestorCmdNames = "";
|
|
379
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
380
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
381
|
+
}
|
|
382
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
383
|
+
}
|
|
384
|
+
commandDescription(cmd) {
|
|
385
|
+
return cmd.description();
|
|
386
|
+
}
|
|
387
|
+
subcommandDescription(cmd) {
|
|
388
|
+
return cmd.summary() || cmd.description();
|
|
389
|
+
}
|
|
390
|
+
optionDescription(option) {
|
|
391
|
+
const extraInfo = [];
|
|
392
|
+
if (option.argChoices) {
|
|
393
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
394
|
+
}
|
|
395
|
+
if (option.defaultValue !== undefined) {
|
|
396
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
397
|
+
if (showDefault) {
|
|
398
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
402
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
403
|
+
}
|
|
404
|
+
if (option.envVar !== undefined) {
|
|
405
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
406
|
+
}
|
|
407
|
+
if (extraInfo.length > 0) {
|
|
408
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
409
|
+
if (option.description) {
|
|
410
|
+
return `${option.description} ${extraDescription}`;
|
|
411
|
+
}
|
|
412
|
+
return extraDescription;
|
|
413
|
+
}
|
|
414
|
+
return option.description;
|
|
415
|
+
}
|
|
416
|
+
argumentDescription(argument) {
|
|
417
|
+
const extraInfo = [];
|
|
418
|
+
if (argument.argChoices) {
|
|
419
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
420
|
+
}
|
|
421
|
+
if (argument.defaultValue !== undefined) {
|
|
422
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
423
|
+
}
|
|
424
|
+
if (extraInfo.length > 0) {
|
|
425
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
426
|
+
if (argument.description) {
|
|
427
|
+
return `${argument.description} ${extraDescription}`;
|
|
428
|
+
}
|
|
429
|
+
return extraDescription;
|
|
430
|
+
}
|
|
431
|
+
return argument.description;
|
|
432
|
+
}
|
|
433
|
+
formatItemList(heading, items, helper) {
|
|
434
|
+
if (items.length === 0)
|
|
435
|
+
return [];
|
|
436
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
437
|
+
}
|
|
438
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
439
|
+
const result = new Map;
|
|
440
|
+
unsortedItems.forEach((item) => {
|
|
441
|
+
const group = getGroup(item);
|
|
442
|
+
if (!result.has(group))
|
|
443
|
+
result.set(group, []);
|
|
444
|
+
});
|
|
445
|
+
visibleItems.forEach((item) => {
|
|
446
|
+
const group = getGroup(item);
|
|
447
|
+
if (!result.has(group)) {
|
|
448
|
+
result.set(group, []);
|
|
449
|
+
}
|
|
450
|
+
result.get(group).push(item);
|
|
451
|
+
});
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
454
|
+
formatHelp(cmd, helper) {
|
|
455
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
456
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
457
|
+
function callFormatItem(term, description) {
|
|
458
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
459
|
+
}
|
|
460
|
+
let output = [
|
|
461
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
462
|
+
""
|
|
463
|
+
];
|
|
464
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
465
|
+
if (commandDescription.length > 0) {
|
|
466
|
+
output = output.concat([
|
|
467
|
+
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
468
|
+
""
|
|
469
|
+
]);
|
|
470
|
+
}
|
|
471
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
472
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
473
|
+
});
|
|
474
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
475
|
+
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
|
|
476
|
+
optionGroups.forEach((options, group) => {
|
|
477
|
+
const optionList = options.map((option) => {
|
|
478
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
479
|
+
});
|
|
480
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
481
|
+
});
|
|
482
|
+
if (helper.showGlobalOptions) {
|
|
483
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
484
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
485
|
+
});
|
|
486
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
487
|
+
}
|
|
488
|
+
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
|
|
489
|
+
commandGroups.forEach((commands, group) => {
|
|
490
|
+
const commandList = commands.map((sub) => {
|
|
491
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
492
|
+
});
|
|
493
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
494
|
+
});
|
|
495
|
+
return output.join(`
|
|
496
|
+
`);
|
|
497
|
+
}
|
|
498
|
+
displayWidth(str) {
|
|
499
|
+
return stripColor(str).length;
|
|
500
|
+
}
|
|
501
|
+
styleTitle(str) {
|
|
502
|
+
return str;
|
|
503
|
+
}
|
|
504
|
+
styleUsage(str) {
|
|
505
|
+
return str.split(" ").map((word) => {
|
|
506
|
+
if (word === "[options]")
|
|
507
|
+
return this.styleOptionText(word);
|
|
508
|
+
if (word === "[command]")
|
|
509
|
+
return this.styleSubcommandText(word);
|
|
510
|
+
if (word[0] === "[" || word[0] === "<")
|
|
511
|
+
return this.styleArgumentText(word);
|
|
512
|
+
return this.styleCommandText(word);
|
|
513
|
+
}).join(" ");
|
|
514
|
+
}
|
|
515
|
+
styleCommandDescription(str) {
|
|
516
|
+
return this.styleDescriptionText(str);
|
|
517
|
+
}
|
|
518
|
+
styleOptionDescription(str) {
|
|
519
|
+
return this.styleDescriptionText(str);
|
|
520
|
+
}
|
|
521
|
+
styleSubcommandDescription(str) {
|
|
522
|
+
return this.styleDescriptionText(str);
|
|
523
|
+
}
|
|
524
|
+
styleArgumentDescription(str) {
|
|
525
|
+
return this.styleDescriptionText(str);
|
|
526
|
+
}
|
|
527
|
+
styleDescriptionText(str) {
|
|
528
|
+
return str;
|
|
529
|
+
}
|
|
530
|
+
styleOptionTerm(str) {
|
|
531
|
+
return this.styleOptionText(str);
|
|
532
|
+
}
|
|
533
|
+
styleSubcommandTerm(str) {
|
|
534
|
+
return str.split(" ").map((word) => {
|
|
535
|
+
if (word === "[options]")
|
|
536
|
+
return this.styleOptionText(word);
|
|
537
|
+
if (word[0] === "[" || word[0] === "<")
|
|
538
|
+
return this.styleArgumentText(word);
|
|
539
|
+
return this.styleSubcommandText(word);
|
|
540
|
+
}).join(" ");
|
|
541
|
+
}
|
|
542
|
+
styleArgumentTerm(str) {
|
|
543
|
+
return this.styleArgumentText(str);
|
|
544
|
+
}
|
|
545
|
+
styleOptionText(str) {
|
|
546
|
+
return str;
|
|
547
|
+
}
|
|
548
|
+
styleArgumentText(str) {
|
|
549
|
+
return str;
|
|
550
|
+
}
|
|
551
|
+
styleSubcommandText(str) {
|
|
552
|
+
return str;
|
|
553
|
+
}
|
|
554
|
+
styleCommandText(str) {
|
|
555
|
+
return str;
|
|
556
|
+
}
|
|
557
|
+
padWidth(cmd, helper) {
|
|
558
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
559
|
+
}
|
|
560
|
+
preformatted(str) {
|
|
561
|
+
return /\n[^\S\r\n]/.test(str);
|
|
562
|
+
}
|
|
563
|
+
formatItem(term, termWidth, description, helper) {
|
|
564
|
+
const itemIndent = 2;
|
|
565
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
566
|
+
if (!description)
|
|
567
|
+
return itemIndentStr + term;
|
|
568
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
569
|
+
const spacerWidth = 2;
|
|
570
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
571
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
572
|
+
let formattedDescription;
|
|
573
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
574
|
+
formattedDescription = description;
|
|
575
|
+
} else {
|
|
576
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
577
|
+
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
578
|
+
` + " ".repeat(termWidth + spacerWidth));
|
|
579
|
+
}
|
|
580
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
581
|
+
${itemIndentStr}`);
|
|
582
|
+
}
|
|
583
|
+
boxWrap(str, width) {
|
|
584
|
+
if (width < this.minWidthToWrap)
|
|
585
|
+
return str;
|
|
586
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
587
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
588
|
+
const wrappedLines = [];
|
|
589
|
+
rawLines.forEach((line) => {
|
|
590
|
+
const chunks = line.match(chunkPattern);
|
|
591
|
+
if (chunks === null) {
|
|
592
|
+
wrappedLines.push("");
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
let sumChunks = [chunks.shift()];
|
|
596
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
597
|
+
chunks.forEach((chunk) => {
|
|
598
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
599
|
+
if (sumWidth + visibleWidth <= width) {
|
|
600
|
+
sumChunks.push(chunk);
|
|
601
|
+
sumWidth += visibleWidth;
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
wrappedLines.push(sumChunks.join(""));
|
|
605
|
+
const nextChunk = chunk.trimStart();
|
|
606
|
+
sumChunks = [nextChunk];
|
|
607
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
608
|
+
});
|
|
609
|
+
wrappedLines.push(sumChunks.join(""));
|
|
610
|
+
});
|
|
611
|
+
return wrappedLines.join(`
|
|
612
|
+
`);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function stripColor(str) {
|
|
616
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
617
|
+
return str.replace(sgrPattern, "");
|
|
618
|
+
}
|
|
619
|
+
exports2.Help = Help;
|
|
620
|
+
exports2.stripColor = stripColor;
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// node_modules/commander/lib/option.js
|
|
624
|
+
var require_option = __commonJS((exports2) => {
|
|
625
|
+
var { InvalidArgumentError } = require_error();
|
|
626
|
+
|
|
627
|
+
class Option {
|
|
628
|
+
constructor(flags, description) {
|
|
629
|
+
this.flags = flags;
|
|
630
|
+
this.description = description || "";
|
|
631
|
+
this.required = flags.includes("<");
|
|
632
|
+
this.optional = flags.includes("[");
|
|
633
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
634
|
+
this.mandatory = false;
|
|
635
|
+
const optionFlags = splitOptionFlags(flags);
|
|
636
|
+
this.short = optionFlags.shortFlag;
|
|
637
|
+
this.long = optionFlags.longFlag;
|
|
638
|
+
this.negate = false;
|
|
639
|
+
if (this.long) {
|
|
640
|
+
this.negate = this.long.startsWith("--no-");
|
|
641
|
+
}
|
|
642
|
+
this.defaultValue = undefined;
|
|
643
|
+
this.defaultValueDescription = undefined;
|
|
644
|
+
this.presetArg = undefined;
|
|
645
|
+
this.envVar = undefined;
|
|
646
|
+
this.parseArg = undefined;
|
|
647
|
+
this.hidden = false;
|
|
648
|
+
this.argChoices = undefined;
|
|
649
|
+
this.conflictsWith = [];
|
|
650
|
+
this.implied = undefined;
|
|
651
|
+
this.helpGroupHeading = undefined;
|
|
652
|
+
}
|
|
653
|
+
default(value, description) {
|
|
654
|
+
this.defaultValue = value;
|
|
655
|
+
this.defaultValueDescription = description;
|
|
656
|
+
return this;
|
|
657
|
+
}
|
|
658
|
+
preset(arg) {
|
|
659
|
+
this.presetArg = arg;
|
|
660
|
+
return this;
|
|
661
|
+
}
|
|
662
|
+
conflicts(names) {
|
|
663
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
implies(impliedOptionValues) {
|
|
667
|
+
let newImplied = impliedOptionValues;
|
|
668
|
+
if (typeof impliedOptionValues === "string") {
|
|
669
|
+
newImplied = { [impliedOptionValues]: true };
|
|
670
|
+
}
|
|
671
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
672
|
+
return this;
|
|
673
|
+
}
|
|
674
|
+
env(name) {
|
|
675
|
+
this.envVar = name;
|
|
676
|
+
return this;
|
|
677
|
+
}
|
|
678
|
+
argParser(fn) {
|
|
679
|
+
this.parseArg = fn;
|
|
680
|
+
return this;
|
|
681
|
+
}
|
|
682
|
+
makeOptionMandatory(mandatory = true) {
|
|
683
|
+
this.mandatory = !!mandatory;
|
|
684
|
+
return this;
|
|
685
|
+
}
|
|
686
|
+
hideHelp(hide = true) {
|
|
687
|
+
this.hidden = !!hide;
|
|
688
|
+
return this;
|
|
689
|
+
}
|
|
690
|
+
_collectValue(value, previous) {
|
|
691
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
692
|
+
return [value];
|
|
693
|
+
}
|
|
694
|
+
previous.push(value);
|
|
695
|
+
return previous;
|
|
696
|
+
}
|
|
697
|
+
choices(values) {
|
|
698
|
+
this.argChoices = values.slice();
|
|
699
|
+
this.parseArg = (arg, previous) => {
|
|
700
|
+
if (!this.argChoices.includes(arg)) {
|
|
701
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
702
|
+
}
|
|
703
|
+
if (this.variadic) {
|
|
704
|
+
return this._collectValue(arg, previous);
|
|
705
|
+
}
|
|
706
|
+
return arg;
|
|
707
|
+
};
|
|
708
|
+
return this;
|
|
709
|
+
}
|
|
710
|
+
name() {
|
|
711
|
+
if (this.long) {
|
|
712
|
+
return this.long.replace(/^--/, "");
|
|
713
|
+
}
|
|
714
|
+
return this.short.replace(/^-/, "");
|
|
715
|
+
}
|
|
716
|
+
attributeName() {
|
|
717
|
+
if (this.negate) {
|
|
718
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
719
|
+
}
|
|
720
|
+
return camelcase(this.name());
|
|
721
|
+
}
|
|
722
|
+
helpGroup(heading) {
|
|
723
|
+
this.helpGroupHeading = heading;
|
|
724
|
+
return this;
|
|
725
|
+
}
|
|
726
|
+
is(arg) {
|
|
727
|
+
return this.short === arg || this.long === arg;
|
|
728
|
+
}
|
|
729
|
+
isBoolean() {
|
|
730
|
+
return !this.required && !this.optional && !this.negate;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
class DualOptions {
|
|
735
|
+
constructor(options) {
|
|
736
|
+
this.positiveOptions = new Map;
|
|
737
|
+
this.negativeOptions = new Map;
|
|
738
|
+
this.dualOptions = new Set;
|
|
739
|
+
options.forEach((option) => {
|
|
740
|
+
if (option.negate) {
|
|
741
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
742
|
+
} else {
|
|
743
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
this.negativeOptions.forEach((value, key) => {
|
|
747
|
+
if (this.positiveOptions.has(key)) {
|
|
748
|
+
this.dualOptions.add(key);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
valueFromOption(value, option) {
|
|
753
|
+
const optionKey = option.attributeName();
|
|
754
|
+
if (!this.dualOptions.has(optionKey))
|
|
755
|
+
return true;
|
|
756
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
757
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
758
|
+
return option.negate === (negativeValue === value);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
function camelcase(str) {
|
|
762
|
+
return str.split("-").reduce((str2, word) => {
|
|
763
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
function splitOptionFlags(flags) {
|
|
767
|
+
let shortFlag;
|
|
768
|
+
let longFlag;
|
|
769
|
+
const shortFlagExp = /^-[^-]$/;
|
|
770
|
+
const longFlagExp = /^--[^-]/;
|
|
771
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
772
|
+
if (shortFlagExp.test(flagParts[0]))
|
|
773
|
+
shortFlag = flagParts.shift();
|
|
774
|
+
if (longFlagExp.test(flagParts[0]))
|
|
775
|
+
longFlag = flagParts.shift();
|
|
776
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
777
|
+
shortFlag = flagParts.shift();
|
|
778
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
779
|
+
shortFlag = longFlag;
|
|
780
|
+
longFlag = flagParts.shift();
|
|
781
|
+
}
|
|
782
|
+
if (flagParts[0].startsWith("-")) {
|
|
783
|
+
const unsupportedFlag = flagParts[0];
|
|
784
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
785
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
786
|
+
throw new Error(`${baseError}
|
|
787
|
+
- a short flag is a single dash and a single character
|
|
788
|
+
- either use a single dash and a single character (for a short flag)
|
|
789
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
790
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
791
|
+
throw new Error(`${baseError}
|
|
792
|
+
- too many short flags`);
|
|
793
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
794
|
+
throw new Error(`${baseError}
|
|
795
|
+
- too many long flags`);
|
|
796
|
+
throw new Error(`${baseError}
|
|
797
|
+
- unrecognised flag format`);
|
|
798
|
+
}
|
|
799
|
+
if (shortFlag === undefined && longFlag === undefined)
|
|
800
|
+
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
801
|
+
return { shortFlag, longFlag };
|
|
802
|
+
}
|
|
803
|
+
exports2.Option = Option;
|
|
804
|
+
exports2.DualOptions = DualOptions;
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
808
|
+
var require_suggestSimilar = __commonJS((exports2) => {
|
|
809
|
+
var maxDistance = 3;
|
|
810
|
+
function editDistance(a3, b3) {
|
|
811
|
+
if (Math.abs(a3.length - b3.length) > maxDistance)
|
|
812
|
+
return Math.max(a3.length, b3.length);
|
|
813
|
+
const d2 = [];
|
|
814
|
+
for (let i = 0;i <= a3.length; i++) {
|
|
815
|
+
d2[i] = [i];
|
|
816
|
+
}
|
|
817
|
+
for (let j3 = 0;j3 <= b3.length; j3++) {
|
|
818
|
+
d2[0][j3] = j3;
|
|
819
|
+
}
|
|
820
|
+
for (let j3 = 1;j3 <= b3.length; j3++) {
|
|
821
|
+
for (let i = 1;i <= a3.length; i++) {
|
|
822
|
+
let cost = 1;
|
|
823
|
+
if (a3[i - 1] === b3[j3 - 1]) {
|
|
824
|
+
cost = 0;
|
|
825
|
+
} else {
|
|
826
|
+
cost = 1;
|
|
827
|
+
}
|
|
828
|
+
d2[i][j3] = Math.min(d2[i - 1][j3] + 1, d2[i][j3 - 1] + 1, d2[i - 1][j3 - 1] + cost);
|
|
829
|
+
if (i > 1 && j3 > 1 && a3[i - 1] === b3[j3 - 2] && a3[i - 2] === b3[j3 - 1]) {
|
|
830
|
+
d2[i][j3] = Math.min(d2[i][j3], d2[i - 2][j3 - 2] + 1);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
return d2[a3.length][b3.length];
|
|
835
|
+
}
|
|
836
|
+
function suggestSimilar(word, candidates) {
|
|
837
|
+
if (!candidates || candidates.length === 0)
|
|
838
|
+
return "";
|
|
839
|
+
candidates = Array.from(new Set(candidates));
|
|
840
|
+
const searchingOptions = word.startsWith("--");
|
|
841
|
+
if (searchingOptions) {
|
|
842
|
+
word = word.slice(2);
|
|
843
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
844
|
+
}
|
|
845
|
+
let similar = [];
|
|
846
|
+
let bestDistance = maxDistance;
|
|
847
|
+
const minSimilarity = 0.4;
|
|
848
|
+
candidates.forEach((candidate) => {
|
|
849
|
+
if (candidate.length <= 1)
|
|
850
|
+
return;
|
|
851
|
+
const distance = editDistance(word, candidate);
|
|
852
|
+
const length = Math.max(word.length, candidate.length);
|
|
853
|
+
const similarity = (length - distance) / length;
|
|
854
|
+
if (similarity > minSimilarity) {
|
|
855
|
+
if (distance < bestDistance) {
|
|
856
|
+
bestDistance = distance;
|
|
857
|
+
similar = [candidate];
|
|
858
|
+
} else if (distance === bestDistance) {
|
|
859
|
+
similar.push(candidate);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
similar.sort((a3, b3) => a3.localeCompare(b3));
|
|
864
|
+
if (searchingOptions) {
|
|
865
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
866
|
+
}
|
|
867
|
+
if (similar.length > 1) {
|
|
868
|
+
return `
|
|
869
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
870
|
+
}
|
|
871
|
+
if (similar.length === 1) {
|
|
872
|
+
return `
|
|
873
|
+
(Did you mean ${similar[0]}?)`;
|
|
874
|
+
}
|
|
875
|
+
return "";
|
|
876
|
+
}
|
|
877
|
+
exports2.suggestSimilar = suggestSimilar;
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// node_modules/commander/lib/command.js
|
|
881
|
+
var require_command = __commonJS((exports2) => {
|
|
882
|
+
var EventEmitter = require("node:events").EventEmitter;
|
|
883
|
+
var childProcess = require("node:child_process");
|
|
884
|
+
var path = require("node:path");
|
|
885
|
+
var fs = require("node:fs");
|
|
886
|
+
var process2 = require("node:process");
|
|
887
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
888
|
+
var { CommanderError } = require_error();
|
|
889
|
+
var { Help, stripColor } = require_help();
|
|
890
|
+
var { Option, DualOptions } = require_option();
|
|
891
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
892
|
+
|
|
893
|
+
class Command extends EventEmitter {
|
|
894
|
+
constructor(name) {
|
|
895
|
+
super();
|
|
896
|
+
this.commands = [];
|
|
897
|
+
this.options = [];
|
|
898
|
+
this.parent = null;
|
|
899
|
+
this._allowUnknownOption = false;
|
|
900
|
+
this._allowExcessArguments = false;
|
|
901
|
+
this.registeredArguments = [];
|
|
902
|
+
this._args = this.registeredArguments;
|
|
903
|
+
this.args = [];
|
|
904
|
+
this.rawArgs = [];
|
|
905
|
+
this.processedArgs = [];
|
|
906
|
+
this._scriptPath = null;
|
|
907
|
+
this._name = name || "";
|
|
908
|
+
this._optionValues = {};
|
|
909
|
+
this._optionValueSources = {};
|
|
910
|
+
this._storeOptionsAsProperties = false;
|
|
911
|
+
this._actionHandler = null;
|
|
912
|
+
this._executableHandler = false;
|
|
913
|
+
this._executableFile = null;
|
|
914
|
+
this._executableDir = null;
|
|
915
|
+
this._defaultCommandName = null;
|
|
916
|
+
this._exitCallback = null;
|
|
917
|
+
this._aliases = [];
|
|
918
|
+
this._combineFlagAndOptionalValue = true;
|
|
919
|
+
this._description = "";
|
|
920
|
+
this._summary = "";
|
|
921
|
+
this._argsDescription = undefined;
|
|
922
|
+
this._enablePositionalOptions = false;
|
|
923
|
+
this._passThroughOptions = false;
|
|
924
|
+
this._lifeCycleHooks = {};
|
|
925
|
+
this._showHelpAfterError = false;
|
|
926
|
+
this._showSuggestionAfterError = true;
|
|
927
|
+
this._savedState = null;
|
|
928
|
+
this._outputConfiguration = {
|
|
929
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
930
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
931
|
+
outputError: (str, write) => write(str),
|
|
932
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
933
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
934
|
+
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
935
|
+
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
936
|
+
stripColor: (str) => stripColor(str)
|
|
937
|
+
};
|
|
938
|
+
this._hidden = false;
|
|
939
|
+
this._helpOption = undefined;
|
|
940
|
+
this._addImplicitHelpCommand = undefined;
|
|
941
|
+
this._helpCommand = undefined;
|
|
942
|
+
this._helpConfiguration = {};
|
|
943
|
+
this._helpGroupHeading = undefined;
|
|
944
|
+
this._defaultCommandGroup = undefined;
|
|
945
|
+
this._defaultOptionGroup = undefined;
|
|
946
|
+
}
|
|
947
|
+
copyInheritedSettings(sourceCommand) {
|
|
948
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
949
|
+
this._helpOption = sourceCommand._helpOption;
|
|
950
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
951
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
952
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
953
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
954
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
955
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
956
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
957
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
958
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
959
|
+
return this;
|
|
960
|
+
}
|
|
961
|
+
_getCommandAndAncestors() {
|
|
962
|
+
const result = [];
|
|
963
|
+
for (let command = this;command; command = command.parent) {
|
|
964
|
+
result.push(command);
|
|
965
|
+
}
|
|
966
|
+
return result;
|
|
967
|
+
}
|
|
968
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
969
|
+
let desc = actionOptsOrExecDesc;
|
|
970
|
+
let opts = execOpts;
|
|
971
|
+
if (typeof desc === "object" && desc !== null) {
|
|
972
|
+
opts = desc;
|
|
973
|
+
desc = null;
|
|
974
|
+
}
|
|
975
|
+
opts = opts || {};
|
|
976
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
977
|
+
const cmd = this.createCommand(name);
|
|
978
|
+
if (desc) {
|
|
979
|
+
cmd.description(desc);
|
|
980
|
+
cmd._executableHandler = true;
|
|
981
|
+
}
|
|
982
|
+
if (opts.isDefault)
|
|
983
|
+
this._defaultCommandName = cmd._name;
|
|
984
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
985
|
+
cmd._executableFile = opts.executableFile || null;
|
|
986
|
+
if (args)
|
|
987
|
+
cmd.arguments(args);
|
|
988
|
+
this._registerCommand(cmd);
|
|
989
|
+
cmd.parent = this;
|
|
990
|
+
cmd.copyInheritedSettings(this);
|
|
991
|
+
if (desc)
|
|
992
|
+
return this;
|
|
993
|
+
return cmd;
|
|
994
|
+
}
|
|
995
|
+
createCommand(name) {
|
|
996
|
+
return new Command(name);
|
|
997
|
+
}
|
|
998
|
+
createHelp() {
|
|
999
|
+
return Object.assign(new Help, this.configureHelp());
|
|
1000
|
+
}
|
|
1001
|
+
configureHelp(configuration) {
|
|
1002
|
+
if (configuration === undefined)
|
|
1003
|
+
return this._helpConfiguration;
|
|
1004
|
+
this._helpConfiguration = configuration;
|
|
1005
|
+
return this;
|
|
1006
|
+
}
|
|
1007
|
+
configureOutput(configuration) {
|
|
1008
|
+
if (configuration === undefined)
|
|
1009
|
+
return this._outputConfiguration;
|
|
1010
|
+
this._outputConfiguration = {
|
|
1011
|
+
...this._outputConfiguration,
|
|
1012
|
+
...configuration
|
|
1013
|
+
};
|
|
1014
|
+
return this;
|
|
1015
|
+
}
|
|
1016
|
+
showHelpAfterError(displayHelp = true) {
|
|
1017
|
+
if (typeof displayHelp !== "string")
|
|
1018
|
+
displayHelp = !!displayHelp;
|
|
1019
|
+
this._showHelpAfterError = displayHelp;
|
|
1020
|
+
return this;
|
|
1021
|
+
}
|
|
1022
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1023
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1024
|
+
return this;
|
|
1025
|
+
}
|
|
1026
|
+
addCommand(cmd, opts) {
|
|
1027
|
+
if (!cmd._name) {
|
|
1028
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
1029
|
+
- specify the name in Command constructor or using .name()`);
|
|
1030
|
+
}
|
|
1031
|
+
opts = opts || {};
|
|
1032
|
+
if (opts.isDefault)
|
|
1033
|
+
this._defaultCommandName = cmd._name;
|
|
1034
|
+
if (opts.noHelp || opts.hidden)
|
|
1035
|
+
cmd._hidden = true;
|
|
1036
|
+
this._registerCommand(cmd);
|
|
1037
|
+
cmd.parent = this;
|
|
1038
|
+
cmd._checkForBrokenPassThrough();
|
|
1039
|
+
return this;
|
|
1040
|
+
}
|
|
1041
|
+
createArgument(name, description) {
|
|
1042
|
+
return new Argument(name, description);
|
|
1043
|
+
}
|
|
1044
|
+
argument(name, description, parseArg, defaultValue) {
|
|
1045
|
+
const argument = this.createArgument(name, description);
|
|
1046
|
+
if (typeof parseArg === "function") {
|
|
1047
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
1048
|
+
} else {
|
|
1049
|
+
argument.default(parseArg);
|
|
1050
|
+
}
|
|
1051
|
+
this.addArgument(argument);
|
|
1052
|
+
return this;
|
|
1053
|
+
}
|
|
1054
|
+
arguments(names) {
|
|
1055
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
1056
|
+
this.argument(detail);
|
|
1057
|
+
});
|
|
1058
|
+
return this;
|
|
1059
|
+
}
|
|
1060
|
+
addArgument(argument) {
|
|
1061
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1062
|
+
if (previousArgument?.variadic) {
|
|
1063
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
1064
|
+
}
|
|
1065
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
1066
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
1067
|
+
}
|
|
1068
|
+
this.registeredArguments.push(argument);
|
|
1069
|
+
return this;
|
|
1070
|
+
}
|
|
1071
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
1072
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1073
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1074
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
1075
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
1076
|
+
}
|
|
1077
|
+
return this;
|
|
1078
|
+
}
|
|
1079
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1080
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1081
|
+
const helpDescription = description ?? "display help for command";
|
|
1082
|
+
const helpCommand = this.createCommand(helpName);
|
|
1083
|
+
helpCommand.helpOption(false);
|
|
1084
|
+
if (helpArgs)
|
|
1085
|
+
helpCommand.arguments(helpArgs);
|
|
1086
|
+
if (helpDescription)
|
|
1087
|
+
helpCommand.description(helpDescription);
|
|
1088
|
+
this._addImplicitHelpCommand = true;
|
|
1089
|
+
this._helpCommand = helpCommand;
|
|
1090
|
+
if (enableOrNameAndArgs || description)
|
|
1091
|
+
this._initCommandGroup(helpCommand);
|
|
1092
|
+
return this;
|
|
1093
|
+
}
|
|
1094
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1095
|
+
if (typeof helpCommand !== "object") {
|
|
1096
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1097
|
+
return this;
|
|
1098
|
+
}
|
|
1099
|
+
this._addImplicitHelpCommand = true;
|
|
1100
|
+
this._helpCommand = helpCommand;
|
|
1101
|
+
this._initCommandGroup(helpCommand);
|
|
1102
|
+
return this;
|
|
1103
|
+
}
|
|
1104
|
+
_getHelpCommand() {
|
|
1105
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
1106
|
+
if (hasImplicitHelpCommand) {
|
|
1107
|
+
if (this._helpCommand === undefined) {
|
|
1108
|
+
this.helpCommand(undefined, undefined);
|
|
1109
|
+
}
|
|
1110
|
+
return this._helpCommand;
|
|
1111
|
+
}
|
|
1112
|
+
return null;
|
|
1113
|
+
}
|
|
1114
|
+
hook(event, listener) {
|
|
1115
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1116
|
+
if (!allowedValues.includes(event)) {
|
|
1117
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1118
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1119
|
+
}
|
|
1120
|
+
if (this._lifeCycleHooks[event]) {
|
|
1121
|
+
this._lifeCycleHooks[event].push(listener);
|
|
1122
|
+
} else {
|
|
1123
|
+
this._lifeCycleHooks[event] = [listener];
|
|
1124
|
+
}
|
|
1125
|
+
return this;
|
|
1126
|
+
}
|
|
1127
|
+
exitOverride(fn) {
|
|
1128
|
+
if (fn) {
|
|
1129
|
+
this._exitCallback = fn;
|
|
1130
|
+
} else {
|
|
1131
|
+
this._exitCallback = (err) => {
|
|
1132
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1133
|
+
throw err;
|
|
1134
|
+
} else {}
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
return this;
|
|
1138
|
+
}
|
|
1139
|
+
_exit(exitCode, code, message) {
|
|
1140
|
+
if (this._exitCallback) {
|
|
1141
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
1142
|
+
}
|
|
1143
|
+
process2.exit(exitCode);
|
|
1144
|
+
}
|
|
1145
|
+
action(fn) {
|
|
1146
|
+
const listener = (args) => {
|
|
1147
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1148
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1149
|
+
if (this._storeOptionsAsProperties) {
|
|
1150
|
+
actionArgs[expectedArgsCount] = this;
|
|
1151
|
+
} else {
|
|
1152
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
1153
|
+
}
|
|
1154
|
+
actionArgs.push(this);
|
|
1155
|
+
return fn.apply(this, actionArgs);
|
|
1156
|
+
};
|
|
1157
|
+
this._actionHandler = listener;
|
|
1158
|
+
return this;
|
|
1159
|
+
}
|
|
1160
|
+
createOption(flags, description) {
|
|
1161
|
+
return new Option(flags, description);
|
|
1162
|
+
}
|
|
1163
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1164
|
+
try {
|
|
1165
|
+
return target.parseArg(value, previous);
|
|
1166
|
+
} catch (err) {
|
|
1167
|
+
if (err.code === "commander.invalidArgument") {
|
|
1168
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1169
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1170
|
+
}
|
|
1171
|
+
throw err;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
_registerOption(option) {
|
|
1175
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1176
|
+
if (matchingOption) {
|
|
1177
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1178
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1179
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1180
|
+
}
|
|
1181
|
+
this._initOptionGroup(option);
|
|
1182
|
+
this.options.push(option);
|
|
1183
|
+
}
|
|
1184
|
+
_registerCommand(command) {
|
|
1185
|
+
const knownBy = (cmd) => {
|
|
1186
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1187
|
+
};
|
|
1188
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
1189
|
+
if (alreadyUsed) {
|
|
1190
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1191
|
+
const newCmd = knownBy(command).join("|");
|
|
1192
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
1193
|
+
}
|
|
1194
|
+
this._initCommandGroup(command);
|
|
1195
|
+
this.commands.push(command);
|
|
1196
|
+
}
|
|
1197
|
+
addOption(option) {
|
|
1198
|
+
this._registerOption(option);
|
|
1199
|
+
const oname = option.name();
|
|
1200
|
+
const name = option.attributeName();
|
|
1201
|
+
if (option.negate) {
|
|
1202
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1203
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
1204
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
1205
|
+
}
|
|
1206
|
+
} else if (option.defaultValue !== undefined) {
|
|
1207
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1208
|
+
}
|
|
1209
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1210
|
+
if (val == null && option.presetArg !== undefined) {
|
|
1211
|
+
val = option.presetArg;
|
|
1212
|
+
}
|
|
1213
|
+
const oldValue = this.getOptionValue(name);
|
|
1214
|
+
if (val !== null && option.parseArg) {
|
|
1215
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1216
|
+
} else if (val !== null && option.variadic) {
|
|
1217
|
+
val = option._collectValue(val, oldValue);
|
|
1218
|
+
}
|
|
1219
|
+
if (val == null) {
|
|
1220
|
+
if (option.negate) {
|
|
1221
|
+
val = false;
|
|
1222
|
+
} else if (option.isBoolean() || option.optional) {
|
|
1223
|
+
val = true;
|
|
1224
|
+
} else {
|
|
1225
|
+
val = "";
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1229
|
+
};
|
|
1230
|
+
this.on("option:" + oname, (val) => {
|
|
1231
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1232
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1233
|
+
});
|
|
1234
|
+
if (option.envVar) {
|
|
1235
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
1236
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1237
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
return this;
|
|
1241
|
+
}
|
|
1242
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1243
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
1244
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1245
|
+
}
|
|
1246
|
+
const option = this.createOption(flags, description);
|
|
1247
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1248
|
+
if (typeof fn === "function") {
|
|
1249
|
+
option.default(defaultValue).argParser(fn);
|
|
1250
|
+
} else if (fn instanceof RegExp) {
|
|
1251
|
+
const regex = fn;
|
|
1252
|
+
fn = (val, def) => {
|
|
1253
|
+
const m2 = regex.exec(val);
|
|
1254
|
+
return m2 ? m2[0] : def;
|
|
1255
|
+
};
|
|
1256
|
+
option.default(defaultValue).argParser(fn);
|
|
1257
|
+
} else {
|
|
1258
|
+
option.default(fn);
|
|
1259
|
+
}
|
|
1260
|
+
return this.addOption(option);
|
|
1261
|
+
}
|
|
1262
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1263
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1264
|
+
}
|
|
1265
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1266
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
1267
|
+
}
|
|
1268
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1269
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1270
|
+
return this;
|
|
1271
|
+
}
|
|
1272
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1273
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1274
|
+
return this;
|
|
1275
|
+
}
|
|
1276
|
+
allowExcessArguments(allowExcess = true) {
|
|
1277
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1278
|
+
return this;
|
|
1279
|
+
}
|
|
1280
|
+
enablePositionalOptions(positional = true) {
|
|
1281
|
+
this._enablePositionalOptions = !!positional;
|
|
1282
|
+
return this;
|
|
1283
|
+
}
|
|
1284
|
+
passThroughOptions(passThrough = true) {
|
|
1285
|
+
this._passThroughOptions = !!passThrough;
|
|
1286
|
+
this._checkForBrokenPassThrough();
|
|
1287
|
+
return this;
|
|
1288
|
+
}
|
|
1289
|
+
_checkForBrokenPassThrough() {
|
|
1290
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1291
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1295
|
+
if (this.options.length) {
|
|
1296
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1297
|
+
}
|
|
1298
|
+
if (Object.keys(this._optionValues).length) {
|
|
1299
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1300
|
+
}
|
|
1301
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1302
|
+
return this;
|
|
1303
|
+
}
|
|
1304
|
+
getOptionValue(key) {
|
|
1305
|
+
if (this._storeOptionsAsProperties) {
|
|
1306
|
+
return this[key];
|
|
1307
|
+
}
|
|
1308
|
+
return this._optionValues[key];
|
|
1309
|
+
}
|
|
1310
|
+
setOptionValue(key, value) {
|
|
1311
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1312
|
+
}
|
|
1313
|
+
setOptionValueWithSource(key, value, source) {
|
|
1314
|
+
if (this._storeOptionsAsProperties) {
|
|
1315
|
+
this[key] = value;
|
|
1316
|
+
} else {
|
|
1317
|
+
this._optionValues[key] = value;
|
|
1318
|
+
}
|
|
1319
|
+
this._optionValueSources[key] = source;
|
|
1320
|
+
return this;
|
|
1321
|
+
}
|
|
1322
|
+
getOptionValueSource(key) {
|
|
1323
|
+
return this._optionValueSources[key];
|
|
1324
|
+
}
|
|
1325
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1326
|
+
let source;
|
|
1327
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1328
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1329
|
+
source = cmd.getOptionValueSource(key);
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
return source;
|
|
1333
|
+
}
|
|
1334
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1335
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1336
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1337
|
+
}
|
|
1338
|
+
parseOptions = parseOptions || {};
|
|
1339
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1340
|
+
if (process2.versions?.electron) {
|
|
1341
|
+
parseOptions.from = "electron";
|
|
1342
|
+
}
|
|
1343
|
+
const execArgv = process2.execArgv ?? [];
|
|
1344
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1345
|
+
parseOptions.from = "eval";
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
if (argv === undefined) {
|
|
1349
|
+
argv = process2.argv;
|
|
1350
|
+
}
|
|
1351
|
+
this.rawArgs = argv.slice();
|
|
1352
|
+
let userArgs;
|
|
1353
|
+
switch (parseOptions.from) {
|
|
1354
|
+
case undefined:
|
|
1355
|
+
case "node":
|
|
1356
|
+
this._scriptPath = argv[1];
|
|
1357
|
+
userArgs = argv.slice(2);
|
|
1358
|
+
break;
|
|
1359
|
+
case "electron":
|
|
1360
|
+
if (process2.defaultApp) {
|
|
1361
|
+
this._scriptPath = argv[1];
|
|
1362
|
+
userArgs = argv.slice(2);
|
|
1363
|
+
} else {
|
|
1364
|
+
userArgs = argv.slice(1);
|
|
1365
|
+
}
|
|
1366
|
+
break;
|
|
1367
|
+
case "user":
|
|
1368
|
+
userArgs = argv.slice(0);
|
|
1369
|
+
break;
|
|
1370
|
+
case "eval":
|
|
1371
|
+
userArgs = argv.slice(1);
|
|
1372
|
+
break;
|
|
1373
|
+
default:
|
|
1374
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1375
|
+
}
|
|
1376
|
+
if (!this._name && this._scriptPath)
|
|
1377
|
+
this.nameFromFilename(this._scriptPath);
|
|
1378
|
+
this._name = this._name || "program";
|
|
1379
|
+
return userArgs;
|
|
1380
|
+
}
|
|
1381
|
+
parse(argv, parseOptions) {
|
|
1382
|
+
this._prepareForParse();
|
|
1383
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1384
|
+
this._parseCommand([], userArgs);
|
|
1385
|
+
return this;
|
|
1386
|
+
}
|
|
1387
|
+
async parseAsync(argv, parseOptions) {
|
|
1388
|
+
this._prepareForParse();
|
|
1389
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1390
|
+
await this._parseCommand([], userArgs);
|
|
1391
|
+
return this;
|
|
1392
|
+
}
|
|
1393
|
+
_prepareForParse() {
|
|
1394
|
+
if (this._savedState === null) {
|
|
1395
|
+
this.saveStateBeforeParse();
|
|
1396
|
+
} else {
|
|
1397
|
+
this.restoreStateBeforeParse();
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
saveStateBeforeParse() {
|
|
1401
|
+
this._savedState = {
|
|
1402
|
+
_name: this._name,
|
|
1403
|
+
_optionValues: { ...this._optionValues },
|
|
1404
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
restoreStateBeforeParse() {
|
|
1408
|
+
if (this._storeOptionsAsProperties)
|
|
1409
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
1410
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1411
|
+
this._name = this._savedState._name;
|
|
1412
|
+
this._scriptPath = null;
|
|
1413
|
+
this.rawArgs = [];
|
|
1414
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
1415
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
1416
|
+
this.args = [];
|
|
1417
|
+
this.processedArgs = [];
|
|
1418
|
+
}
|
|
1419
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1420
|
+
if (fs.existsSync(executableFile))
|
|
1421
|
+
return;
|
|
1422
|
+
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";
|
|
1423
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1424
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1425
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1426
|
+
- ${executableDirMessage}`;
|
|
1427
|
+
throw new Error(executableMissing);
|
|
1428
|
+
}
|
|
1429
|
+
_executeSubCommand(subcommand, args) {
|
|
1430
|
+
args = args.slice();
|
|
1431
|
+
let launchWithNode = false;
|
|
1432
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1433
|
+
function findFile(baseDir, baseName) {
|
|
1434
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1435
|
+
if (fs.existsSync(localBin))
|
|
1436
|
+
return localBin;
|
|
1437
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1438
|
+
return;
|
|
1439
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1440
|
+
if (foundExt)
|
|
1441
|
+
return `${localBin}${foundExt}`;
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
this._checkForMissingMandatoryOptions();
|
|
1445
|
+
this._checkForConflictingOptions();
|
|
1446
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1447
|
+
let executableDir = this._executableDir || "";
|
|
1448
|
+
if (this._scriptPath) {
|
|
1449
|
+
let resolvedScriptPath;
|
|
1450
|
+
try {
|
|
1451
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1452
|
+
} catch {
|
|
1453
|
+
resolvedScriptPath = this._scriptPath;
|
|
1454
|
+
}
|
|
1455
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1456
|
+
}
|
|
1457
|
+
if (executableDir) {
|
|
1458
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1459
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1460
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1461
|
+
if (legacyName !== this._name) {
|
|
1462
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
executableFile = localFile || executableFile;
|
|
1466
|
+
}
|
|
1467
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1468
|
+
let proc;
|
|
1469
|
+
if (process2.platform !== "win32") {
|
|
1470
|
+
if (launchWithNode) {
|
|
1471
|
+
args.unshift(executableFile);
|
|
1472
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1473
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1474
|
+
} else {
|
|
1475
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1476
|
+
}
|
|
1477
|
+
} else {
|
|
1478
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1479
|
+
args.unshift(executableFile);
|
|
1480
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1481
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1482
|
+
}
|
|
1483
|
+
if (!proc.killed) {
|
|
1484
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1485
|
+
signals.forEach((signal) => {
|
|
1486
|
+
process2.on(signal, () => {
|
|
1487
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1488
|
+
proc.kill(signal);
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
const exitCallback = this._exitCallback;
|
|
1494
|
+
proc.on("close", (code) => {
|
|
1495
|
+
code = code ?? 1;
|
|
1496
|
+
if (!exitCallback) {
|
|
1497
|
+
process2.exit(code);
|
|
1498
|
+
} else {
|
|
1499
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
proc.on("error", (err) => {
|
|
1503
|
+
if (err.code === "ENOENT") {
|
|
1504
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1505
|
+
} else if (err.code === "EACCES") {
|
|
1506
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1507
|
+
}
|
|
1508
|
+
if (!exitCallback) {
|
|
1509
|
+
process2.exit(1);
|
|
1510
|
+
} else {
|
|
1511
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1512
|
+
wrappedError.nestedError = err;
|
|
1513
|
+
exitCallback(wrappedError);
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
this.runningCommand = proc;
|
|
1517
|
+
}
|
|
1518
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1519
|
+
const subCommand = this._findCommand(commandName);
|
|
1520
|
+
if (!subCommand)
|
|
1521
|
+
this.help({ error: true });
|
|
1522
|
+
subCommand._prepareForParse();
|
|
1523
|
+
let promiseChain;
|
|
1524
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1525
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1526
|
+
if (subCommand._executableHandler) {
|
|
1527
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1528
|
+
} else {
|
|
1529
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
return promiseChain;
|
|
1533
|
+
}
|
|
1534
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1535
|
+
if (!subcommandName) {
|
|
1536
|
+
this.help();
|
|
1537
|
+
}
|
|
1538
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1539
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1540
|
+
subCommand.help();
|
|
1541
|
+
}
|
|
1542
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1543
|
+
}
|
|
1544
|
+
_checkNumberOfArguments() {
|
|
1545
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1546
|
+
if (arg.required && this.args[i] == null) {
|
|
1547
|
+
this.missingArgument(arg.name());
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1554
|
+
this._excessArguments(this.args);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
_processArguments() {
|
|
1558
|
+
const myParseArg = (argument, value, previous) => {
|
|
1559
|
+
let parsedValue = value;
|
|
1560
|
+
if (value !== null && argument.parseArg) {
|
|
1561
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1562
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1563
|
+
}
|
|
1564
|
+
return parsedValue;
|
|
1565
|
+
};
|
|
1566
|
+
this._checkNumberOfArguments();
|
|
1567
|
+
const processedArgs = [];
|
|
1568
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1569
|
+
let value = declaredArg.defaultValue;
|
|
1570
|
+
if (declaredArg.variadic) {
|
|
1571
|
+
if (index < this.args.length) {
|
|
1572
|
+
value = this.args.slice(index);
|
|
1573
|
+
if (declaredArg.parseArg) {
|
|
1574
|
+
value = value.reduce((processed, v3) => {
|
|
1575
|
+
return myParseArg(declaredArg, v3, processed);
|
|
1576
|
+
}, declaredArg.defaultValue);
|
|
1577
|
+
}
|
|
1578
|
+
} else if (value === undefined) {
|
|
1579
|
+
value = [];
|
|
1580
|
+
}
|
|
1581
|
+
} else if (index < this.args.length) {
|
|
1582
|
+
value = this.args[index];
|
|
1583
|
+
if (declaredArg.parseArg) {
|
|
1584
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
processedArgs[index] = value;
|
|
1588
|
+
});
|
|
1589
|
+
this.processedArgs = processedArgs;
|
|
1590
|
+
}
|
|
1591
|
+
_chainOrCall(promise, fn) {
|
|
1592
|
+
if (promise?.then && typeof promise.then === "function") {
|
|
1593
|
+
return promise.then(() => fn());
|
|
1594
|
+
}
|
|
1595
|
+
return fn();
|
|
1596
|
+
}
|
|
1597
|
+
_chainOrCallHooks(promise, event) {
|
|
1598
|
+
let result = promise;
|
|
1599
|
+
const hooks = [];
|
|
1600
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1601
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1602
|
+
hooks.push({ hookedCommand, callback });
|
|
1603
|
+
});
|
|
1604
|
+
});
|
|
1605
|
+
if (event === "postAction") {
|
|
1606
|
+
hooks.reverse();
|
|
1607
|
+
}
|
|
1608
|
+
hooks.forEach((hookDetail) => {
|
|
1609
|
+
result = this._chainOrCall(result, () => {
|
|
1610
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
return result;
|
|
1614
|
+
}
|
|
1615
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1616
|
+
let result = promise;
|
|
1617
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1618
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1619
|
+
result = this._chainOrCall(result, () => {
|
|
1620
|
+
return hook(this, subCommand);
|
|
1621
|
+
});
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
return result;
|
|
1625
|
+
}
|
|
1626
|
+
_parseCommand(operands, unknown) {
|
|
1627
|
+
const parsed = this.parseOptions(unknown);
|
|
1628
|
+
this._parseOptionsEnv();
|
|
1629
|
+
this._parseOptionsImplied();
|
|
1630
|
+
operands = operands.concat(parsed.operands);
|
|
1631
|
+
unknown = parsed.unknown;
|
|
1632
|
+
this.args = operands.concat(unknown);
|
|
1633
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1634
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1635
|
+
}
|
|
1636
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1637
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1638
|
+
}
|
|
1639
|
+
if (this._defaultCommandName) {
|
|
1640
|
+
this._outputHelpIfRequested(unknown);
|
|
1641
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1642
|
+
}
|
|
1643
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1644
|
+
this.help({ error: true });
|
|
1645
|
+
}
|
|
1646
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1647
|
+
this._checkForMissingMandatoryOptions();
|
|
1648
|
+
this._checkForConflictingOptions();
|
|
1649
|
+
const checkForUnknownOptions = () => {
|
|
1650
|
+
if (parsed.unknown.length > 0) {
|
|
1651
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
const commandEvent = `command:${this.name()}`;
|
|
1655
|
+
if (this._actionHandler) {
|
|
1656
|
+
checkForUnknownOptions();
|
|
1657
|
+
this._processArguments();
|
|
1658
|
+
let promiseChain;
|
|
1659
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1660
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1661
|
+
if (this.parent) {
|
|
1662
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1663
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1667
|
+
return promiseChain;
|
|
1668
|
+
}
|
|
1669
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
1670
|
+
checkForUnknownOptions();
|
|
1671
|
+
this._processArguments();
|
|
1672
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1673
|
+
} else if (operands.length) {
|
|
1674
|
+
if (this._findCommand("*")) {
|
|
1675
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1676
|
+
}
|
|
1677
|
+
if (this.listenerCount("command:*")) {
|
|
1678
|
+
this.emit("command:*", operands, unknown);
|
|
1679
|
+
} else if (this.commands.length) {
|
|
1680
|
+
this.unknownCommand();
|
|
1681
|
+
} else {
|
|
1682
|
+
checkForUnknownOptions();
|
|
1683
|
+
this._processArguments();
|
|
1684
|
+
}
|
|
1685
|
+
} else if (this.commands.length) {
|
|
1686
|
+
checkForUnknownOptions();
|
|
1687
|
+
this.help({ error: true });
|
|
1688
|
+
} else {
|
|
1689
|
+
checkForUnknownOptions();
|
|
1690
|
+
this._processArguments();
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
_findCommand(name) {
|
|
1694
|
+
if (!name)
|
|
1695
|
+
return;
|
|
1696
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1697
|
+
}
|
|
1698
|
+
_findOption(arg) {
|
|
1699
|
+
return this.options.find((option) => option.is(arg));
|
|
1700
|
+
}
|
|
1701
|
+
_checkForMissingMandatoryOptions() {
|
|
1702
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1703
|
+
cmd.options.forEach((anOption) => {
|
|
1704
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1705
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
_checkForConflictingLocalOptions() {
|
|
1711
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1712
|
+
const optionKey = option.attributeName();
|
|
1713
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1714
|
+
return false;
|
|
1715
|
+
}
|
|
1716
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1717
|
+
});
|
|
1718
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1719
|
+
optionsWithConflicting.forEach((option) => {
|
|
1720
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1721
|
+
if (conflictingAndDefined) {
|
|
1722
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
_checkForConflictingOptions() {
|
|
1727
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1728
|
+
cmd._checkForConflictingLocalOptions();
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
parseOptions(args) {
|
|
1732
|
+
const operands = [];
|
|
1733
|
+
const unknown = [];
|
|
1734
|
+
let dest = operands;
|
|
1735
|
+
function maybeOption(arg) {
|
|
1736
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1737
|
+
}
|
|
1738
|
+
const negativeNumberArg = (arg) => {
|
|
1739
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
|
|
1740
|
+
return false;
|
|
1741
|
+
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
1742
|
+
};
|
|
1743
|
+
let activeVariadicOption = null;
|
|
1744
|
+
let activeGroup = null;
|
|
1745
|
+
let i = 0;
|
|
1746
|
+
while (i < args.length || activeGroup) {
|
|
1747
|
+
const arg = activeGroup ?? args[i++];
|
|
1748
|
+
activeGroup = null;
|
|
1749
|
+
if (arg === "--") {
|
|
1750
|
+
if (dest === unknown)
|
|
1751
|
+
dest.push(arg);
|
|
1752
|
+
dest.push(...args.slice(i));
|
|
1753
|
+
break;
|
|
1754
|
+
}
|
|
1755
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
1756
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1757
|
+
continue;
|
|
1758
|
+
}
|
|
1759
|
+
activeVariadicOption = null;
|
|
1760
|
+
if (maybeOption(arg)) {
|
|
1761
|
+
const option = this._findOption(arg);
|
|
1762
|
+
if (option) {
|
|
1763
|
+
if (option.required) {
|
|
1764
|
+
const value = args[i++];
|
|
1765
|
+
if (value === undefined)
|
|
1766
|
+
this.optionMissingArgument(option);
|
|
1767
|
+
this.emit(`option:${option.name()}`, value);
|
|
1768
|
+
} else if (option.optional) {
|
|
1769
|
+
let value = null;
|
|
1770
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
1771
|
+
value = args[i++];
|
|
1772
|
+
}
|
|
1773
|
+
this.emit(`option:${option.name()}`, value);
|
|
1774
|
+
} else {
|
|
1775
|
+
this.emit(`option:${option.name()}`);
|
|
1776
|
+
}
|
|
1777
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1778
|
+
continue;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1782
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1783
|
+
if (option) {
|
|
1784
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1785
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1786
|
+
} else {
|
|
1787
|
+
this.emit(`option:${option.name()}`);
|
|
1788
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
1789
|
+
}
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1794
|
+
const index = arg.indexOf("=");
|
|
1795
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1796
|
+
if (option && (option.required || option.optional)) {
|
|
1797
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
1802
|
+
dest = unknown;
|
|
1803
|
+
}
|
|
1804
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1805
|
+
if (this._findCommand(arg)) {
|
|
1806
|
+
operands.push(arg);
|
|
1807
|
+
unknown.push(...args.slice(i));
|
|
1808
|
+
break;
|
|
1809
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1810
|
+
operands.push(arg, ...args.slice(i));
|
|
1811
|
+
break;
|
|
1812
|
+
} else if (this._defaultCommandName) {
|
|
1813
|
+
unknown.push(arg, ...args.slice(i));
|
|
1814
|
+
break;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
if (this._passThroughOptions) {
|
|
1818
|
+
dest.push(arg, ...args.slice(i));
|
|
1819
|
+
break;
|
|
1820
|
+
}
|
|
1821
|
+
dest.push(arg);
|
|
1822
|
+
}
|
|
1823
|
+
return { operands, unknown };
|
|
1824
|
+
}
|
|
1825
|
+
opts() {
|
|
1826
|
+
if (this._storeOptionsAsProperties) {
|
|
1827
|
+
const result = {};
|
|
1828
|
+
const len = this.options.length;
|
|
1829
|
+
for (let i = 0;i < len; i++) {
|
|
1830
|
+
const key = this.options[i].attributeName();
|
|
1831
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1832
|
+
}
|
|
1833
|
+
return result;
|
|
1834
|
+
}
|
|
1835
|
+
return this._optionValues;
|
|
1836
|
+
}
|
|
1837
|
+
optsWithGlobals() {
|
|
1838
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1839
|
+
}
|
|
1840
|
+
error(message, errorOptions) {
|
|
1841
|
+
this._outputConfiguration.outputError(`${message}
|
|
1842
|
+
`, this._outputConfiguration.writeErr);
|
|
1843
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1844
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1845
|
+
`);
|
|
1846
|
+
} else if (this._showHelpAfterError) {
|
|
1847
|
+
this._outputConfiguration.writeErr(`
|
|
1848
|
+
`);
|
|
1849
|
+
this.outputHelp({ error: true });
|
|
1850
|
+
}
|
|
1851
|
+
const config = errorOptions || {};
|
|
1852
|
+
const exitCode = config.exitCode || 1;
|
|
1853
|
+
const code = config.code || "commander.error";
|
|
1854
|
+
this._exit(exitCode, code, message);
|
|
1855
|
+
}
|
|
1856
|
+
_parseOptionsEnv() {
|
|
1857
|
+
this.options.forEach((option) => {
|
|
1858
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1859
|
+
const optionKey = option.attributeName();
|
|
1860
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1861
|
+
if (option.required || option.optional) {
|
|
1862
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1863
|
+
} else {
|
|
1864
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
_parseOptionsImplied() {
|
|
1871
|
+
const dualHelper = new DualOptions(this.options);
|
|
1872
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1873
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1874
|
+
};
|
|
1875
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1876
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1877
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1878
|
+
});
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
missingArgument(name) {
|
|
1882
|
+
const message = `error: missing required argument '${name}'`;
|
|
1883
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1884
|
+
}
|
|
1885
|
+
optionMissingArgument(option) {
|
|
1886
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1887
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1888
|
+
}
|
|
1889
|
+
missingMandatoryOptionValue(option) {
|
|
1890
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1891
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1892
|
+
}
|
|
1893
|
+
_conflictingOption(option, conflictingOption) {
|
|
1894
|
+
const findBestOptionFromValue = (option2) => {
|
|
1895
|
+
const optionKey = option2.attributeName();
|
|
1896
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1897
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1898
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1899
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1900
|
+
return negativeOption;
|
|
1901
|
+
}
|
|
1902
|
+
return positiveOption || option2;
|
|
1903
|
+
};
|
|
1904
|
+
const getErrorMessage = (option2) => {
|
|
1905
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1906
|
+
const optionKey = bestOption.attributeName();
|
|
1907
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1908
|
+
if (source === "env") {
|
|
1909
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1910
|
+
}
|
|
1911
|
+
return `option '${bestOption.flags}'`;
|
|
1912
|
+
};
|
|
1913
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1914
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1915
|
+
}
|
|
1916
|
+
unknownOption(flag) {
|
|
1917
|
+
if (this._allowUnknownOption)
|
|
1918
|
+
return;
|
|
1919
|
+
let suggestion = "";
|
|
1920
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1921
|
+
let candidateFlags = [];
|
|
1922
|
+
let command = this;
|
|
1923
|
+
do {
|
|
1924
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1925
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1926
|
+
command = command.parent;
|
|
1927
|
+
} while (command && !command._enablePositionalOptions);
|
|
1928
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1929
|
+
}
|
|
1930
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1931
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1932
|
+
}
|
|
1933
|
+
_excessArguments(receivedArgs) {
|
|
1934
|
+
if (this._allowExcessArguments)
|
|
1935
|
+
return;
|
|
1936
|
+
const expected = this.registeredArguments.length;
|
|
1937
|
+
const s = expected === 1 ? "" : "s";
|
|
1938
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1939
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1940
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1941
|
+
}
|
|
1942
|
+
unknownCommand() {
|
|
1943
|
+
const unknownName = this.args[0];
|
|
1944
|
+
let suggestion = "";
|
|
1945
|
+
if (this._showSuggestionAfterError) {
|
|
1946
|
+
const candidateNames = [];
|
|
1947
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1948
|
+
candidateNames.push(command.name());
|
|
1949
|
+
if (command.alias())
|
|
1950
|
+
candidateNames.push(command.alias());
|
|
1951
|
+
});
|
|
1952
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1953
|
+
}
|
|
1954
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1955
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1956
|
+
}
|
|
1957
|
+
version(str, flags, description) {
|
|
1958
|
+
if (str === undefined)
|
|
1959
|
+
return this._version;
|
|
1960
|
+
this._version = str;
|
|
1961
|
+
flags = flags || "-V, --version";
|
|
1962
|
+
description = description || "output the version number";
|
|
1963
|
+
const versionOption = this.createOption(flags, description);
|
|
1964
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1965
|
+
this._registerOption(versionOption);
|
|
1966
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1967
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1968
|
+
`);
|
|
1969
|
+
this._exit(0, "commander.version", str);
|
|
1970
|
+
});
|
|
1971
|
+
return this;
|
|
1972
|
+
}
|
|
1973
|
+
description(str, argsDescription) {
|
|
1974
|
+
if (str === undefined && argsDescription === undefined)
|
|
1975
|
+
return this._description;
|
|
1976
|
+
this._description = str;
|
|
1977
|
+
if (argsDescription) {
|
|
1978
|
+
this._argsDescription = argsDescription;
|
|
1979
|
+
}
|
|
1980
|
+
return this;
|
|
1981
|
+
}
|
|
1982
|
+
summary(str) {
|
|
1983
|
+
if (str === undefined)
|
|
1984
|
+
return this._summary;
|
|
1985
|
+
this._summary = str;
|
|
1986
|
+
return this;
|
|
1987
|
+
}
|
|
1988
|
+
alias(alias) {
|
|
1989
|
+
if (alias === undefined)
|
|
1990
|
+
return this._aliases[0];
|
|
1991
|
+
let command = this;
|
|
1992
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1993
|
+
command = this.commands[this.commands.length - 1];
|
|
1994
|
+
}
|
|
1995
|
+
if (alias === command._name)
|
|
1996
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1997
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1998
|
+
if (matchingCommand) {
|
|
1999
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
2000
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
2001
|
+
}
|
|
2002
|
+
command._aliases.push(alias);
|
|
2003
|
+
return this;
|
|
2004
|
+
}
|
|
2005
|
+
aliases(aliases) {
|
|
2006
|
+
if (aliases === undefined)
|
|
2007
|
+
return this._aliases;
|
|
2008
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
2009
|
+
return this;
|
|
2010
|
+
}
|
|
2011
|
+
usage(str) {
|
|
2012
|
+
if (str === undefined) {
|
|
2013
|
+
if (this._usage)
|
|
2014
|
+
return this._usage;
|
|
2015
|
+
const args = this.registeredArguments.map((arg) => {
|
|
2016
|
+
return humanReadableArgName(arg);
|
|
2017
|
+
});
|
|
2018
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
2019
|
+
}
|
|
2020
|
+
this._usage = str;
|
|
2021
|
+
return this;
|
|
2022
|
+
}
|
|
2023
|
+
name(str) {
|
|
2024
|
+
if (str === undefined)
|
|
2025
|
+
return this._name;
|
|
2026
|
+
this._name = str;
|
|
2027
|
+
return this;
|
|
2028
|
+
}
|
|
2029
|
+
helpGroup(heading) {
|
|
2030
|
+
if (heading === undefined)
|
|
2031
|
+
return this._helpGroupHeading ?? "";
|
|
2032
|
+
this._helpGroupHeading = heading;
|
|
2033
|
+
return this;
|
|
2034
|
+
}
|
|
2035
|
+
commandsGroup(heading) {
|
|
2036
|
+
if (heading === undefined)
|
|
2037
|
+
return this._defaultCommandGroup ?? "";
|
|
2038
|
+
this._defaultCommandGroup = heading;
|
|
2039
|
+
return this;
|
|
2040
|
+
}
|
|
2041
|
+
optionsGroup(heading) {
|
|
2042
|
+
if (heading === undefined)
|
|
2043
|
+
return this._defaultOptionGroup ?? "";
|
|
2044
|
+
this._defaultOptionGroup = heading;
|
|
2045
|
+
return this;
|
|
2046
|
+
}
|
|
2047
|
+
_initOptionGroup(option) {
|
|
2048
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
2049
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
2050
|
+
}
|
|
2051
|
+
_initCommandGroup(cmd) {
|
|
2052
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
2053
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
2054
|
+
}
|
|
2055
|
+
nameFromFilename(filename) {
|
|
2056
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
2057
|
+
return this;
|
|
2058
|
+
}
|
|
2059
|
+
executableDir(path2) {
|
|
2060
|
+
if (path2 === undefined)
|
|
2061
|
+
return this._executableDir;
|
|
2062
|
+
this._executableDir = path2;
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2065
|
+
helpInformation(contextOptions) {
|
|
2066
|
+
const helper = this.createHelp();
|
|
2067
|
+
const context = this._getOutputContext(contextOptions);
|
|
2068
|
+
helper.prepareContext({
|
|
2069
|
+
error: context.error,
|
|
2070
|
+
helpWidth: context.helpWidth,
|
|
2071
|
+
outputHasColors: context.hasColors
|
|
2072
|
+
});
|
|
2073
|
+
const text = helper.formatHelp(this, helper);
|
|
2074
|
+
if (context.hasColors)
|
|
2075
|
+
return text;
|
|
2076
|
+
return this._outputConfiguration.stripColor(text);
|
|
2077
|
+
}
|
|
2078
|
+
_getOutputContext(contextOptions) {
|
|
2079
|
+
contextOptions = contextOptions || {};
|
|
2080
|
+
const error = !!contextOptions.error;
|
|
2081
|
+
let baseWrite;
|
|
2082
|
+
let hasColors;
|
|
2083
|
+
let helpWidth;
|
|
2084
|
+
if (error) {
|
|
2085
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
2086
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
2087
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
2088
|
+
} else {
|
|
2089
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
2090
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
2091
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
2092
|
+
}
|
|
2093
|
+
const write = (str) => {
|
|
2094
|
+
if (!hasColors)
|
|
2095
|
+
str = this._outputConfiguration.stripColor(str);
|
|
2096
|
+
return baseWrite(str);
|
|
2097
|
+
};
|
|
2098
|
+
return { error, write, hasColors, helpWidth };
|
|
2099
|
+
}
|
|
2100
|
+
outputHelp(contextOptions) {
|
|
2101
|
+
let deprecatedCallback;
|
|
2102
|
+
if (typeof contextOptions === "function") {
|
|
2103
|
+
deprecatedCallback = contextOptions;
|
|
2104
|
+
contextOptions = undefined;
|
|
2105
|
+
}
|
|
2106
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
2107
|
+
const eventContext = {
|
|
2108
|
+
error: outputContext.error,
|
|
2109
|
+
write: outputContext.write,
|
|
2110
|
+
command: this
|
|
2111
|
+
};
|
|
2112
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
2113
|
+
this.emit("beforeHelp", eventContext);
|
|
2114
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
2115
|
+
if (deprecatedCallback) {
|
|
2116
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
2117
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2118
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
outputContext.write(helpInformation);
|
|
2122
|
+
if (this._getHelpOption()?.long) {
|
|
2123
|
+
this.emit(this._getHelpOption().long);
|
|
2124
|
+
}
|
|
2125
|
+
this.emit("afterHelp", eventContext);
|
|
2126
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
2127
|
+
}
|
|
2128
|
+
helpOption(flags, description) {
|
|
2129
|
+
if (typeof flags === "boolean") {
|
|
2130
|
+
if (flags) {
|
|
2131
|
+
if (this._helpOption === null)
|
|
2132
|
+
this._helpOption = undefined;
|
|
2133
|
+
if (this._defaultOptionGroup) {
|
|
2134
|
+
this._initOptionGroup(this._getHelpOption());
|
|
2135
|
+
}
|
|
2136
|
+
} else {
|
|
2137
|
+
this._helpOption = null;
|
|
2138
|
+
}
|
|
2139
|
+
return this;
|
|
2140
|
+
}
|
|
2141
|
+
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
2142
|
+
if (flags || description)
|
|
2143
|
+
this._initOptionGroup(this._helpOption);
|
|
2144
|
+
return this;
|
|
2145
|
+
}
|
|
2146
|
+
_getHelpOption() {
|
|
2147
|
+
if (this._helpOption === undefined) {
|
|
2148
|
+
this.helpOption(undefined, undefined);
|
|
2149
|
+
}
|
|
2150
|
+
return this._helpOption;
|
|
2151
|
+
}
|
|
2152
|
+
addHelpOption(option) {
|
|
2153
|
+
this._helpOption = option;
|
|
2154
|
+
this._initOptionGroup(option);
|
|
2155
|
+
return this;
|
|
2156
|
+
}
|
|
2157
|
+
help(contextOptions) {
|
|
2158
|
+
this.outputHelp(contextOptions);
|
|
2159
|
+
let exitCode = Number(process2.exitCode ?? 0);
|
|
2160
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
2161
|
+
exitCode = 1;
|
|
2162
|
+
}
|
|
2163
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2164
|
+
}
|
|
2165
|
+
addHelpText(position, text) {
|
|
2166
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
2167
|
+
if (!allowedValues.includes(position)) {
|
|
2168
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
2169
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2170
|
+
}
|
|
2171
|
+
const helpEvent = `${position}Help`;
|
|
2172
|
+
this.on(helpEvent, (context) => {
|
|
2173
|
+
let helpStr;
|
|
2174
|
+
if (typeof text === "function") {
|
|
2175
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
2176
|
+
} else {
|
|
2177
|
+
helpStr = text;
|
|
2178
|
+
}
|
|
2179
|
+
if (helpStr) {
|
|
2180
|
+
context.write(`${helpStr}
|
|
2181
|
+
`);
|
|
2182
|
+
}
|
|
2183
|
+
});
|
|
2184
|
+
return this;
|
|
2185
|
+
}
|
|
2186
|
+
_outputHelpIfRequested(args) {
|
|
2187
|
+
const helpOption = this._getHelpOption();
|
|
2188
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
2189
|
+
if (helpRequested) {
|
|
2190
|
+
this.outputHelp();
|
|
2191
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
function incrementNodeInspectorPort(args) {
|
|
2196
|
+
return args.map((arg) => {
|
|
2197
|
+
if (!arg.startsWith("--inspect")) {
|
|
2198
|
+
return arg;
|
|
2199
|
+
}
|
|
2200
|
+
let debugOption;
|
|
2201
|
+
let debugHost = "127.0.0.1";
|
|
2202
|
+
let debugPort = "9229";
|
|
2203
|
+
let match;
|
|
2204
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
2205
|
+
debugOption = match[1];
|
|
2206
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
2207
|
+
debugOption = match[1];
|
|
2208
|
+
if (/^\d+$/.test(match[3])) {
|
|
2209
|
+
debugPort = match[3];
|
|
2210
|
+
} else {
|
|
2211
|
+
debugHost = match[3];
|
|
2212
|
+
}
|
|
2213
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
2214
|
+
debugOption = match[1];
|
|
2215
|
+
debugHost = match[3];
|
|
2216
|
+
debugPort = match[4];
|
|
2217
|
+
}
|
|
2218
|
+
if (debugOption && debugPort !== "0") {
|
|
2219
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
2220
|
+
}
|
|
2221
|
+
return arg;
|
|
2222
|
+
});
|
|
2223
|
+
}
|
|
2224
|
+
function useColor() {
|
|
2225
|
+
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
2226
|
+
return false;
|
|
2227
|
+
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
|
|
2228
|
+
return true;
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
exports2.Command = Command;
|
|
2232
|
+
exports2.useColor = useColor;
|
|
2233
|
+
});
|
|
2234
|
+
|
|
2235
|
+
// node_modules/commander/index.js
|
|
2236
|
+
var require_commander = __commonJS((exports2) => {
|
|
2237
|
+
var { Argument } = require_argument();
|
|
2238
|
+
var { Command } = require_command();
|
|
2239
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
2240
|
+
var { Help } = require_help();
|
|
2241
|
+
var { Option } = require_option();
|
|
2242
|
+
exports2.program = new Command;
|
|
2243
|
+
exports2.createCommand = (name) => new Command(name);
|
|
2244
|
+
exports2.createOption = (flags, description) => new Option(flags, description);
|
|
2245
|
+
exports2.createArgument = (name, description) => new Argument(name, description);
|
|
2246
|
+
exports2.Command = Command;
|
|
2247
|
+
exports2.Option = Option;
|
|
2248
|
+
exports2.Argument = Argument;
|
|
2249
|
+
exports2.Help = Help;
|
|
2250
|
+
exports2.CommanderError = CommanderError;
|
|
2251
|
+
exports2.InvalidArgumentError = InvalidArgumentError;
|
|
2252
|
+
exports2.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2253
|
+
});
|
|
2254
|
+
|
|
2255
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
2256
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
2257
|
+
var import_node_process = require("node:process");
|
|
2258
|
+
var f = __toESM(require("node:readline"));
|
|
2259
|
+
var import_node_readline = __toESM(require("node:readline"));
|
|
2260
|
+
var import_node_tty = require("node:tty");
|
|
2261
|
+
function q({ onlyFirst: e = false } = {}) {
|
|
2262
|
+
const F = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
2263
|
+
return new RegExp(F, e ? undefined : "g");
|
|
2264
|
+
}
|
|
2265
|
+
var J = q();
|
|
2266
|
+
function S(e) {
|
|
2267
|
+
if (typeof e != "string")
|
|
2268
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``);
|
|
2269
|
+
return e.replace(J, "");
|
|
2270
|
+
}
|
|
2271
|
+
function T(e) {
|
|
2272
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
2273
|
+
}
|
|
2274
|
+
var j = { exports: {} };
|
|
2275
|
+
(function(e) {
|
|
2276
|
+
var u = {};
|
|
2277
|
+
e.exports = u, u.eastAsianWidth = function(t) {
|
|
2278
|
+
var s = t.charCodeAt(0), C = t.length == 2 ? t.charCodeAt(1) : 0, D = s;
|
|
2279
|
+
return 55296 <= s && s <= 56319 && 56320 <= C && C <= 57343 && (s &= 1023, C &= 1023, D = s << 10 | C, D += 65536), D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N";
|
|
2280
|
+
}, u.characterLength = function(t) {
|
|
2281
|
+
var s = this.eastAsianWidth(t);
|
|
2282
|
+
return s == "F" || s == "W" || s == "A" ? 2 : 1;
|
|
2283
|
+
};
|
|
2284
|
+
function F(t) {
|
|
2285
|
+
return t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
|
|
2286
|
+
}
|
|
2287
|
+
u.length = function(t) {
|
|
2288
|
+
for (var s = F(t), C = 0, D = 0;D < s.length; D++)
|
|
2289
|
+
C = C + this.characterLength(s[D]);
|
|
2290
|
+
return C;
|
|
2291
|
+
}, u.slice = function(t, s, C) {
|
|
2292
|
+
textLen = u.length(t), s = s || 0, C = C || 1, s < 0 && (s = textLen + s), C < 0 && (C = textLen + C);
|
|
2293
|
+
for (var D = "", i = 0, n = F(t), E = 0;E < n.length; E++) {
|
|
2294
|
+
var h = n[E], o = u.length(h);
|
|
2295
|
+
if (i >= s - (o == 2 ? 1 : 0))
|
|
2296
|
+
if (i + o <= C)
|
|
2297
|
+
D += h;
|
|
2298
|
+
else
|
|
2299
|
+
break;
|
|
2300
|
+
i += o;
|
|
2301
|
+
}
|
|
2302
|
+
return D;
|
|
2303
|
+
};
|
|
2304
|
+
})(j);
|
|
2305
|
+
var Q = j.exports;
|
|
2306
|
+
var X = T(Q);
|
|
2307
|
+
var DD = function() {
|
|
2308
|
+
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
|
|
2309
|
+
};
|
|
2310
|
+
var uD = T(DD);
|
|
2311
|
+
function A(e, u = {}) {
|
|
2312
|
+
if (typeof e != "string" || e.length === 0 || (u = { ambiguousIsNarrow: true, ...u }, e = S(e), e.length === 0))
|
|
2313
|
+
return 0;
|
|
2314
|
+
e = e.replace(uD(), " ");
|
|
2315
|
+
const F = u.ambiguousIsNarrow ? 1 : 2;
|
|
2316
|
+
let t = 0;
|
|
2317
|
+
for (const s of e) {
|
|
2318
|
+
const C = s.codePointAt(0);
|
|
2319
|
+
if (C <= 31 || C >= 127 && C <= 159 || C >= 768 && C <= 879)
|
|
2320
|
+
continue;
|
|
2321
|
+
switch (X.eastAsianWidth(s)) {
|
|
2322
|
+
case "F":
|
|
2323
|
+
case "W":
|
|
2324
|
+
t += 2;
|
|
2325
|
+
break;
|
|
2326
|
+
case "A":
|
|
2327
|
+
t += F;
|
|
2328
|
+
break;
|
|
2329
|
+
default:
|
|
2330
|
+
t += 1;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
return t;
|
|
2334
|
+
}
|
|
2335
|
+
var d = 10;
|
|
2336
|
+
var M = (e = 0) => (u) => `\x1B[${u + e}m`;
|
|
2337
|
+
var P = (e = 0) => (u) => `\x1B[${38 + e};5;${u}m`;
|
|
2338
|
+
var W = (e = 0) => (u, F, t) => `\x1B[${38 + e};2;${u};${F};${t}m`;
|
|
2339
|
+
var r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } };
|
|
2340
|
+
Object.keys(r.modifier);
|
|
2341
|
+
var FD = Object.keys(r.color);
|
|
2342
|
+
var eD = Object.keys(r.bgColor);
|
|
2343
|
+
[...FD, ...eD];
|
|
2344
|
+
function tD() {
|
|
2345
|
+
const e = new Map;
|
|
2346
|
+
for (const [u, F] of Object.entries(r)) {
|
|
2347
|
+
for (const [t, s] of Object.entries(F))
|
|
2348
|
+
r[t] = { open: `\x1B[${s[0]}m`, close: `\x1B[${s[1]}m` }, F[t] = r[t], e.set(s[0], s[1]);
|
|
2349
|
+
Object.defineProperty(r, u, { value: F, enumerable: false });
|
|
2350
|
+
}
|
|
2351
|
+
return Object.defineProperty(r, "codes", { value: e, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = M(), r.color.ansi256 = P(), r.color.ansi16m = W(), r.bgColor.ansi = M(d), r.bgColor.ansi256 = P(d), r.bgColor.ansi16m = W(d), Object.defineProperties(r, { rgbToAnsi256: { value: (u, F, t) => u === F && F === t ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(F / 255 * 5) + Math.round(t / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => {
|
|
2352
|
+
const F = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));
|
|
2353
|
+
if (!F)
|
|
2354
|
+
return [0, 0, 0];
|
|
2355
|
+
let [t] = F;
|
|
2356
|
+
t.length === 3 && (t = [...t].map((C) => C + C).join(""));
|
|
2357
|
+
const s = Number.parseInt(t, 16);
|
|
2358
|
+
return [s >> 16 & 255, s >> 8 & 255, s & 255];
|
|
2359
|
+
}, enumerable: false }, hexToAnsi256: { value: (u) => r.rgbToAnsi256(...r.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => {
|
|
2360
|
+
if (u < 8)
|
|
2361
|
+
return 30 + u;
|
|
2362
|
+
if (u < 16)
|
|
2363
|
+
return 90 + (u - 8);
|
|
2364
|
+
let F, t, s;
|
|
2365
|
+
if (u >= 232)
|
|
2366
|
+
F = ((u - 232) * 10 + 8) / 255, t = F, s = F;
|
|
2367
|
+
else {
|
|
2368
|
+
u -= 16;
|
|
2369
|
+
const i = u % 36;
|
|
2370
|
+
F = Math.floor(u / 36) / 5, t = Math.floor(i / 6) / 5, s = i % 6 / 5;
|
|
2371
|
+
}
|
|
2372
|
+
const C = Math.max(F, t, s) * 2;
|
|
2373
|
+
if (C === 0)
|
|
2374
|
+
return 30;
|
|
2375
|
+
let D = 30 + (Math.round(s) << 2 | Math.round(t) << 1 | Math.round(F));
|
|
2376
|
+
return C === 2 && (D += 60), D;
|
|
2377
|
+
}, enumerable: false }, rgbToAnsi: { value: (u, F, t) => r.ansi256ToAnsi(r.rgbToAnsi256(u, F, t)), enumerable: false }, hexToAnsi: { value: (u) => r.ansi256ToAnsi(r.hexToAnsi256(u)), enumerable: false } }), r;
|
|
2378
|
+
}
|
|
2379
|
+
var sD = tD();
|
|
2380
|
+
var g = new Set(["\x1B", ""]);
|
|
2381
|
+
var CD = 39;
|
|
2382
|
+
var b = "\x07";
|
|
2383
|
+
var O = "[";
|
|
2384
|
+
var iD = "]";
|
|
2385
|
+
var I = "m";
|
|
2386
|
+
var w = `${iD}8;;`;
|
|
2387
|
+
var N = (e) => `${g.values().next().value}${O}${e}${I}`;
|
|
2388
|
+
var L = (e) => `${g.values().next().value}${w}${e}${b}`;
|
|
2389
|
+
var rD = (e) => e.split(" ").map((u) => A(u));
|
|
2390
|
+
var y = (e, u, F) => {
|
|
2391
|
+
const t = [...u];
|
|
2392
|
+
let s = false, C = false, D = A(S(e[e.length - 1]));
|
|
2393
|
+
for (const [i, n] of t.entries()) {
|
|
2394
|
+
const E = A(n);
|
|
2395
|
+
if (D + E <= F ? e[e.length - 1] += n : (e.push(n), D = 0), g.has(n) && (s = true, C = t.slice(i + 1).join("").startsWith(w)), s) {
|
|
2396
|
+
C ? n === b && (s = false, C = false) : n === I && (s = false);
|
|
2397
|
+
continue;
|
|
2398
|
+
}
|
|
2399
|
+
D += E, D === F && i < t.length - 1 && (e.push(""), D = 0);
|
|
2400
|
+
}
|
|
2401
|
+
!D && e[e.length - 1].length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
|
|
2402
|
+
};
|
|
2403
|
+
var ED = (e) => {
|
|
2404
|
+
const u = e.split(" ");
|
|
2405
|
+
let F = u.length;
|
|
2406
|
+
for (;F > 0 && !(A(u[F - 1]) > 0); )
|
|
2407
|
+
F--;
|
|
2408
|
+
return F === u.length ? e : u.slice(0, F).join(" ") + u.slice(F).join("");
|
|
2409
|
+
};
|
|
2410
|
+
var oD = (e, u, F = {}) => {
|
|
2411
|
+
if (F.trim !== false && e.trim() === "")
|
|
2412
|
+
return "";
|
|
2413
|
+
let t = "", s, C;
|
|
2414
|
+
const D = rD(e);
|
|
2415
|
+
let i = [""];
|
|
2416
|
+
for (const [E, h] of e.split(" ").entries()) {
|
|
2417
|
+
F.trim !== false && (i[i.length - 1] = i[i.length - 1].trimStart());
|
|
2418
|
+
let o = A(i[i.length - 1]);
|
|
2419
|
+
if (E !== 0 && (o >= u && (F.wordWrap === false || F.trim === false) && (i.push(""), o = 0), (o > 0 || F.trim === false) && (i[i.length - 1] += " ", o++)), F.hard && D[E] > u) {
|
|
2420
|
+
const B = u - o, p = 1 + Math.floor((D[E] - B - 1) / u);
|
|
2421
|
+
Math.floor((D[E] - 1) / u) < p && i.push(""), y(i, h, u);
|
|
2422
|
+
continue;
|
|
2423
|
+
}
|
|
2424
|
+
if (o + D[E] > u && o > 0 && D[E] > 0) {
|
|
2425
|
+
if (F.wordWrap === false && o < u) {
|
|
2426
|
+
y(i, h, u);
|
|
2427
|
+
continue;
|
|
2428
|
+
}
|
|
2429
|
+
i.push("");
|
|
2430
|
+
}
|
|
2431
|
+
if (o + D[E] > u && F.wordWrap === false) {
|
|
2432
|
+
y(i, h, u);
|
|
2433
|
+
continue;
|
|
2434
|
+
}
|
|
2435
|
+
i[i.length - 1] += h;
|
|
2436
|
+
}
|
|
2437
|
+
F.trim !== false && (i = i.map((E) => ED(E)));
|
|
2438
|
+
const n = [...i.join(`
|
|
2439
|
+
`)];
|
|
2440
|
+
for (const [E, h] of n.entries()) {
|
|
2441
|
+
if (t += h, g.has(h)) {
|
|
2442
|
+
const { groups: B } = new RegExp(`(?:\\${O}(?<code>\\d+)m|\\${w}(?<uri>.*)${b})`).exec(n.slice(E).join("")) || { groups: {} };
|
|
2443
|
+
if (B.code !== undefined) {
|
|
2444
|
+
const p = Number.parseFloat(B.code);
|
|
2445
|
+
s = p === CD ? undefined : p;
|
|
2446
|
+
} else
|
|
2447
|
+
B.uri !== undefined && (C = B.uri.length === 0 ? undefined : B.uri);
|
|
2448
|
+
}
|
|
2449
|
+
const o = sD.codes.get(Number(s));
|
|
2450
|
+
n[E + 1] === `
|
|
2451
|
+
` ? (C && (t += L("")), s && o && (t += N(o))) : h === `
|
|
2452
|
+
` && (s && o && (t += N(s)), C && (t += L(C)));
|
|
2453
|
+
}
|
|
2454
|
+
return t;
|
|
2455
|
+
};
|
|
2456
|
+
function R(e, u, F) {
|
|
2457
|
+
return String(e).normalize().replace(/\r\n/g, `
|
|
2458
|
+
`).split(`
|
|
2459
|
+
`).map((t) => oD(t, u, F)).join(`
|
|
2460
|
+
`);
|
|
2461
|
+
}
|
|
2462
|
+
var nD = Object.defineProperty;
|
|
2463
|
+
var aD = (e, u, F) => (u in e) ? nD(e, u, { enumerable: true, configurable: true, writable: true, value: F }) : e[u] = F;
|
|
2464
|
+
var a = (e, u, F) => (aD(e, typeof u != "symbol" ? u + "" : u, F), F);
|
|
2465
|
+
function hD(e, u) {
|
|
2466
|
+
if (e === u)
|
|
2467
|
+
return;
|
|
2468
|
+
const F = e.split(`
|
|
2469
|
+
`), t = u.split(`
|
|
2470
|
+
`), s = [];
|
|
2471
|
+
for (let C = 0;C < Math.max(F.length, t.length); C++)
|
|
2472
|
+
F[C] !== t[C] && s.push(C);
|
|
2473
|
+
return s;
|
|
2474
|
+
}
|
|
2475
|
+
var V = Symbol("clack:cancel");
|
|
2476
|
+
function lD(e) {
|
|
2477
|
+
return e === V;
|
|
2478
|
+
}
|
|
2479
|
+
function v(e, u) {
|
|
2480
|
+
e.isTTY && e.setRawMode(u);
|
|
2481
|
+
}
|
|
2482
|
+
var z = new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"]]);
|
|
2483
|
+
var xD = new Set(["up", "down", "left", "right", "space", "enter"]);
|
|
2484
|
+
|
|
2485
|
+
class x {
|
|
2486
|
+
constructor({ render: u, input: F = import_node_process.stdin, output: t = import_node_process.stdout, ...s }, C = true) {
|
|
2487
|
+
a(this, "input"), a(this, "output"), a(this, "rl"), a(this, "opts"), a(this, "_track", false), a(this, "_render"), a(this, "_cursor", 0), a(this, "state", "initial"), a(this, "value"), a(this, "error", ""), a(this, "subscribers", new Map), a(this, "_prevFrame", ""), this.opts = s, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = u.bind(this), this._track = C, this.input = F, this.output = t;
|
|
2488
|
+
}
|
|
2489
|
+
prompt() {
|
|
2490
|
+
const u = new import_node_tty.WriteStream(0);
|
|
2491
|
+
return u._write = (F, t, s) => {
|
|
2492
|
+
this._track && (this.value = this.rl.line.replace(/\t/g, ""), this._cursor = this.rl.cursor, this.emit("value", this.value)), s();
|
|
2493
|
+
}, this.input.pipe(u), this.rl = import_node_readline.default.createInterface({ input: this.input, output: u, tabSize: 2, prompt: "", escapeCodeTimeout: 50 }), import_node_readline.default.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== undefined && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), v(this.input, true), this.output.on("resize", this.render), this.render(), new Promise((F, t) => {
|
|
2494
|
+
this.once("submit", () => {
|
|
2495
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), v(this.input, false), F(this.value);
|
|
2496
|
+
}), this.once("cancel", () => {
|
|
2497
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), v(this.input, false), F(V);
|
|
2498
|
+
});
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
on(u, F) {
|
|
2502
|
+
const t = this.subscribers.get(u) ?? [];
|
|
2503
|
+
t.push({ cb: F }), this.subscribers.set(u, t);
|
|
2504
|
+
}
|
|
2505
|
+
once(u, F) {
|
|
2506
|
+
const t = this.subscribers.get(u) ?? [];
|
|
2507
|
+
t.push({ cb: F, once: true }), this.subscribers.set(u, t);
|
|
2508
|
+
}
|
|
2509
|
+
emit(u, ...F) {
|
|
2510
|
+
const t = this.subscribers.get(u) ?? [], s = [];
|
|
2511
|
+
for (const C of t)
|
|
2512
|
+
C.cb(...F), C.once && s.push(() => t.splice(t.indexOf(C), 1));
|
|
2513
|
+
for (const C of s)
|
|
2514
|
+
C();
|
|
2515
|
+
}
|
|
2516
|
+
unsubscribe() {
|
|
2517
|
+
this.subscribers.clear();
|
|
2518
|
+
}
|
|
2519
|
+
onKeypress(u, F) {
|
|
2520
|
+
if (this.state === "error" && (this.state = "active"), F?.name && !this._track && z.has(F.name) && this.emit("cursor", z.get(F.name)), F?.name && xD.has(F.name) && this.emit("cursor", F.name), u && (u.toLowerCase() === "y" || u.toLowerCase() === "n") && this.emit("confirm", u.toLowerCase() === "y"), u === "\t" && this.opts.placeholder && (this.value || (this.rl.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u && this.emit("key", u.toLowerCase()), F?.name === "return") {
|
|
2521
|
+
if (this.opts.validate) {
|
|
2522
|
+
const t = this.opts.validate(this.value);
|
|
2523
|
+
t && (this.error = t, this.state = "error", this.rl.write(this.value));
|
|
2524
|
+
}
|
|
2525
|
+
this.state !== "error" && (this.state = "submit");
|
|
2526
|
+
}
|
|
2527
|
+
u === "\x03" && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
2528
|
+
}
|
|
2529
|
+
close() {
|
|
2530
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
2531
|
+
`), v(this.input, false), this.rl.close(), this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
2532
|
+
}
|
|
2533
|
+
restoreCursor() {
|
|
2534
|
+
const u = R(this._prevFrame, process.stdout.columns, { hard: true }).split(`
|
|
2535
|
+
`).length - 1;
|
|
2536
|
+
this.output.write(import_sisteransi.cursor.move(-999, u * -1));
|
|
2537
|
+
}
|
|
2538
|
+
render() {
|
|
2539
|
+
const u = R(this._render(this) ?? "", process.stdout.columns, { hard: true });
|
|
2540
|
+
if (u !== this._prevFrame) {
|
|
2541
|
+
if (this.state === "initial")
|
|
2542
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
2543
|
+
else {
|
|
2544
|
+
const F = hD(this._prevFrame, u);
|
|
2545
|
+
if (this.restoreCursor(), F && F?.length === 1) {
|
|
2546
|
+
const t = F[0];
|
|
2547
|
+
this.output.write(import_sisteransi.cursor.move(0, t)), this.output.write(import_sisteransi.erase.lines(1));
|
|
2548
|
+
const s = u.split(`
|
|
2549
|
+
`);
|
|
2550
|
+
this.output.write(s[t]), this._prevFrame = u, this.output.write(import_sisteransi.cursor.move(0, s.length - t - 1));
|
|
2551
|
+
return;
|
|
2552
|
+
} else if (F && F?.length > 1) {
|
|
2553
|
+
const t = F[0];
|
|
2554
|
+
this.output.write(import_sisteransi.cursor.move(0, t)), this.output.write(import_sisteransi.erase.down());
|
|
2555
|
+
const s = u.split(`
|
|
2556
|
+
`).slice(t);
|
|
2557
|
+
this.output.write(s.join(`
|
|
2558
|
+
`)), this._prevFrame = u;
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
this.output.write(import_sisteransi.erase.down());
|
|
2562
|
+
}
|
|
2563
|
+
this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u;
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
class BD extends x {
|
|
2569
|
+
get cursor() {
|
|
2570
|
+
return this.value ? 0 : 1;
|
|
2571
|
+
}
|
|
2572
|
+
get _value() {
|
|
2573
|
+
return this.cursor === 0;
|
|
2574
|
+
}
|
|
2575
|
+
constructor(u) {
|
|
2576
|
+
super(u, false), this.value = !!u.initialValue, this.on("value", () => {
|
|
2577
|
+
this.value = this._value;
|
|
2578
|
+
}), this.on("confirm", (F) => {
|
|
2579
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = F, this.state = "submit", this.close();
|
|
2580
|
+
}), this.on("cursor", () => {
|
|
2581
|
+
this.value = !this.value;
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
var WD = globalThis.process.platform.startsWith("win");
|
|
2586
|
+
function OD({ input: e = import_node_process.stdin, output: u = import_node_process.stdout, overwrite: F = true, hideCursor: t = true } = {}) {
|
|
2587
|
+
const s = f.createInterface({ input: e, output: u, prompt: "", tabSize: 1 });
|
|
2588
|
+
f.emitKeypressEvents(e, s), e.isTTY && e.setRawMode(true);
|
|
2589
|
+
const C = (D, { name: i }) => {
|
|
2590
|
+
if (String(D) === "\x03") {
|
|
2591
|
+
t && u.write(import_sisteransi.cursor.show), process.exit(0);
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
if (!F)
|
|
2595
|
+
return;
|
|
2596
|
+
let n = i === "return" ? 0 : -1, E = i === "return" ? -1 : 0;
|
|
2597
|
+
f.moveCursor(u, n, E, () => {
|
|
2598
|
+
f.clearLine(u, 1, () => {
|
|
2599
|
+
e.once("keypress", C);
|
|
2600
|
+
});
|
|
2601
|
+
});
|
|
2602
|
+
};
|
|
2603
|
+
return t && u.write(import_sisteransi.cursor.hide), e.once("keypress", C), () => {
|
|
2604
|
+
e.off("keypress", C), t && u.write(import_sisteransi.cursor.show), e.isTTY && !WD && e.setRawMode(false), s.terminal = false, s.close();
|
|
2605
|
+
};
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
// node_modules/@clack/prompts/dist/index.mjs
|
|
2609
|
+
var import_node_process2 = __toESM(require("node:process"));
|
|
2610
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
2611
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
2612
|
+
function K() {
|
|
2613
|
+
return import_node_process2.default.platform !== "win32" ? import_node_process2.default.env.TERM !== "linux" : !!import_node_process2.default.env.CI || !!import_node_process2.default.env.WT_SESSION || !!import_node_process2.default.env.TERMINUS_SUBLIME || import_node_process2.default.env.ConEmuTask === "{cmd::Cmder}" || import_node_process2.default.env.TERM_PROGRAM === "Terminus-Sublime" || import_node_process2.default.env.TERM_PROGRAM === "vscode" || import_node_process2.default.env.TERM === "xterm-256color" || import_node_process2.default.env.TERM === "alacritty" || import_node_process2.default.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
2614
|
+
}
|
|
2615
|
+
var C = K();
|
|
2616
|
+
var u = (s, n) => C ? s : n;
|
|
2617
|
+
var Y = u("◆", "*");
|
|
2618
|
+
var P2 = u("■", "x");
|
|
2619
|
+
var V2 = u("▲", "x");
|
|
2620
|
+
var M2 = u("◇", "o");
|
|
2621
|
+
var Q2 = u("┌", "T");
|
|
2622
|
+
var a2 = u("│", "|");
|
|
2623
|
+
var $2 = u("└", "—");
|
|
2624
|
+
var I2 = u("●", ">");
|
|
2625
|
+
var T2 = u("○", " ");
|
|
2626
|
+
var j2 = u("◻", "[•]");
|
|
2627
|
+
var b2 = u("◼", "[+]");
|
|
2628
|
+
var B = u("◻", "[ ]");
|
|
2629
|
+
var X2 = u("▪", "•");
|
|
2630
|
+
var G = u("─", "-");
|
|
2631
|
+
var H = u("╮", "+");
|
|
2632
|
+
var ee = u("├", "+");
|
|
2633
|
+
var te = u("╯", "+");
|
|
2634
|
+
var se = u("●", "•");
|
|
2635
|
+
var re = u("◆", "*");
|
|
2636
|
+
var ie = u("▲", "!");
|
|
2637
|
+
var ne = u("■", "x");
|
|
2638
|
+
var y2 = (s) => {
|
|
2639
|
+
switch (s) {
|
|
2640
|
+
case "initial":
|
|
2641
|
+
case "active":
|
|
2642
|
+
return import_picocolors.default.cyan(Y);
|
|
2643
|
+
case "cancel":
|
|
2644
|
+
return import_picocolors.default.red(P2);
|
|
2645
|
+
case "error":
|
|
2646
|
+
return import_picocolors.default.yellow(V2);
|
|
2647
|
+
case "submit":
|
|
2648
|
+
return import_picocolors.default.green(M2);
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
var ce = (s) => {
|
|
2652
|
+
const n = s.active ?? "Yes", t = s.inactive ?? "No";
|
|
2653
|
+
return new BD({ active: n, inactive: t, initialValue: s.initialValue ?? true, render() {
|
|
2654
|
+
const i = `${import_picocolors.default.gray(a2)}
|
|
2655
|
+
${y2(this.state)} ${s.message}
|
|
2656
|
+
`, r2 = this.value ? n : t;
|
|
2657
|
+
switch (this.state) {
|
|
2658
|
+
case "submit":
|
|
2659
|
+
return `${i}${import_picocolors.default.gray(a2)} ${import_picocolors.default.dim(r2)}`;
|
|
2660
|
+
case "cancel":
|
|
2661
|
+
return `${i}${import_picocolors.default.gray(a2)} ${import_picocolors.default.strikethrough(import_picocolors.default.dim(r2))}
|
|
2662
|
+
${import_picocolors.default.gray(a2)}`;
|
|
2663
|
+
default:
|
|
2664
|
+
return `${i}${import_picocolors.default.cyan(a2)} ${this.value ? `${import_picocolors.default.green(I2)} ${n}` : `${import_picocolors.default.dim(T2)} ${import_picocolors.default.dim(n)}`} ${import_picocolors.default.dim("/")} ${this.value ? `${import_picocolors.default.dim(T2)} ${import_picocolors.default.dim(t)}` : `${import_picocolors.default.green(I2)} ${t}`}
|
|
2665
|
+
${import_picocolors.default.cyan($2)}
|
|
2666
|
+
`;
|
|
2667
|
+
}
|
|
2668
|
+
} }).prompt();
|
|
2669
|
+
};
|
|
2670
|
+
var R2 = (s) => s.replace(ye(), "");
|
|
2671
|
+
var me = (s = "", n = "") => {
|
|
2672
|
+
const t = `
|
|
2673
|
+
${s}
|
|
2674
|
+
`.split(`
|
|
2675
|
+
`), i = R2(n).length, r2 = Math.max(t.reduce((c, l2) => (l2 = R2(l2), l2.length > c ? l2.length : c), 0), i) + 2, o = t.map((c) => `${import_picocolors.default.gray(a2)} ${import_picocolors.default.dim(c)}${" ".repeat(r2 - R2(c).length)}${import_picocolors.default.gray(a2)}`).join(`
|
|
2676
|
+
`);
|
|
2677
|
+
process.stdout.write(`${import_picocolors.default.gray(a2)}
|
|
2678
|
+
${import_picocolors.default.green(M2)} ${import_picocolors.default.reset(n)} ${import_picocolors.default.gray(G.repeat(Math.max(r2 - i - 1, 1)) + H)}
|
|
2679
|
+
${o}
|
|
2680
|
+
${import_picocolors.default.gray(ee + G.repeat(r2 + 2) + te)}
|
|
2681
|
+
`);
|
|
2682
|
+
};
|
|
2683
|
+
var pe = (s = "") => {
|
|
2684
|
+
process.stdout.write(`${import_picocolors.default.gray(Q2)} ${s}
|
|
2685
|
+
`);
|
|
2686
|
+
};
|
|
2687
|
+
var ge = (s = "") => {
|
|
2688
|
+
process.stdout.write(`${import_picocolors.default.gray(a2)}
|
|
2689
|
+
${import_picocolors.default.gray($2)} ${s}
|
|
2690
|
+
|
|
2691
|
+
`);
|
|
2692
|
+
};
|
|
2693
|
+
var v2 = { message: (s = "", { symbol: n = import_picocolors.default.gray(a2) } = {}) => {
|
|
2694
|
+
const t = [`${import_picocolors.default.gray(a2)}`];
|
|
2695
|
+
if (s) {
|
|
2696
|
+
const [i, ...r2] = s.split(`
|
|
2697
|
+
`);
|
|
2698
|
+
t.push(`${n} ${i}`, ...r2.map((o) => `${import_picocolors.default.gray(a2)} ${o}`));
|
|
2699
|
+
}
|
|
2700
|
+
process.stdout.write(`${t.join(`
|
|
2701
|
+
`)}
|
|
2702
|
+
`);
|
|
2703
|
+
}, info: (s) => {
|
|
2704
|
+
v2.message(s, { symbol: import_picocolors.default.blue(se) });
|
|
2705
|
+
}, success: (s) => {
|
|
2706
|
+
v2.message(s, { symbol: import_picocolors.default.green(re) });
|
|
2707
|
+
}, step: (s) => {
|
|
2708
|
+
v2.message(s, { symbol: import_picocolors.default.green(M2) });
|
|
2709
|
+
}, warn: (s) => {
|
|
2710
|
+
v2.message(s, { symbol: import_picocolors.default.yellow(ie) });
|
|
2711
|
+
}, warning: (s) => {
|
|
2712
|
+
v2.warn(s);
|
|
2713
|
+
}, error: (s) => {
|
|
2714
|
+
v2.message(s, { symbol: import_picocolors.default.red(ne) });
|
|
2715
|
+
} };
|
|
2716
|
+
var _2 = () => {
|
|
2717
|
+
const s = C ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"], n = C ? 80 : 120;
|
|
2718
|
+
let t, i, r2 = false, o = "";
|
|
2719
|
+
const c = (g2) => {
|
|
2720
|
+
const m2 = g2 > 1 ? "Something went wrong" : "Canceled";
|
|
2721
|
+
r2 && x2(m2, g2);
|
|
2722
|
+
}, l2 = () => c(2), d2 = () => c(1), p = () => {
|
|
2723
|
+
process.on("uncaughtExceptionMonitor", l2), process.on("unhandledRejection", l2), process.on("SIGINT", d2), process.on("SIGTERM", d2), process.on("exit", c);
|
|
2724
|
+
}, S2 = () => {
|
|
2725
|
+
process.removeListener("uncaughtExceptionMonitor", l2), process.removeListener("unhandledRejection", l2), process.removeListener("SIGINT", d2), process.removeListener("SIGTERM", d2), process.removeListener("exit", c);
|
|
2726
|
+
}, f2 = (g2 = "") => {
|
|
2727
|
+
r2 = true, t = OD(), o = g2.replace(/\.+$/, ""), process.stdout.write(`${import_picocolors.default.gray(a2)}
|
|
2728
|
+
`);
|
|
2729
|
+
let m2 = 0, w2 = 0;
|
|
2730
|
+
p(), i = setInterval(() => {
|
|
2731
|
+
const L2 = import_picocolors.default.magenta(s[m2]), O2 = ".".repeat(Math.floor(w2)).slice(0, 3);
|
|
2732
|
+
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${L2} ${o}${O2}`), m2 = m2 + 1 < s.length ? m2 + 1 : 0, w2 = w2 < s.length ? w2 + 0.125 : 0;
|
|
2733
|
+
}, n);
|
|
2734
|
+
}, x2 = (g2 = "", m2 = 0) => {
|
|
2735
|
+
o = g2 ?? o, r2 = false, clearInterval(i);
|
|
2736
|
+
const w2 = m2 === 0 ? import_picocolors.default.green(M2) : m2 === 1 ? import_picocolors.default.red(P2) : import_picocolors.default.red(V2);
|
|
2737
|
+
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${w2} ${o}
|
|
2738
|
+
`), S2(), t();
|
|
2739
|
+
};
|
|
2740
|
+
return { start: f2, stop: x2, message: (g2 = "") => {
|
|
2741
|
+
o = g2 ?? o;
|
|
2742
|
+
} };
|
|
2743
|
+
};
|
|
2744
|
+
function ye() {
|
|
2745
|
+
const s = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
2746
|
+
return new RegExp(s, "g");
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
// node_modules/commander/esm.mjs
|
|
2750
|
+
var import__ = __toESM(require_commander(), 1);
|
|
2751
|
+
var {
|
|
2752
|
+
program,
|
|
2753
|
+
createCommand,
|
|
2754
|
+
createArgument,
|
|
2755
|
+
createOption,
|
|
2756
|
+
CommanderError,
|
|
2757
|
+
InvalidArgumentError,
|
|
2758
|
+
InvalidOptionArgumentError,
|
|
2759
|
+
Command,
|
|
2760
|
+
Argument,
|
|
2761
|
+
Option,
|
|
2762
|
+
Help
|
|
2763
|
+
} = import__.default;
|
|
2764
|
+
|
|
2765
|
+
// src/cli.ts
|
|
2766
|
+
var import_node_module = require("node:module");
|
|
2767
|
+
|
|
2768
|
+
// src/lib/oauth.ts
|
|
2769
|
+
var import_node_buffer = require("node:buffer");
|
|
2770
|
+
var import_node_crypto = require("node:crypto");
|
|
2771
|
+
|
|
2772
|
+
// src/lib/config.ts
|
|
2773
|
+
var TRAILING_SLASHES_REGEX = /\/+$/;
|
|
2774
|
+
var DEFAULT_BASE_URL = "https://parix.io";
|
|
2775
|
+
var LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
|
|
2776
|
+
function resolveBaseUrl(input, storedSession, options = {}) {
|
|
2777
|
+
const storedSessionBaseUrl = options.useStoredSession === false ? undefined : storedSession?.baseUrl;
|
|
2778
|
+
const value = input ?? storedSessionBaseUrl ?? process.env.PARIX_BASE_URL ?? DEFAULT_BASE_URL;
|
|
2779
|
+
return trimTrailingSlash(new URL(value).toString());
|
|
2780
|
+
}
|
|
2781
|
+
function trimTrailingSlash(value) {
|
|
2782
|
+
return value.replace(TRAILING_SLASHES_REGEX, "");
|
|
2783
|
+
}
|
|
2784
|
+
function parsePortOption(value) {
|
|
2785
|
+
const parsed = Number.parseInt(value, 10);
|
|
2786
|
+
if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
|
|
2787
|
+
throw new Error(`Invalid port: ${value}`);
|
|
2788
|
+
}
|
|
2789
|
+
return parsed;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
// src/lib/oauth.ts
|
|
2793
|
+
var PARIX_CLIENT_ID = "parix";
|
|
2794
|
+
var PARIX_LOCAL_CALLBACK_PATH = "/callback";
|
|
2795
|
+
var CLI_OAUTH_CONSENT_GRANTED_PATH = "/cli-oauth-consent-granted";
|
|
2796
|
+
function createPkcePair() {
|
|
2797
|
+
const codeVerifier = import_node_crypto.randomBytes(32).toString("base64url");
|
|
2798
|
+
const codeChallenge = import_node_crypto.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
2799
|
+
return {
|
|
2800
|
+
codeChallenge,
|
|
2801
|
+
codeVerifier
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
function buildAuthorizeUrl(input) {
|
|
2805
|
+
const url = new URL("/api/oauth/cli/authorize", trimTrailingSlash(input.baseUrl));
|
|
2806
|
+
url.searchParams.set("state", input.state);
|
|
2807
|
+
url.searchParams.set("code_challenge", input.codeChallenge);
|
|
2808
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
2809
|
+
if (input.prompt) {
|
|
2810
|
+
url.searchParams.set("prompt", input.prompt);
|
|
2811
|
+
}
|
|
2812
|
+
return url.toString();
|
|
2813
|
+
}
|
|
2814
|
+
function buildCliState(redirectUri) {
|
|
2815
|
+
return import_node_buffer.Buffer.from(JSON.stringify({
|
|
2816
|
+
nonce: import_node_crypto.randomBytes(16).toString("hex"),
|
|
2817
|
+
redirectUri
|
|
2818
|
+
}), "utf8").toString("base64url");
|
|
2819
|
+
}
|
|
2820
|
+
function buildOAuthCallbackUrl(baseUrl) {
|
|
2821
|
+
return new URL("/api/oauth/cli/callback", trimTrailingSlash(baseUrl)).toString();
|
|
2822
|
+
}
|
|
2823
|
+
function buildOAuthTokenUrl(baseUrl) {
|
|
2824
|
+
return new URL("/api/auth/oauth2/token", trimTrailingSlash(baseUrl)).toString();
|
|
2825
|
+
}
|
|
2826
|
+
function buildOAuthUserInfoUrl(baseUrl) {
|
|
2827
|
+
return new URL("/api/auth/oauth2/userinfo", trimTrailingSlash(baseUrl)).toString();
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
// src/lib/oauth-api.ts
|
|
2831
|
+
var WHITESPACE_REGEX = /\s+/;
|
|
2832
|
+
async function exchangeAuthorizationCode(input) {
|
|
2833
|
+
const body = new URLSearchParams({
|
|
2834
|
+
client_id: PARIX_CLIENT_ID,
|
|
2835
|
+
code: input.code,
|
|
2836
|
+
code_verifier: input.codeVerifier,
|
|
2837
|
+
grant_type: "authorization_code",
|
|
2838
|
+
redirect_uri: buildOAuthCallbackUrl(input.baseUrl)
|
|
2839
|
+
});
|
|
2840
|
+
const response = await fetch(buildOAuthTokenUrl(input.baseUrl), {
|
|
2841
|
+
body,
|
|
2842
|
+
headers: {
|
|
2843
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
2844
|
+
},
|
|
2845
|
+
method: "POST"
|
|
2846
|
+
});
|
|
2847
|
+
return await parseTokenResponse(response);
|
|
2848
|
+
}
|
|
2849
|
+
async function refreshOAuthTokens(input) {
|
|
2850
|
+
const body = new URLSearchParams({
|
|
2851
|
+
client_id: PARIX_CLIENT_ID,
|
|
2852
|
+
grant_type: "refresh_token",
|
|
2853
|
+
refresh_token: input.refreshToken
|
|
2854
|
+
});
|
|
2855
|
+
const response = await fetch(buildOAuthTokenUrl(input.baseUrl), {
|
|
2856
|
+
body,
|
|
2857
|
+
headers: {
|
|
2858
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
2859
|
+
},
|
|
2860
|
+
method: "POST"
|
|
2861
|
+
});
|
|
2862
|
+
return await parseTokenResponse(response);
|
|
2863
|
+
}
|
|
2864
|
+
async function fetchOAuthUserInfo(input) {
|
|
2865
|
+
const response = await fetch(buildOAuthUserInfoUrl(input.baseUrl), {
|
|
2866
|
+
headers: {
|
|
2867
|
+
authorization: `Bearer ${input.accessToken}`
|
|
2868
|
+
}
|
|
2869
|
+
});
|
|
2870
|
+
if (!response.ok) {
|
|
2871
|
+
throw new Error(await readErrorMessage(response, "Unable to fetch the authenticated user."));
|
|
2872
|
+
}
|
|
2873
|
+
return await response.json();
|
|
2874
|
+
}
|
|
2875
|
+
async function parseTokenResponse(response) {
|
|
2876
|
+
if (!response.ok) {
|
|
2877
|
+
throw new Error(await readErrorMessage(response, "Unable to exchange OAuth tokens."));
|
|
2878
|
+
}
|
|
2879
|
+
const payload = await response.json();
|
|
2880
|
+
return {
|
|
2881
|
+
accessToken: payload.access_token,
|
|
2882
|
+
expiresIn: payload.expires_in,
|
|
2883
|
+
refreshToken: payload.refresh_token ?? null,
|
|
2884
|
+
scope: payload.scope?.split(WHITESPACE_REGEX).filter(Boolean) ?? [],
|
|
2885
|
+
tokenType: payload.token_type
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
async function readErrorMessage(response, fallback) {
|
|
2889
|
+
try {
|
|
2890
|
+
const payload = await response.clone().json();
|
|
2891
|
+
return payload.error_description ?? payload.message ?? payload.error ?? fallback;
|
|
2892
|
+
} catch {
|
|
2893
|
+
const text = await response.text();
|
|
2894
|
+
return text.trim() || fallback;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
// src/lib/session.ts
|
|
2899
|
+
var import_promises = require("node:fs/promises");
|
|
2900
|
+
var import_node_os = require("node:os");
|
|
2901
|
+
var import_node_path = require("node:path");
|
|
2902
|
+
var SESSION_FILE_PATH = import_node_path.join(import_node_os.homedir(), ".config", "parix", "session.json");
|
|
2903
|
+
async function readStoredSession() {
|
|
2904
|
+
try {
|
|
2905
|
+
const raw = await import_promises.readFile(SESSION_FILE_PATH, "utf8");
|
|
2906
|
+
return parseStoredSession(JSON.parse(raw));
|
|
2907
|
+
} catch (error) {
|
|
2908
|
+
if (isMissingFileError(error)) {
|
|
2909
|
+
return null;
|
|
2910
|
+
}
|
|
2911
|
+
if (error instanceof SyntaxError) {
|
|
2912
|
+
throw new TypeError(`Failed to parse ${SESSION_FILE_PATH}`);
|
|
2913
|
+
}
|
|
2914
|
+
throw error;
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
async function writeStoredSession(session) {
|
|
2918
|
+
await import_promises.mkdir(import_node_path.dirname(SESSION_FILE_PATH), { recursive: true });
|
|
2919
|
+
await import_promises.writeFile(SESSION_FILE_PATH, `${JSON.stringify(session, null, 2)}
|
|
2920
|
+
`, "utf8");
|
|
2921
|
+
}
|
|
2922
|
+
async function clearStoredSession() {
|
|
2923
|
+
await import_promises.rm(SESSION_FILE_PATH, { force: true });
|
|
2924
|
+
}
|
|
2925
|
+
function parseStoredSession(value) {
|
|
2926
|
+
if (!value || typeof value !== "object") {
|
|
2927
|
+
throw new Error(`Invalid session data in ${SESSION_FILE_PATH}`);
|
|
2928
|
+
}
|
|
2929
|
+
const row = value;
|
|
2930
|
+
const user = row.user;
|
|
2931
|
+
const organization = row.organization;
|
|
2932
|
+
if (row.version !== 2 || typeof row.baseUrl !== "string" || typeof row.accessToken !== "string" || typeof row.accessTokenExpiresAt !== "string" || typeof row.createdAt !== "string" || !Array.isArray(row.scopes) || typeof row.tokenType !== "string" || typeof row.updatedAt !== "string" || !user || typeof user.id !== "string" || !organization) {
|
|
2933
|
+
throw new Error(`Invalid session data in ${SESSION_FILE_PATH}`);
|
|
2934
|
+
}
|
|
2935
|
+
return {
|
|
2936
|
+
version: 2,
|
|
2937
|
+
accessToken: row.accessToken,
|
|
2938
|
+
accessTokenExpiresAt: row.accessTokenExpiresAt,
|
|
2939
|
+
baseUrl: row.baseUrl,
|
|
2940
|
+
createdAt: row.createdAt,
|
|
2941
|
+
refreshToken: typeof row.refreshToken === "string" ? row.refreshToken : null,
|
|
2942
|
+
scopes: row.scopes.filter((scope) => typeof scope === "string"),
|
|
2943
|
+
tokenType: row.tokenType,
|
|
2944
|
+
updatedAt: row.updatedAt,
|
|
2945
|
+
user: {
|
|
2946
|
+
id: user.id,
|
|
2947
|
+
email: typeof user.email === "string" ? user.email : null,
|
|
2948
|
+
emailVerified: typeof user.emailVerified === "boolean" ? user.emailVerified : null,
|
|
2949
|
+
name: typeof user.name === "string" ? user.name : null,
|
|
2950
|
+
image: typeof user.image === "string" ? user.image : null
|
|
2951
|
+
},
|
|
2952
|
+
organization: {
|
|
2953
|
+
id: typeof organization.id === "string" ? organization.id : null,
|
|
2954
|
+
memberRole: typeof organization.memberRole === "string" ? organization.memberRole : null,
|
|
2955
|
+
name: typeof organization.name === "string" ? organization.name : null,
|
|
2956
|
+
slug: typeof organization.slug === "string" ? organization.slug : null
|
|
2957
|
+
}
|
|
2958
|
+
};
|
|
2959
|
+
}
|
|
2960
|
+
function isMissingFileError(error) {
|
|
2961
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
// src/lib/oauth-session.ts
|
|
2965
|
+
var REFRESH_BUFFER_MS = 60000;
|
|
2966
|
+
async function createStoredSession(input) {
|
|
2967
|
+
const now = new Date;
|
|
2968
|
+
const [userInfo, resolvedOrganization] = await Promise.all([
|
|
2969
|
+
fetchOAuthUserInfo({
|
|
2970
|
+
accessToken: input.tokenSet.accessToken,
|
|
2971
|
+
baseUrl: input.baseUrl
|
|
2972
|
+
}),
|
|
2973
|
+
fetchResolvedSessionOrganization({
|
|
2974
|
+
accessToken: input.tokenSet.accessToken,
|
|
2975
|
+
baseUrl: input.baseUrl
|
|
2976
|
+
}).catch(() => null)
|
|
2977
|
+
]);
|
|
2978
|
+
return {
|
|
2979
|
+
version: 2,
|
|
2980
|
+
accessToken: input.tokenSet.accessToken,
|
|
2981
|
+
accessTokenExpiresAt: new Date(now.getTime() + input.tokenSet.expiresIn * 1000).toISOString(),
|
|
2982
|
+
baseUrl: input.baseUrl,
|
|
2983
|
+
createdAt: input.createdAt ?? now.toISOString(),
|
|
2984
|
+
refreshToken: input.tokenSet.refreshToken,
|
|
2985
|
+
scopes: input.tokenSet.scope,
|
|
2986
|
+
tokenType: input.tokenSet.tokenType,
|
|
2987
|
+
updatedAt: now.toISOString(),
|
|
2988
|
+
user: {
|
|
2989
|
+
email: userInfo.email ?? null,
|
|
2990
|
+
emailVerified: userInfo.email_verified ?? null,
|
|
2991
|
+
id: userInfo.sub,
|
|
2992
|
+
image: userInfo.picture ?? null,
|
|
2993
|
+
name: userInfo.name ?? null
|
|
2994
|
+
},
|
|
2995
|
+
organization: {
|
|
2996
|
+
id: resolvedOrganization?.id ?? userInfo.organization_id ?? null,
|
|
2997
|
+
memberRole: resolvedOrganization?.memberRole ?? userInfo.member_role ?? null,
|
|
2998
|
+
name: resolvedOrganization?.name ?? userInfo.organization_name ?? null,
|
|
2999
|
+
slug: resolvedOrganization?.slug ?? userInfo.organization_slug ?? null
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
}
|
|
3003
|
+
async function hydrateStoredSessionOrganization(session) {
|
|
3004
|
+
const resolvedOrganization = await fetchResolvedSessionOrganization({
|
|
3005
|
+
accessToken: session.accessToken,
|
|
3006
|
+
baseUrl: session.baseUrl
|
|
3007
|
+
}).catch(() => null);
|
|
3008
|
+
if (!resolvedOrganization || organizationsEqual(session.organization, resolvedOrganization)) {
|
|
3009
|
+
return session;
|
|
3010
|
+
}
|
|
3011
|
+
const nextSession = {
|
|
3012
|
+
...session,
|
|
3013
|
+
organization: resolvedOrganization,
|
|
3014
|
+
updatedAt: new Date().toISOString()
|
|
3015
|
+
};
|
|
3016
|
+
await writeStoredSession(nextSession);
|
|
3017
|
+
return nextSession;
|
|
3018
|
+
}
|
|
3019
|
+
async function ensureFreshSession(session) {
|
|
3020
|
+
if (!shouldRefresh(session)) {
|
|
3021
|
+
return session;
|
|
3022
|
+
}
|
|
3023
|
+
if (!session.refreshToken) {
|
|
3024
|
+
throw new Error("The local session has expired and cannot be refreshed. Run `parix auth login` again.");
|
|
3025
|
+
}
|
|
3026
|
+
const refreshedTokens = await refreshOAuthTokens({
|
|
3027
|
+
baseUrl: session.baseUrl,
|
|
3028
|
+
refreshToken: session.refreshToken
|
|
3029
|
+
});
|
|
3030
|
+
const updatedSession = await createStoredSession({
|
|
3031
|
+
baseUrl: session.baseUrl,
|
|
3032
|
+
createdAt: session.createdAt,
|
|
3033
|
+
tokenSet: refreshedTokens
|
|
3034
|
+
});
|
|
3035
|
+
await writeStoredSession(updatedSession);
|
|
3036
|
+
return updatedSession;
|
|
3037
|
+
}
|
|
3038
|
+
function shouldRefresh(session) {
|
|
3039
|
+
const expiresAt = Date.parse(session.accessTokenExpiresAt);
|
|
3040
|
+
return Number.isNaN(expiresAt) || expiresAt <= Date.now() + REFRESH_BUFFER_MS;
|
|
3041
|
+
}
|
|
3042
|
+
async function fetchResolvedSessionOrganization(input) {
|
|
3043
|
+
const response = await fetch(new URL("/api/v1/session", input.baseUrl), {
|
|
3044
|
+
headers: {
|
|
3045
|
+
authorization: `Bearer ${input.accessToken}`
|
|
3046
|
+
}
|
|
3047
|
+
});
|
|
3048
|
+
if (!response.ok) {
|
|
3049
|
+
throw new Error("Unable to resolve the authenticated organization.");
|
|
3050
|
+
}
|
|
3051
|
+
const payload = await response.json();
|
|
3052
|
+
const organization = payload.auth?.organization;
|
|
3053
|
+
if (!organization) {
|
|
3054
|
+
return null;
|
|
3055
|
+
}
|
|
3056
|
+
return {
|
|
3057
|
+
id: typeof organization.id === "string" ? organization.id : null,
|
|
3058
|
+
memberRole: typeof organization.memberRole === "string" ? organization.memberRole : null,
|
|
3059
|
+
name: typeof organization.name === "string" ? organization.name : null,
|
|
3060
|
+
slug: typeof organization.slug === "string" ? organization.slug : null
|
|
3061
|
+
};
|
|
3062
|
+
}
|
|
3063
|
+
function organizationsEqual(left, right) {
|
|
3064
|
+
return left.id === right.id && left.memberRole === right.memberRole && left.name === right.name && left.slug === right.slug;
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
// src/lib/api-client.ts
|
|
3068
|
+
var TRAILING_SLASHES_REGEX2 = /\/+$/;
|
|
3069
|
+
|
|
3070
|
+
class ApiClient {
|
|
3071
|
+
session;
|
|
3072
|
+
constructor(options) {
|
|
3073
|
+
this.session = options.session;
|
|
3074
|
+
}
|
|
3075
|
+
async request(pathname, init = {}) {
|
|
3076
|
+
this.session = await ensureFreshSession(this.session);
|
|
3077
|
+
const url = toRequestUrl(pathname, this.session.baseUrl);
|
|
3078
|
+
const headers = new Headers(init.headers);
|
|
3079
|
+
headers.set("authorization", `Bearer ${this.session.accessToken}`);
|
|
3080
|
+
const response = await fetch(url, {
|
|
3081
|
+
...init,
|
|
3082
|
+
headers
|
|
3083
|
+
});
|
|
3084
|
+
if (response.status !== 401) {
|
|
3085
|
+
return response;
|
|
3086
|
+
}
|
|
3087
|
+
this.session = await ensureFreshSession({
|
|
3088
|
+
...this.session,
|
|
3089
|
+
accessTokenExpiresAt: new Date(0).toISOString()
|
|
3090
|
+
});
|
|
3091
|
+
const retryHeaders = new Headers(init.headers);
|
|
3092
|
+
retryHeaders.set("authorization", `Bearer ${this.session.accessToken}`);
|
|
3093
|
+
return fetch(url, {
|
|
3094
|
+
...init,
|
|
3095
|
+
headers: retryHeaders
|
|
3096
|
+
});
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
function toRequestUrl(pathname, baseUrl) {
|
|
3100
|
+
if (pathname.startsWith("http://") || pathname.startsWith("https://")) {
|
|
3101
|
+
return pathname;
|
|
3102
|
+
}
|
|
3103
|
+
return new URL(pathname, `${trimTrailingSlash2(baseUrl)}/`).toString();
|
|
3104
|
+
}
|
|
3105
|
+
function trimTrailingSlash2(value) {
|
|
3106
|
+
return value.replace(TRAILING_SLASHES_REGEX2, "");
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
// src/commands/api.ts
|
|
3110
|
+
function createApiCommand() {
|
|
3111
|
+
return new Command("api").description("Make an authenticated API request with the stored bearer token").argument("<path>", "Relative API path or absolute URL").option("-X, --method <method>", "HTTP method", "GET").option("-d, --body <body>", "Raw request body").option("-H, --header <header>", "Additional header in key:value form", collectValues, []).option("-b, --base-url <url>", "Override the stored base URL").action(async (requestPath, options) => {
|
|
3112
|
+
await handleApiRequest(requestPath, options);
|
|
3113
|
+
});
|
|
3114
|
+
}
|
|
3115
|
+
async function handleApiRequest(requestPath, options) {
|
|
3116
|
+
const storedSession = await readStoredSession();
|
|
3117
|
+
if (!storedSession) {
|
|
3118
|
+
throw new Error("No local session found. Run `parix auth login` first.");
|
|
3119
|
+
}
|
|
3120
|
+
const baseUrl = resolveBaseUrl(options.baseUrl, storedSession);
|
|
3121
|
+
const headers = parseHeaders(options.header ?? []);
|
|
3122
|
+
const body = options.body ?? undefined;
|
|
3123
|
+
if (body && !hasHeader(headers, "content-type")) {
|
|
3124
|
+
headers.set("content-type", "application/json");
|
|
3125
|
+
}
|
|
3126
|
+
const client = new ApiClient({
|
|
3127
|
+
session: {
|
|
3128
|
+
...storedSession,
|
|
3129
|
+
baseUrl
|
|
3130
|
+
}
|
|
3131
|
+
});
|
|
3132
|
+
const response = await client.request(requestPath, {
|
|
3133
|
+
method: options.method ?? "GET",
|
|
3134
|
+
headers,
|
|
3135
|
+
body
|
|
3136
|
+
});
|
|
3137
|
+
const contentType = response.headers.get("content-type") ?? "unknown";
|
|
3138
|
+
const payload = await response.text();
|
|
3139
|
+
me([`Status: ${response.status} ${response.statusText}`, `Content-Type: ${contentType}`].join(`
|
|
3140
|
+
`), "Response");
|
|
3141
|
+
if (contentType.includes("application/json") && payload.length > 0) {
|
|
3142
|
+
try {
|
|
3143
|
+
v2.message(JSON.stringify(JSON.parse(payload), null, 2));
|
|
3144
|
+
} catch {
|
|
3145
|
+
v2.message(payload);
|
|
3146
|
+
}
|
|
3147
|
+
} else if (payload.length > 0) {
|
|
3148
|
+
v2.message(payload);
|
|
3149
|
+
}
|
|
3150
|
+
if (!response.ok) {
|
|
3151
|
+
process.exitCode = 1;
|
|
3152
|
+
ge(`Request failed with HTTP ${response.status}`);
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
ge("Request completed");
|
|
3156
|
+
}
|
|
3157
|
+
function collectValues(value, previous) {
|
|
3158
|
+
previous.push(value);
|
|
3159
|
+
return previous;
|
|
3160
|
+
}
|
|
3161
|
+
function parseHeaders(values) {
|
|
3162
|
+
const headers = new Headers;
|
|
3163
|
+
for (const value of values) {
|
|
3164
|
+
const separatorIndex = value.indexOf(":");
|
|
3165
|
+
if (separatorIndex <= 0) {
|
|
3166
|
+
throw new Error(`Invalid header format: ${value}. Use key:value.`);
|
|
3167
|
+
}
|
|
3168
|
+
const key = value.slice(0, separatorIndex).trim();
|
|
3169
|
+
const headerValue = value.slice(separatorIndex + 1).trim();
|
|
3170
|
+
if (!key) {
|
|
3171
|
+
throw new Error(`Invalid header name: ${value}`);
|
|
3172
|
+
}
|
|
3173
|
+
headers.set(key, headerValue);
|
|
3174
|
+
}
|
|
3175
|
+
return headers;
|
|
3176
|
+
}
|
|
3177
|
+
function hasHeader(headers, name) {
|
|
3178
|
+
return headers.has(name) || headers.has(name.toLowerCase());
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
// src/lib/loopback-server.ts
|
|
3182
|
+
var import_node_http = require("node:http");
|
|
3183
|
+
async function startLoopbackServer(options) {
|
|
3184
|
+
const server = import_node_http.createServer();
|
|
3185
|
+
let completed = false;
|
|
3186
|
+
let expectedState = options.state ?? null;
|
|
3187
|
+
let resolveResult = null;
|
|
3188
|
+
let rejectResult = null;
|
|
3189
|
+
let timeout = null;
|
|
3190
|
+
const clearTimeoutIfNeeded = () => {
|
|
3191
|
+
if (timeout) {
|
|
3192
|
+
clearTimeout(timeout);
|
|
3193
|
+
timeout = null;
|
|
3194
|
+
}
|
|
3195
|
+
};
|
|
3196
|
+
const settle = (handler, value, reason) => {
|
|
3197
|
+
if (completed) {
|
|
3198
|
+
return;
|
|
3199
|
+
}
|
|
3200
|
+
completed = true;
|
|
3201
|
+
clearTimeoutIfNeeded();
|
|
3202
|
+
if (!handler) {
|
|
3203
|
+
return;
|
|
3204
|
+
}
|
|
3205
|
+
if (reason !== undefined) {
|
|
3206
|
+
handler(reason);
|
|
3207
|
+
return;
|
|
3208
|
+
}
|
|
3209
|
+
if (value) {
|
|
3210
|
+
handler(value);
|
|
3211
|
+
}
|
|
3212
|
+
};
|
|
3213
|
+
const result = new Promise((resolve, reject) => {
|
|
3214
|
+
resolveResult = resolve;
|
|
3215
|
+
rejectResult = reject;
|
|
3216
|
+
});
|
|
3217
|
+
server.on("request", (request, response) => {
|
|
3218
|
+
response.setHeader("connection", "close");
|
|
3219
|
+
const requestUrl = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
3220
|
+
if (requestUrl.pathname === "/favicon.ico") {
|
|
3221
|
+
response.writeHead(204);
|
|
3222
|
+
response.end();
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
if (requestUrl.pathname !== options.callbackPath) {
|
|
3226
|
+
response.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
|
|
3227
|
+
response.end("Not found");
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
const returnedState = requestUrl.searchParams.get("state");
|
|
3231
|
+
const code = requestUrl.searchParams.get("code");
|
|
3232
|
+
const error = requestUrl.searchParams.get("error");
|
|
3233
|
+
const errorDescription = requestUrl.searchParams.get("error_description");
|
|
3234
|
+
if (!expectedState || returnedState !== expectedState) {
|
|
3235
|
+
response.writeHead(400, { "content-type": "text/html; charset=utf-8" });
|
|
3236
|
+
response.end(buildHtml("Authentication failed", "The callback state did not match."));
|
|
3237
|
+
settle(rejectResult, undefined, new Error("The callback state did not match the original login request."));
|
|
3238
|
+
return;
|
|
3239
|
+
}
|
|
3240
|
+
if (error) {
|
|
3241
|
+
response.writeHead(400, { "content-type": "text/html; charset=utf-8" });
|
|
3242
|
+
response.end(buildHtml("Authentication failed", errorDescription ?? error));
|
|
3243
|
+
settle(rejectResult, undefined, new Error(errorDescription ?? error));
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
if (!code) {
|
|
3247
|
+
response.writeHead(400, { "content-type": "text/html; charset=utf-8" });
|
|
3248
|
+
response.end(buildHtml("Authentication failed", "No authorization code was returned."));
|
|
3249
|
+
settle(rejectResult, undefined, new Error("No authorization code was returned from the browser callback."));
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
if (options.successPage) {
|
|
3253
|
+
response.writeHead(302, {
|
|
3254
|
+
"cache-control": "no-store",
|
|
3255
|
+
location: options.successPage.redirectUrl
|
|
3256
|
+
});
|
|
3257
|
+
response.end();
|
|
3258
|
+
settle(resolveResult, { code });
|
|
3259
|
+
return;
|
|
3260
|
+
}
|
|
3261
|
+
response.writeHead(200, {
|
|
3262
|
+
"cache-control": "no-store",
|
|
3263
|
+
"content-type": "text/html; charset=utf-8"
|
|
3264
|
+
});
|
|
3265
|
+
response.end(buildHtml("Authentication complete", "You can close the tab and return to the terminal."));
|
|
3266
|
+
settle(resolveResult, { code });
|
|
3267
|
+
});
|
|
3268
|
+
await listen(server, options.port ?? 0);
|
|
3269
|
+
timeout = setTimeout(() => {
|
|
3270
|
+
settle(rejectResult, undefined, new Error("Timed out waiting for the browser callback."));
|
|
3271
|
+
closeServer(server);
|
|
3272
|
+
}, options.timeoutMs);
|
|
3273
|
+
const address = server.address();
|
|
3274
|
+
if (!address || typeof address === "string") {
|
|
3275
|
+
throw new Error("Failed to determine the loopback callback port.");
|
|
3276
|
+
}
|
|
3277
|
+
return {
|
|
3278
|
+
callbackUrl: `http://127.0.0.1:${address.port}${options.callbackPath}`,
|
|
3279
|
+
setState: (state) => {
|
|
3280
|
+
expectedState = state;
|
|
3281
|
+
},
|
|
3282
|
+
waitForResult: async () => {
|
|
3283
|
+
return await result;
|
|
3284
|
+
},
|
|
3285
|
+
close: async () => {
|
|
3286
|
+
clearTimeoutIfNeeded();
|
|
3287
|
+
await closeServer(server);
|
|
3288
|
+
}
|
|
3289
|
+
};
|
|
3290
|
+
}
|
|
3291
|
+
function listen(server, port) {
|
|
3292
|
+
return new Promise((resolve, reject) => {
|
|
3293
|
+
server.once("error", reject);
|
|
3294
|
+
server.listen({ host: "127.0.0.1", port }, () => {
|
|
3295
|
+
server.off("error", reject);
|
|
3296
|
+
resolve();
|
|
3297
|
+
});
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
function closeServer(server) {
|
|
3301
|
+
return new Promise((resolve, reject) => {
|
|
3302
|
+
let settled = false;
|
|
3303
|
+
const finish = (error) => {
|
|
3304
|
+
if (settled) {
|
|
3305
|
+
return;
|
|
3306
|
+
}
|
|
3307
|
+
settled = true;
|
|
3308
|
+
if (error) {
|
|
3309
|
+
reject(error);
|
|
3310
|
+
return;
|
|
3311
|
+
}
|
|
3312
|
+
resolve();
|
|
3313
|
+
};
|
|
3314
|
+
server.close((error) => {
|
|
3315
|
+
if (error) {
|
|
3316
|
+
if ("code" in error && error.code === "ERR_SERVER_NOT_RUNNING") {
|
|
3317
|
+
finish();
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
finish(error);
|
|
3321
|
+
return;
|
|
3322
|
+
}
|
|
3323
|
+
finish();
|
|
3324
|
+
});
|
|
3325
|
+
server.closeAllConnections();
|
|
3326
|
+
setTimeout(() => {
|
|
3327
|
+
finish();
|
|
3328
|
+
}, 250).unref();
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
function buildHtml(title, message) {
|
|
3332
|
+
return `<!doctype html>
|
|
3333
|
+
<html lang="en">
|
|
3334
|
+
<head>
|
|
3335
|
+
<meta charset="utf-8" />
|
|
3336
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
3337
|
+
<title>${escapeHtml(title)}</title>
|
|
3338
|
+
</head>
|
|
3339
|
+
<body style="font-family: sans-serif; padding: 2rem; line-height: 1.5;">
|
|
3340
|
+
<h1>${escapeHtml(title)}</h1>
|
|
3341
|
+
<p>${escapeHtml(message)}</p>
|
|
3342
|
+
<script>window.close()</script>
|
|
3343
|
+
</body>
|
|
3344
|
+
</html>`;
|
|
3345
|
+
}
|
|
3346
|
+
function escapeHtml(value) {
|
|
3347
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3350
|
+
// src/lib/open-url.ts
|
|
3351
|
+
var import_node_child_process = require("node:child_process");
|
|
3352
|
+
var import_node_process3 = __toESM(require("node:process"));
|
|
3353
|
+
async function openUrlInBrowser(url) {
|
|
3354
|
+
const command = getOpenCommand(url);
|
|
3355
|
+
if (!command) {
|
|
3356
|
+
return false;
|
|
3357
|
+
}
|
|
3358
|
+
try {
|
|
3359
|
+
const child = import_node_child_process.spawn(command.bin, command.args, {
|
|
3360
|
+
detached: true,
|
|
3361
|
+
stdio: "ignore",
|
|
3362
|
+
windowsHide: true
|
|
3363
|
+
});
|
|
3364
|
+
child.unref();
|
|
3365
|
+
return true;
|
|
3366
|
+
} catch {
|
|
3367
|
+
return false;
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
function getOpenCommand(url) {
|
|
3371
|
+
if (import_node_process3.default.platform === "darwin") {
|
|
3372
|
+
return { bin: "open", args: [url] };
|
|
3373
|
+
}
|
|
3374
|
+
if (import_node_process3.default.platform === "win32") {
|
|
3375
|
+
return { bin: "cmd", args: ["/c", "start", "", url] };
|
|
3376
|
+
}
|
|
3377
|
+
if (import_node_process3.default.platform === "linux") {
|
|
3378
|
+
return { bin: "xdg-open", args: [url] };
|
|
3379
|
+
}
|
|
3380
|
+
return null;
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
// src/commands/auth.ts
|
|
3384
|
+
var DEFAULT_OIDC_PROMPT = "consent";
|
|
3385
|
+
function createAuthCommand() {
|
|
3386
|
+
const auth = new Command("auth").description("Authenticate with Parix");
|
|
3387
|
+
auth.command("login").description("Sign in with OAuth consent and PKCE").option("-b, --base-url <url>", "Parix base URL").option("-p, --port <port>", "Loopback callback port", parsePortOption).option("--prompt <prompt>", "OAuth prompt override", DEFAULT_OIDC_PROMPT).action(async (options) => {
|
|
3388
|
+
await handleLogin(options);
|
|
3389
|
+
});
|
|
3390
|
+
auth.command("status").description("Show the current authenticated session").option("-b, --base-url <url>", "Override the stored base URL").action(async (options) => {
|
|
3391
|
+
await handleStatus(options);
|
|
3392
|
+
});
|
|
3393
|
+
auth.command("logout").description("Remove the local session file").action(async () => {
|
|
3394
|
+
await clearStoredSession();
|
|
3395
|
+
ge(`Removed local session at ${SESSION_FILE_PATH}`);
|
|
3396
|
+
});
|
|
3397
|
+
return auth;
|
|
3398
|
+
}
|
|
3399
|
+
async function handleLogin(options) {
|
|
3400
|
+
pe("Parix sign in");
|
|
3401
|
+
const storedSession = await readStoredSession();
|
|
3402
|
+
const baseUrl = resolveBaseUrl(options.baseUrl, storedSession, { useStoredSession: false });
|
|
3403
|
+
const loopbackServer = await startLoopbackServer({
|
|
3404
|
+
callbackPath: PARIX_LOCAL_CALLBACK_PATH,
|
|
3405
|
+
port: options.port,
|
|
3406
|
+
successPage: {
|
|
3407
|
+
redirectUrl: new URL(CLI_OAUTH_CONSENT_GRANTED_PATH, baseUrl).toString()
|
|
3408
|
+
},
|
|
3409
|
+
timeoutMs: LOGIN_TIMEOUT_MS
|
|
3410
|
+
});
|
|
3411
|
+
try {
|
|
3412
|
+
const pkcePair = createPkcePair();
|
|
3413
|
+
const state = buildCliState(loopbackServer.callbackUrl);
|
|
3414
|
+
loopbackServer.setState(state);
|
|
3415
|
+
const browserUrl = buildAuthorizeUrl({
|
|
3416
|
+
baseUrl,
|
|
3417
|
+
codeChallenge: pkcePair.codeChallenge,
|
|
3418
|
+
prompt: options.prompt,
|
|
3419
|
+
state
|
|
3420
|
+
});
|
|
3421
|
+
const prepareSpinner = _2();
|
|
3422
|
+
prepareSpinner.start("Preparing browser sign-in");
|
|
3423
|
+
prepareSpinner.stop("Browser sign-in ready");
|
|
3424
|
+
const opened = await openUrlInBrowser(browserUrl);
|
|
3425
|
+
me(opened ? browserUrl : `Open this URL manually:
|
|
3426
|
+
${browserUrl}`, opened ? "Opened browser URL" : "Manual browser URL");
|
|
3427
|
+
const waitSpinner = _2();
|
|
3428
|
+
waitSpinner.start("Waiting for browser callback");
|
|
3429
|
+
const callbackResult = await loopbackServer.waitForResult();
|
|
3430
|
+
waitSpinner.stop("Received browser callback");
|
|
3431
|
+
await loopbackServer.close().catch(() => {});
|
|
3432
|
+
const tokenSet = await exchangeAuthorizationCode({
|
|
3433
|
+
baseUrl,
|
|
3434
|
+
code: callbackResult.code,
|
|
3435
|
+
codeVerifier: pkcePair.codeVerifier
|
|
3436
|
+
});
|
|
3437
|
+
const nextSession = await createStoredSession({
|
|
3438
|
+
baseUrl,
|
|
3439
|
+
createdAt: storedSession?.createdAt,
|
|
3440
|
+
tokenSet
|
|
3441
|
+
});
|
|
3442
|
+
await writeStoredSession(nextSession);
|
|
3443
|
+
me(SESSION_FILE_PATH, "Stored session file");
|
|
3444
|
+
ge(`Signed in as ${formatUserLabel(nextSession.user)}`);
|
|
3445
|
+
} finally {
|
|
3446
|
+
await loopbackServer.close().catch(() => {});
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
async function handleStatus(options) {
|
|
3450
|
+
pe("Parix auth status");
|
|
3451
|
+
const storedSession = await readStoredSession();
|
|
3452
|
+
if (!storedSession) {
|
|
3453
|
+
v2.warn(`No local session found at ${SESSION_FILE_PATH}`);
|
|
3454
|
+
process.exitCode = 1;
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
const baseUrl = resolveBaseUrl(options.baseUrl, storedSession);
|
|
3458
|
+
try {
|
|
3459
|
+
const refreshedSession = await hydrateStoredSessionOrganization(await ensureFreshSession({
|
|
3460
|
+
...storedSession,
|
|
3461
|
+
baseUrl
|
|
3462
|
+
}));
|
|
3463
|
+
const userInfo = await fetchOAuthUserInfo({
|
|
3464
|
+
accessToken: refreshedSession.accessToken,
|
|
3465
|
+
baseUrl
|
|
3466
|
+
});
|
|
3467
|
+
me([
|
|
3468
|
+
`User: ${userInfo.email ?? formatUserLabel(refreshedSession.user)}`,
|
|
3469
|
+
`Base URL: ${baseUrl}`,
|
|
3470
|
+
`Expires: ${refreshedSession.accessTokenExpiresAt}`,
|
|
3471
|
+
`Scopes: ${refreshedSession.scopes.join(", ")}`,
|
|
3472
|
+
`Organization: ${refreshedSession.organization.name ?? "none"}`,
|
|
3473
|
+
`Organization slug: ${refreshedSession.organization.slug ?? "none"}`,
|
|
3474
|
+
`Member role: ${refreshedSession.organization.memberRole ?? "none"}`,
|
|
3475
|
+
`Session file: ${SESSION_FILE_PATH}`
|
|
3476
|
+
].join(`
|
|
3477
|
+
`), "Authenticated session");
|
|
3478
|
+
ge("Session is valid");
|
|
3479
|
+
} catch (error) {
|
|
35
3480
|
const message = error instanceof Error ? error.message : String(error);
|
|
36
|
-
|
|
37
|
-
process.
|
|
3481
|
+
v2.warn(`Stored session is invalid: ${message}`);
|
|
3482
|
+
process.exitCode = 1;
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
function formatUserLabel(user) {
|
|
3486
|
+
return user.email ?? user.name ?? user.id;
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
// src/lib/output.ts
|
|
3490
|
+
function printJson(value) {
|
|
3491
|
+
v2.message(JSON.stringify(value, null, 2));
|
|
3492
|
+
}
|
|
3493
|
+
function printKeyValues(entries) {
|
|
3494
|
+
const keyWidth = Math.max(...entries.map(([key]) => key.length), 0);
|
|
3495
|
+
v2.message(entries.map(([key, value]) => `${key.padEnd(keyWidth)} ${value}`).join(`
|
|
3496
|
+
`));
|
|
3497
|
+
}
|
|
3498
|
+
function printTable(input) {
|
|
3499
|
+
const widths = input.columns.map((column, index) => Math.max(column.length, ...input.rows.map((row) => row[index]?.length ?? 0)));
|
|
3500
|
+
const header = input.columns.map((column, index) => column.padEnd(widths[index] ?? 0)).join(" ");
|
|
3501
|
+
const divider = widths.map((width) => "-".repeat(width)).join(" ");
|
|
3502
|
+
const rows = input.rows.map((row) => row.map((value, index) => value.padEnd(widths[index] ?? 0)).join(" "));
|
|
3503
|
+
v2.message([header, divider, ...rows].join(`
|
|
3504
|
+
`));
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
// src/lib/parix-api.ts
|
|
3508
|
+
async function createApiClient(baseUrlOverride) {
|
|
3509
|
+
const storedSession = await readStoredSession();
|
|
3510
|
+
if (!storedSession) {
|
|
3511
|
+
throw new Error("No local session found. Run `parix auth login` first.");
|
|
3512
|
+
}
|
|
3513
|
+
const baseUrl = resolveBaseUrl(baseUrlOverride, storedSession);
|
|
3514
|
+
return {
|
|
3515
|
+
baseUrl,
|
|
3516
|
+
client: new ApiClient({
|
|
3517
|
+
session: {
|
|
3518
|
+
...storedSession,
|
|
3519
|
+
baseUrl
|
|
3520
|
+
}
|
|
3521
|
+
})
|
|
3522
|
+
};
|
|
3523
|
+
}
|
|
3524
|
+
async function requestApiJson(input) {
|
|
3525
|
+
const { client } = await createApiClient(input.baseUrl);
|
|
3526
|
+
const response = await client.request(input.path, {
|
|
3527
|
+
body: input.body,
|
|
3528
|
+
headers: input.headers,
|
|
3529
|
+
method: input.method
|
|
3530
|
+
});
|
|
3531
|
+
const raw = await response.text();
|
|
3532
|
+
const payload = raw.length > 0 ? safeParseJson(raw) : null;
|
|
3533
|
+
if (!response.ok) {
|
|
3534
|
+
const message = getApiErrorMessage(payload) ?? (typeof raw === "string" && raw.trim().length > 0 ? raw.trim() : null) ?? `${response.status} ${response.statusText}`;
|
|
3535
|
+
throw new ApiRequestError(message, response.status, payload);
|
|
3536
|
+
}
|
|
3537
|
+
return payload;
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
class ApiRequestError extends Error {
|
|
3541
|
+
status;
|
|
3542
|
+
payload;
|
|
3543
|
+
constructor(message, status, payload) {
|
|
3544
|
+
super(message);
|
|
3545
|
+
this.name = "ApiRequestError";
|
|
3546
|
+
this.status = status;
|
|
3547
|
+
this.payload = payload;
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
function safeParseJson(value) {
|
|
3551
|
+
try {
|
|
3552
|
+
return JSON.parse(value);
|
|
3553
|
+
} catch {
|
|
3554
|
+
return value;
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
function getApiErrorMessage(payload) {
|
|
3558
|
+
if (!payload || typeof payload !== "object") {
|
|
3559
|
+
return null;
|
|
3560
|
+
}
|
|
3561
|
+
const row = payload;
|
|
3562
|
+
const parts = [];
|
|
3563
|
+
if (typeof row.detail === "string" && row.detail.trim().length > 0) {
|
|
3564
|
+
parts.push(row.detail.trim());
|
|
3565
|
+
} else if (typeof row.message === "string" && row.message.trim().length > 0) {
|
|
3566
|
+
parts.push(row.message.trim());
|
|
3567
|
+
} else if (typeof row.error === "string" && row.error.trim().length > 0) {
|
|
3568
|
+
parts.push(row.error.trim());
|
|
3569
|
+
} else if (typeof row.title === "string" && row.title.trim().length > 0) {
|
|
3570
|
+
parts.push(row.title.trim());
|
|
3571
|
+
}
|
|
3572
|
+
if (Array.isArray(row.tbResults) && row.tbResults.length > 0) {
|
|
3573
|
+
parts.push(`tbResults: ${JSON.stringify(row.tbResults)}`);
|
|
3574
|
+
}
|
|
3575
|
+
if (parts.length === 0) {
|
|
3576
|
+
return null;
|
|
3577
|
+
}
|
|
3578
|
+
return parts.join(" — ");
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
// src/commands/database.ts
|
|
3582
|
+
function createDatabaseCommand() {
|
|
3583
|
+
const database = new Command("database").description("Manage Parix databases").addHelpText("after", [
|
|
3584
|
+
"",
|
|
3585
|
+
"Examples:",
|
|
3586
|
+
" parix database catalog --base-url http://localhost:5173",
|
|
3587
|
+
" parix database create demo-ledger --provider gcp --region asia-southeast1",
|
|
3588
|
+
" parix database list",
|
|
3589
|
+
" parix database info id-123",
|
|
3590
|
+
" parix database remove id-123 --yes"
|
|
3591
|
+
].join(`
|
|
3592
|
+
`));
|
|
3593
|
+
database.command("catalog").description("Show database creation catalog options").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").action(async (options) => {
|
|
3594
|
+
const response = await requestApiJson({
|
|
3595
|
+
baseUrl: options.baseUrl,
|
|
3596
|
+
path: "/api/v1/catalog/create"
|
|
3597
|
+
});
|
|
3598
|
+
if (options.json) {
|
|
3599
|
+
printJson(response);
|
|
3600
|
+
return;
|
|
3601
|
+
}
|
|
3602
|
+
printTable({
|
|
3603
|
+
columns: ["Provider", "Regions"],
|
|
3604
|
+
rows: response.catalog.providers.map((provider) => [
|
|
3605
|
+
provider.slug,
|
|
3606
|
+
provider.regions.map((region) => region.code).join(", ")
|
|
3607
|
+
])
|
|
3608
|
+
});
|
|
3609
|
+
me("Use `--provider <slug>` and `--region <code>` from this table.", "Providers");
|
|
3610
|
+
printTable({
|
|
3611
|
+
columns: ["Config ID", "Label", "Nodes"],
|
|
3612
|
+
rows: response.catalog.clusterConfigs.map((config) => [config.id, config.label, String(config.nodeCount)])
|
|
3613
|
+
});
|
|
3614
|
+
printTable({
|
|
3615
|
+
columns: ["Storage ID", "Label", "Multiplier"],
|
|
3616
|
+
rows: response.catalog.storageTiers.map((tier) => [tier.id, tier.label, `${tier.priceMultiplier}x`])
|
|
3617
|
+
});
|
|
3618
|
+
printTable({
|
|
3619
|
+
columns: ["Size ID", "Label", "vCPU", "Memory GB"],
|
|
3620
|
+
rows: response.catalog.clusterSizes.map((size) => [
|
|
3621
|
+
size.id,
|
|
3622
|
+
size.label,
|
|
3623
|
+
String(size.vcpu),
|
|
3624
|
+
String(size.memoryGb)
|
|
3625
|
+
])
|
|
3626
|
+
});
|
|
3627
|
+
ge("Done");
|
|
3628
|
+
});
|
|
3629
|
+
database.command("create").description("Create a new database").argument("<database>", "Database name").option("-b, --base-url <url>", "Parix base URL").option("--provider <slug>", "Provider slug (for example: gcp, aws)").option("--region <code>", "Region code").option("--cluster-config-id <id>", "Cluster config id").option("--storage-tier-id <id>", "Storage tier id").option("--cluster-size-id <id>", "Cluster size id").option("--storage-gb <n>", "Storage size in GB").option("--json", "Print raw JSON").addHelpText("after", [
|
|
3630
|
+
"",
|
|
3631
|
+
"Examples:",
|
|
3632
|
+
" parix database create payments-ledger --provider gcp --region asia-southeast1",
|
|
3633
|
+
" parix database create payments-ledger --provider aws --region ap-southeast-1 --cluster-config-id config-single --cluster-size-id size-hx-5"
|
|
3634
|
+
].join(`
|
|
3635
|
+
`)).action(async (databaseName, options) => {
|
|
3636
|
+
const parsedStorageGb = options.storageGb ? Number.parseInt(options.storageGb, 10) : null;
|
|
3637
|
+
if (options.storageGb && (typeof parsedStorageGb !== "number" || !Number.isInteger(parsedStorageGb) || parsedStorageGb <= 0)) {
|
|
3638
|
+
throw new Error("--storage-gb must be a positive integer.");
|
|
3639
|
+
}
|
|
3640
|
+
const response = await requestApiJson({
|
|
3641
|
+
baseUrl: options.baseUrl,
|
|
3642
|
+
body: JSON.stringify({
|
|
3643
|
+
clusterConfigId: options.clusterConfigId,
|
|
3644
|
+
clusterSizeId: options.clusterSizeId,
|
|
3645
|
+
name: databaseName,
|
|
3646
|
+
provider: options.provider,
|
|
3647
|
+
region: options.region,
|
|
3648
|
+
selectedStorageGb: parsedStorageGb ?? undefined,
|
|
3649
|
+
storageTierId: options.storageTierId
|
|
3650
|
+
}),
|
|
3651
|
+
headers: {
|
|
3652
|
+
"content-type": "application/json"
|
|
3653
|
+
},
|
|
3654
|
+
method: "POST",
|
|
3655
|
+
path: "/api/v1/databases"
|
|
3656
|
+
});
|
|
3657
|
+
if (options.json) {
|
|
3658
|
+
printJson(response);
|
|
3659
|
+
return;
|
|
3660
|
+
}
|
|
3661
|
+
if (!response.success) {
|
|
3662
|
+
me([
|
|
3663
|
+
`Billing: ${response.billing?.message ?? response.message}`,
|
|
3664
|
+
`Checkout URL: ${response.billing?.checkoutUrl ?? "-"}`
|
|
3665
|
+
].join(`
|
|
3666
|
+
`), "Provisioning blocked");
|
|
3667
|
+
ge(response.message);
|
|
3668
|
+
return;
|
|
3669
|
+
}
|
|
3670
|
+
printKeyValues([
|
|
3671
|
+
["Database ID", response.database?.id ?? "-"],
|
|
3672
|
+
["Database Name", response.database?.name ?? databaseName],
|
|
3673
|
+
["Profile ID", response.profile?.id ?? "-"],
|
|
3674
|
+
["Profile status", response.profile?.status ?? "-"],
|
|
3675
|
+
["Provisioning", response.provisioning?.status ?? "-"],
|
|
3676
|
+
["Workflow ID", response.job?.workflowId ?? "-"]
|
|
3677
|
+
]);
|
|
3678
|
+
if (response.provisioning) {
|
|
3679
|
+
me([`Status: ${response.provisioning.status}`, `Message: ${response.provisioning.message ?? "-"}`].join(`
|
|
3680
|
+
`), "Provisioning");
|
|
3681
|
+
}
|
|
3682
|
+
ge(response.message);
|
|
3683
|
+
});
|
|
3684
|
+
database.command("list").description("List databases in the active organization").option("-b, --base-url <url>", "Parix base URL").option("--search <text>", "Filter database names").option("--limit <n>", "Maximum number of rows to return").option("--json", "Print raw JSON").addHelpText("after", [
|
|
3685
|
+
"",
|
|
3686
|
+
"Examples:",
|
|
3687
|
+
" parix database list",
|
|
3688
|
+
" parix database list --search payments",
|
|
3689
|
+
" parix database list --json"
|
|
3690
|
+
].join(`
|
|
3691
|
+
`)).action(async (options) => {
|
|
3692
|
+
const query = new URLSearchParams;
|
|
3693
|
+
if (options.search) {
|
|
3694
|
+
query.set("search", options.search);
|
|
3695
|
+
}
|
|
3696
|
+
if (options.limit) {
|
|
3697
|
+
query.set("limit", options.limit);
|
|
3698
|
+
}
|
|
3699
|
+
const suffix = query.size > 0 ? `?${query.toString()}` : "";
|
|
3700
|
+
const response = await requestApiJson({
|
|
3701
|
+
baseUrl: options.baseUrl,
|
|
3702
|
+
path: `/api/v1/databases${suffix}`
|
|
3703
|
+
});
|
|
3704
|
+
if (options.json) {
|
|
3705
|
+
printJson(response);
|
|
3706
|
+
return;
|
|
3707
|
+
}
|
|
3708
|
+
if (response.databases.length === 0) {
|
|
3709
|
+
ge("No databases found");
|
|
3710
|
+
return;
|
|
3711
|
+
}
|
|
3712
|
+
printTable({
|
|
3713
|
+
columns: ["ID", "Name", "Region", "Provider", "Status", "Updated"],
|
|
3714
|
+
rows: response.databases.map((database2) => [
|
|
3715
|
+
database2.id,
|
|
3716
|
+
database2.name,
|
|
3717
|
+
database2.region ?? "-",
|
|
3718
|
+
database2.provider ?? "-",
|
|
3719
|
+
database2.status,
|
|
3720
|
+
database2.updatedAt
|
|
3721
|
+
])
|
|
3722
|
+
});
|
|
3723
|
+
me(String(response.databases.length), "Databases");
|
|
3724
|
+
ge("Done");
|
|
3725
|
+
});
|
|
3726
|
+
database.command("info").description("Show database details").argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").addHelpText("after", ["", "Examples:", " parix database info db_123", " parix database info db_123 --json"].join(`
|
|
3727
|
+
`)).action(async (databaseId, options) => {
|
|
3728
|
+
const response = await requestApiJson({
|
|
3729
|
+
baseUrl: options.baseUrl,
|
|
3730
|
+
path: `/api/v1/databases/${encodeURIComponent(databaseId)}`
|
|
3731
|
+
});
|
|
3732
|
+
if (options.json) {
|
|
3733
|
+
printJson(response);
|
|
3734
|
+
return;
|
|
3735
|
+
}
|
|
3736
|
+
printKeyValues([
|
|
3737
|
+
["Database ID", response.database.id],
|
|
3738
|
+
["Database Name", response.database.name],
|
|
3739
|
+
["Provider", response.provider ?? "-"],
|
|
3740
|
+
["Region", response.region ?? "-"],
|
|
3741
|
+
["Gateway URL", response.gatewayUrl ?? "-"],
|
|
3742
|
+
["Status", response.decommissionState?.status ?? response.profile?.status ?? "-"],
|
|
3743
|
+
["Version", response.profile?.tigerbeetleCurrentVersion ?? response.profile?.tigerbeetleVersion ?? "-"],
|
|
3744
|
+
["Nodes", response.profile ? String(response.profile.selectedNodeCount) : "-"],
|
|
3745
|
+
["CPU", response.profile ? String(response.profile.selectedVcpu) : "-"],
|
|
3746
|
+
["Memory GB", response.profile ? String(response.profile.selectedMemoryGb) : "-"],
|
|
3747
|
+
["Storage GB", response.profile?.selectedStorageGb != null ? String(response.profile.selectedStorageGb) : "-"],
|
|
3748
|
+
["Updated", response.database.updatedAt]
|
|
3749
|
+
]);
|
|
3750
|
+
if (response.metricsSummary) {
|
|
3751
|
+
me([
|
|
3752
|
+
`CPU: ${response.metricsSummary.cpuUsagePct ?? "-"}%`,
|
|
3753
|
+
`Memory: ${response.metricsSummary.memoryUsagePct ?? "-"}%`,
|
|
3754
|
+
`Disk: ${response.metricsSummary.diskUsagePct ?? "-"}%`,
|
|
3755
|
+
`Gateway P95: ${response.metricsSummary.gatewayP95LatencyMs ?? "-"}ms`,
|
|
3756
|
+
`Last collected: ${response.metricsSummary.lastCollectedAt ?? "-"}`
|
|
3757
|
+
].join(`
|
|
3758
|
+
`), "Metrics");
|
|
3759
|
+
}
|
|
3760
|
+
if (response.latestProvisionJob) {
|
|
3761
|
+
me([
|
|
3762
|
+
`Provision job: ${response.latestProvisionJob.id}`,
|
|
3763
|
+
`Provision status: ${response.latestProvisionJob.status}`,
|
|
3764
|
+
`Workflow ID: ${response.latestProvisionJob.workflowId ?? "-"}`
|
|
3765
|
+
].join(`
|
|
3766
|
+
`), "Latest provision job");
|
|
3767
|
+
}
|
|
3768
|
+
ge("Done");
|
|
3769
|
+
});
|
|
3770
|
+
database.command("remove").description("Queue database deletion").argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").option("-y, --yes", "Skip confirmation prompt").addHelpText("after", ["", "Examples:", " parix database remove db_123", " parix database remove db_123 --yes --json"].join(`
|
|
3771
|
+
`)).action(async (databaseId, options) => {
|
|
3772
|
+
if (!options.yes) {
|
|
3773
|
+
const confirmed = await ce({
|
|
3774
|
+
message: `Queue deletion for ${databaseId}?`
|
|
3775
|
+
});
|
|
3776
|
+
if (lD(confirmed) || !confirmed) {
|
|
3777
|
+
ge("Cancelled");
|
|
3778
|
+
return;
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
const response = await requestApiJson({
|
|
3782
|
+
baseUrl: options.baseUrl,
|
|
3783
|
+
method: "DELETE",
|
|
3784
|
+
path: `/api/v1/databases/${encodeURIComponent(databaseId)}`
|
|
3785
|
+
});
|
|
3786
|
+
if (options.json) {
|
|
3787
|
+
printJson(response);
|
|
3788
|
+
return;
|
|
3789
|
+
}
|
|
3790
|
+
printKeyValues([
|
|
3791
|
+
["Database ID", response.databaseId],
|
|
3792
|
+
["Status", response.status],
|
|
3793
|
+
["Workflow ID", response.workflowId]
|
|
3794
|
+
]);
|
|
3795
|
+
ge(response.message);
|
|
3796
|
+
});
|
|
3797
|
+
return database;
|
|
3798
|
+
}
|
|
3799
|
+
|
|
3800
|
+
// src/commands/skill-content.ts
|
|
3801
|
+
var PARIX_AGENT_SKILL = [
|
|
3802
|
+
"---",
|
|
3803
|
+
"name: parix",
|
|
3804
|
+
'description: "Operate Parix through the `parix` CLI: inspect authentication and active organization context, manage database lifecycle, call authenticated Parix API endpoints, and run TigerBeetle queries or mutations. Use for Parix CLI setup, sessions, database catalog/list/info/create/remove work, Parix API requests, and TigerBeetle account or transfer operations."',
|
|
3805
|
+
"---",
|
|
3806
|
+
"",
|
|
3807
|
+
"# Parix CLI",
|
|
3808
|
+
"",
|
|
3809
|
+
"Use the installed `parix` binary. Prefer scoped `--help` over guessing flags.",
|
|
3810
|
+
"",
|
|
3811
|
+
"## Start safely",
|
|
3812
|
+
"",
|
|
3813
|
+
"1. Run `command -v parix`. If it is absent, ask the user to install it with `npm install -g @parix/cli`.",
|
|
3814
|
+
"2. Run `parix auth status` before authenticated work. Confirm the base URL and active organization before any mutation. Status may refresh and persist tokens or organization context, so it is not strictly read-only. If no usable session exists, ask the user to complete `parix auth login`; login opens a browser OAuth flow.",
|
|
3815
|
+
"3. Treat `https://parix.io` as production. Login resolves its target as explicit `--base-url`, then `PARIX_BASE_URL`, then production; it ignores any URL in the stored session. Later commands resolve explicit URL, then stored URL, then environment, then production. Pass `--base-url <url>` explicitly when the environment matters.",
|
|
3816
|
+
"4. Use `parix database`, not `parix db`; no `db` alias exists.",
|
|
3817
|
+
"",
|
|
3818
|
+
"Never read or print `~/.config/parix/session.json`; it contains access and refresh tokens.",
|
|
3819
|
+
"",
|
|
3820
|
+
"`parix auth logout` deletes the local session without confirmation; run it only when explicitly requested.",
|
|
3821
|
+
"",
|
|
3822
|
+
"## Discover before changing state",
|
|
3823
|
+
"",
|
|
3824
|
+
"```bash",
|
|
3825
|
+
"parix database catalog",
|
|
3826
|
+
"parix database list",
|
|
3827
|
+
"parix database info <database-id>",
|
|
3828
|
+
"parix database <command> --help",
|
|
3829
|
+
"parix tb <command> --help",
|
|
3830
|
+
"```",
|
|
3831
|
+
"",
|
|
3832
|
+
"Database and TigerBeetle commands operate in the active organization from the current session. Stop if that organization or target environment is not the intended one.",
|
|
3833
|
+
"",
|
|
3834
|
+
"Use `--json` when a database or TigerBeetle command needs the complete response, but do not assume it is directly pipeable to `jq`: current output is wrapped by Clack formatting.",
|
|
3835
|
+
"",
|
|
3836
|
+
"## Manage databases",
|
|
3837
|
+
"",
|
|
3838
|
+
"- Run `parix database catalog` before creation and use provider, region, cluster, size, and storage identifiers returned by it.",
|
|
3839
|
+
"- Treat `parix database create` as potentially billable. Run it only when the user explicitly requests the exact resource. `--storage-gb` must be a positive integer.",
|
|
3840
|
+
"- Inspect the create response, including `success`, billing, and provisioning fields; exit code 0 alone does not prove provisioning started. Only when `success` is true and a database ID is returned, follow with `parix database info <database-id>`.",
|
|
3841
|
+
"- Treat `parix database remove <database-id>` as destructive. Resolve the exact ID, obtain explicit confirmation, and only then use `--yes` for a non-interactive run. Removal is queued; verify the returned workflow/status rather than claiming immediate deletion.",
|
|
3842
|
+
"",
|
|
3843
|
+
"## Run TigerBeetle operations",
|
|
3844
|
+
"",
|
|
3845
|
+
"Read operations are `lookup-accounts`, `lookup-transfers`, `get-account-transfers`, `get-account-balances`, `query-accounts`, and `query-transfers`. `create-accounts` and `create-transfers` mutate data; run them only when explicitly requested.",
|
|
3846
|
+
"",
|
|
3847
|
+
"Choose exactly one payload style:",
|
|
3848
|
+
"",
|
|
3849
|
+
"- flags for a single/common operation;",
|
|
3850
|
+
"- `--payload '<json>'` for raw JSON; or",
|
|
3851
|
+
"- `--file <path>` for a JSON file.",
|
|
3852
|
+
"",
|
|
3853
|
+
"`--file` takes precedence over `--payload`, and either raw form bypasses flag-built payloads, defaults, and validation. Flag-built account creation requires `--ledger` and `--code`. Ordinary transfer creation requires `--from`, `--to`, `--amount`, `--ledger`, and `--code`. Post-pending transfer creation requires `--flag post_pending_transfer`, `--pending-id`, and `--amount`; debit/credit IDs, ledger, and code may be omitted to inherit them. Void-pending transfer creation requires `--flag void_pending_transfer` and `--pending-id`; amount and the same inherited fields may be omitted. Imported accounts and transfers also require `--timestamp` in nanoseconds, greater than 0 and less than 2^63; nonzero `--timeout` values are in seconds and limited to non-imported pending transfers. Linked batches require `--payload` or `--file`.",
|
|
3854
|
+
"",
|
|
3855
|
+
"Supply stable explicit `--id` values for retryable mutations; omitted IDs are newly generated on each run. Flag-built queries and account filters default to `--limit 100`.",
|
|
3856
|
+
"",
|
|
3857
|
+
"Newly provisioned databases may not be ready immediately. Check `parix database info` and retry read-only readiness checks before TigerBeetle mutations.",
|
|
3858
|
+
"",
|
|
3859
|
+
"## Call the authenticated API",
|
|
3860
|
+
"",
|
|
3861
|
+
"```bash",
|
|
3862
|
+
"parix api /api/v1/session",
|
|
3863
|
+
`parix api /api/v1/example -X POST -d '{"key":"value"}'`,
|
|
3864
|
+
"```",
|
|
3865
|
+
"",
|
|
3866
|
+
"Prefer relative `/api/...` paths. An absolute HTTP(S) URL also receives the stored bearer token, so use one only when the user explicitly trusts that host. Repeat `-H 'name:value'` for headers; a body defaults to `content-type: application/json` unless overridden.",
|
|
3867
|
+
"",
|
|
3868
|
+
"Always inspect the printed HTTP status. `parix api` and `parix tb` set a non-zero exit code on HTTP 4xx/5xx; still read the body for `detail` and `tbResults`.",
|
|
3869
|
+
"",
|
|
3870
|
+
"## Verify outcomes",
|
|
3871
|
+
"",
|
|
3872
|
+
"Report the target base URL and organization, the exact command class used, the response status/body, and any asynchronous provisioning or deletion state. Do not infer success from process exit alone.",
|
|
3873
|
+
""
|
|
3874
|
+
].join(`
|
|
3875
|
+
`);
|
|
3876
|
+
|
|
3877
|
+
// src/commands/skill.ts
|
|
3878
|
+
function createSkillCommand() {
|
|
3879
|
+
return new Command("skill").description("Print the agent skill file to stdout").action(() => {
|
|
3880
|
+
process.stdout.write(PARIX_AGENT_SKILL);
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
// src/lib/tb-payloads.ts
|
|
3885
|
+
var import_promises2 = require("node:fs/promises");
|
|
3886
|
+
var SPLIT_IDS_REGEX = /[\s,]+/;
|
|
3887
|
+
var DECIMAL_INTEGER_REGEX = /^\d+$/;
|
|
3888
|
+
var LINKED_FLAG = 1n;
|
|
3889
|
+
var ACCOUNT_IMPORTED_FLAG = 16n;
|
|
3890
|
+
var TRANSFER_PENDING_FLAG = 2n;
|
|
3891
|
+
var TRANSFER_POST_PENDING_FLAG = 4n;
|
|
3892
|
+
var TRANSFER_VOID_PENDING_FLAG = 8n;
|
|
3893
|
+
var TRANSFER_IMPORTED_FLAG = 256n;
|
|
3894
|
+
var TIGERBEETLE_TIMESTAMP_MAX_EXCLUSIVE = 1n << 63n;
|
|
3895
|
+
var IMPORTED_TIMESTAMP_ERROR = "--timestamp must be a decimal integer greater than 0 and less than 2^63 when --flag imported is used.";
|
|
3896
|
+
var ACCOUNT_FLAG_SET = {
|
|
3897
|
+
allowedMask: 63n,
|
|
3898
|
+
label: "account",
|
|
3899
|
+
nameToBit: new Map([
|
|
3900
|
+
["linked", LINKED_FLAG],
|
|
3901
|
+
["debits_must_not_exceed_credits", 2n],
|
|
3902
|
+
["credits_must_not_exceed_debits", 4n],
|
|
3903
|
+
["history", 8n],
|
|
3904
|
+
["imported", ACCOUNT_IMPORTED_FLAG],
|
|
3905
|
+
["closed", 32n]
|
|
3906
|
+
])
|
|
3907
|
+
};
|
|
3908
|
+
var TRANSFER_FLAG_SET = {
|
|
3909
|
+
allowedMask: 511n,
|
|
3910
|
+
label: "transfer",
|
|
3911
|
+
nameToBit: new Map([
|
|
3912
|
+
["linked", LINKED_FLAG],
|
|
3913
|
+
["pending", TRANSFER_PENDING_FLAG],
|
|
3914
|
+
["post_pending_transfer", TRANSFER_POST_PENDING_FLAG],
|
|
3915
|
+
["void_pending_transfer", TRANSFER_VOID_PENDING_FLAG],
|
|
3916
|
+
["balancing_debit", 16n],
|
|
3917
|
+
["balancing_credit", 32n],
|
|
3918
|
+
["closing_debit", 64n],
|
|
3919
|
+
["closing_credit", 128n],
|
|
3920
|
+
["imported", TRANSFER_IMPORTED_FLAG]
|
|
3921
|
+
])
|
|
3922
|
+
};
|
|
3923
|
+
var ACCOUNT_FILTER_FLAG_SET = {
|
|
3924
|
+
allowedMask: 7n,
|
|
3925
|
+
label: "account filter",
|
|
3926
|
+
nameToBit: new Map([
|
|
3927
|
+
["debits", 1n],
|
|
3928
|
+
["credits", 2n],
|
|
3929
|
+
["reversed", 4n]
|
|
3930
|
+
])
|
|
3931
|
+
};
|
|
3932
|
+
var QUERY_FILTER_FLAG_SET = {
|
|
3933
|
+
allowedMask: 1n,
|
|
3934
|
+
label: "query filter",
|
|
3935
|
+
nameToBit: new Map([["reversed", 1n]])
|
|
3936
|
+
};
|
|
3937
|
+
async function resolveTbPayload(options, buildFromFlags) {
|
|
3938
|
+
if (options.file) {
|
|
3939
|
+
return JSON.parse(await import_promises2.readFile(options.file, "utf8"));
|
|
3940
|
+
}
|
|
3941
|
+
if (options.payload) {
|
|
3942
|
+
return JSON.parse(options.payload);
|
|
3943
|
+
}
|
|
3944
|
+
return buildFromFlags();
|
|
3945
|
+
}
|
|
3946
|
+
function buildCreateAccountsPayload(options) {
|
|
3947
|
+
const flags = flagsBitfield(options.flags, ACCOUNT_FLAG_SET);
|
|
3948
|
+
rejectLinkedSingleEvent(flags);
|
|
3949
|
+
const isImported = flagIsSet(flags, ACCOUNT_IMPORTED_FLAG);
|
|
3950
|
+
if (!isImported && valueIsNonZero(options.timestamp)) {
|
|
3951
|
+
throw new Error("--timestamp requires --flag imported when nonzero.");
|
|
3952
|
+
}
|
|
3953
|
+
return [
|
|
3954
|
+
omitEmpty({
|
|
3955
|
+
code: requiredValue(options.code, "--code"),
|
|
3956
|
+
flags,
|
|
3957
|
+
id: options.id ?? randomTbId(),
|
|
3958
|
+
ledger: requiredValue(options.ledger, "--ledger"),
|
|
3959
|
+
timestamp: isImported ? requiredImportedTimestamp(options.timestamp) : options.timestamp,
|
|
3960
|
+
user_data_128: options.userData128,
|
|
3961
|
+
user_data_32: options.userData32,
|
|
3962
|
+
user_data_64: options.userData64
|
|
3963
|
+
})
|
|
3964
|
+
];
|
|
3965
|
+
}
|
|
3966
|
+
function buildCreateTransfersPayload(options) {
|
|
3967
|
+
const flags = flagsBitfield(options.flags, TRANSFER_FLAG_SET);
|
|
3968
|
+
rejectLinkedSingleEvent(flags);
|
|
3969
|
+
const isPending = flagIsSet(flags, TRANSFER_PENDING_FLAG);
|
|
3970
|
+
const isPostPending = flagIsSet(flags, TRANSFER_POST_PENDING_FLAG);
|
|
3971
|
+
const isVoidPending = flagIsSet(flags, TRANSFER_VOID_PENDING_FLAG);
|
|
3972
|
+
const isImported = flagIsSet(flags, TRANSFER_IMPORTED_FLAG);
|
|
3973
|
+
const lifecycleModeCount = Number(isPending) + Number(isPostPending) + Number(isVoidPending);
|
|
3974
|
+
if (lifecycleModeCount > 1) {
|
|
3975
|
+
throw new Error("The pending, post_pending_transfer, and void_pending_transfer flags cannot be combined.");
|
|
3976
|
+
}
|
|
3977
|
+
const resolvesPending = isPostPending || isVoidPending;
|
|
3978
|
+
if (!isImported && valueIsNonZero(options.timestamp)) {
|
|
3979
|
+
throw new Error("--timestamp requires --flag imported when nonzero.");
|
|
3980
|
+
}
|
|
3981
|
+
if (valueIsNonZero(options.timeout)) {
|
|
3982
|
+
if (isImported) {
|
|
3983
|
+
throw new Error("--timeout must be zero or omitted with --flag imported.");
|
|
3984
|
+
}
|
|
3985
|
+
if (!isPending) {
|
|
3986
|
+
throw new Error("--timeout requires --flag pending when nonzero.");
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
if (!resolvesPending && valueIsNonZero(options.pendingId)) {
|
|
3990
|
+
throw new Error("--pending-id requires --flag post_pending_transfer or --flag void_pending_transfer when nonzero.");
|
|
3991
|
+
}
|
|
3992
|
+
return [
|
|
3993
|
+
omitEmpty({
|
|
3994
|
+
amount: isVoidPending ? valueOrZero(options.amount) : requiredValue(options.amount, "--amount"),
|
|
3995
|
+
code: resolvesPending ? valueOrZero(options.code) : requiredValue(options.code, "--code"),
|
|
3996
|
+
credit_account_id: resolvesPending ? valueOrZero(options.creditAccountId) : requiredValue(options.creditAccountId, "--to"),
|
|
3997
|
+
debit_account_id: resolvesPending ? valueOrZero(options.debitAccountId) : requiredValue(options.debitAccountId, "--from"),
|
|
3998
|
+
flags,
|
|
3999
|
+
id: options.id ?? randomTbId(),
|
|
4000
|
+
ledger: resolvesPending ? valueOrZero(options.ledger) : requiredValue(options.ledger, "--ledger"),
|
|
4001
|
+
pending_id: resolvesPending ? requiredValue(options.pendingId, "--pending-id") : options.pendingId,
|
|
4002
|
+
timestamp: isImported ? requiredImportedTimestamp(options.timestamp) : options.timestamp,
|
|
4003
|
+
timeout: options.timeout,
|
|
4004
|
+
user_data_128: options.userData128,
|
|
4005
|
+
user_data_32: options.userData32,
|
|
4006
|
+
user_data_64: options.userData64
|
|
4007
|
+
})
|
|
4008
|
+
];
|
|
4009
|
+
}
|
|
4010
|
+
function buildLookupPayload(options) {
|
|
4011
|
+
const ids = [...options.id ?? [], ...splitIds(options.ids)];
|
|
4012
|
+
if (ids.length === 0) {
|
|
4013
|
+
throw new Error("Provide at least one `--id` or `--ids` value.");
|
|
4014
|
+
}
|
|
4015
|
+
return ids;
|
|
4016
|
+
}
|
|
4017
|
+
function buildAccountFilterPayload(options) {
|
|
4018
|
+
return omitEmpty({
|
|
4019
|
+
account_id: requiredValue(options.accountId, "--account-id"),
|
|
4020
|
+
code: options.code,
|
|
4021
|
+
flags: flagsBitfield(options.flags, ACCOUNT_FILTER_FLAG_SET),
|
|
4022
|
+
limit: requiredValue(options.limit, "--limit"),
|
|
4023
|
+
timestamp_max: options.timestampMax,
|
|
4024
|
+
timestamp_min: options.timestampMin,
|
|
4025
|
+
user_data_128: options.userData128,
|
|
4026
|
+
user_data_32: options.userData32,
|
|
4027
|
+
user_data_64: options.userData64
|
|
4028
|
+
});
|
|
4029
|
+
}
|
|
4030
|
+
function buildQueryPayload(options) {
|
|
4031
|
+
return omitEmpty({
|
|
4032
|
+
code: options.code,
|
|
4033
|
+
flags: flagsBitfield(options.flags, QUERY_FILTER_FLAG_SET),
|
|
4034
|
+
ledger: options.ledger,
|
|
4035
|
+
limit: requiredValue(options.limit, "--limit"),
|
|
4036
|
+
timestamp_max: options.timestampMax,
|
|
4037
|
+
timestamp_min: options.timestampMin,
|
|
4038
|
+
user_data_128: options.userData128,
|
|
4039
|
+
user_data_32: options.userData32,
|
|
4040
|
+
user_data_64: options.userData64
|
|
4041
|
+
});
|
|
4042
|
+
}
|
|
4043
|
+
function flagsBitfield(flags, flagSet) {
|
|
4044
|
+
if (!flags || flags.length === 0) {
|
|
4045
|
+
return "0";
|
|
4046
|
+
}
|
|
4047
|
+
let bitfield = 0n;
|
|
4048
|
+
for (const flag of flags) {
|
|
4049
|
+
const normalized = flag.trim();
|
|
4050
|
+
if (!normalized) {
|
|
4051
|
+
continue;
|
|
4052
|
+
}
|
|
4053
|
+
if (DECIMAL_INTEGER_REGEX.test(normalized)) {
|
|
4054
|
+
const direct = BigInt(normalized);
|
|
4055
|
+
if ((direct & ~flagSet.allowedMask) !== 0n) {
|
|
4056
|
+
throw new Error(`Unsupported ${flagSet.label} flag bitfield: ${flag}`);
|
|
4057
|
+
}
|
|
4058
|
+
bitfield |= direct;
|
|
4059
|
+
continue;
|
|
4060
|
+
}
|
|
4061
|
+
const bit = flagSet.nameToBit.get(normalized);
|
|
4062
|
+
if (bit === undefined) {
|
|
4063
|
+
throw new Error(`Unsupported ${flagSet.label} flag: ${flag}`);
|
|
4064
|
+
}
|
|
4065
|
+
bitfield |= bit;
|
|
4066
|
+
}
|
|
4067
|
+
return bitfield.toString();
|
|
4068
|
+
}
|
|
4069
|
+
function flagIsSet(flags, flag) {
|
|
4070
|
+
return (BigInt(flags) & flag) !== 0n;
|
|
4071
|
+
}
|
|
4072
|
+
function rejectLinkedSingleEvent(flags) {
|
|
4073
|
+
if (flagIsSet(flags, LINKED_FLAG)) {
|
|
4074
|
+
throw new Error("--flag linked requires --payload or --file with a batch of events.");
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
function omitEmpty(input) {
|
|
4078
|
+
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined && value.trim().length > 0));
|
|
4079
|
+
}
|
|
4080
|
+
function randomTbId() {
|
|
4081
|
+
return BigInt(`0x${crypto.getRandomValues(new Uint8Array(16)).reduce((value, byte) => value + byte.toString(16).padStart(2, "0"), "")}`).toString();
|
|
4082
|
+
}
|
|
4083
|
+
function requiredValue(value, flagName) {
|
|
4084
|
+
if (!value || value.trim().length === 0) {
|
|
4085
|
+
throw new Error(`${flagName} is required unless --payload or --file is used.`);
|
|
4086
|
+
}
|
|
4087
|
+
return value.trim();
|
|
4088
|
+
}
|
|
4089
|
+
function requiredImportedTimestamp(value) {
|
|
4090
|
+
const timestamp = requiredValue(value, "--timestamp");
|
|
4091
|
+
if (!DECIMAL_INTEGER_REGEX.test(timestamp)) {
|
|
4092
|
+
throw new Error(IMPORTED_TIMESTAMP_ERROR);
|
|
4093
|
+
}
|
|
4094
|
+
const parsed = BigInt(timestamp);
|
|
4095
|
+
if (parsed === 0n || parsed >= TIGERBEETLE_TIMESTAMP_MAX_EXCLUSIVE) {
|
|
4096
|
+
throw new Error(IMPORTED_TIMESTAMP_ERROR);
|
|
4097
|
+
}
|
|
4098
|
+
return timestamp;
|
|
4099
|
+
}
|
|
4100
|
+
function valueOrZero(value) {
|
|
4101
|
+
const trimmed = value?.trim();
|
|
4102
|
+
return trimmed || "0";
|
|
4103
|
+
}
|
|
4104
|
+
function valueIsNonZero(value) {
|
|
4105
|
+
const trimmed = value?.trim();
|
|
4106
|
+
if (!trimmed) {
|
|
4107
|
+
return false;
|
|
4108
|
+
}
|
|
4109
|
+
return !DECIMAL_INTEGER_REGEX.test(trimmed) || BigInt(trimmed) !== 0n;
|
|
4110
|
+
}
|
|
4111
|
+
function splitIds(value) {
|
|
4112
|
+
if (!value) {
|
|
4113
|
+
return [];
|
|
4114
|
+
}
|
|
4115
|
+
return value.split(SPLIT_IDS_REGEX).map((item) => item.trim()).filter(Boolean);
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
// src/commands/tb.ts
|
|
4119
|
+
function createTbCommand() {
|
|
4120
|
+
const tb = new Command("tb").description("Run TigerBeetle operations against a database").addHelpText("after", [
|
|
4121
|
+
"",
|
|
4122
|
+
"Examples:",
|
|
4123
|
+
" parix tb create-accounts db_123 --id 1000 --ledger 1 --code 1",
|
|
4124
|
+
" parix tb create-transfers db_123 --id 2000 --from 1000 --to 1001 --amount 1 --ledger 1 --code 1",
|
|
4125
|
+
" parix tb lookup-accounts db_123 --id 1000 --id 1001",
|
|
4126
|
+
" parix tb query-transfers db_123 --limit 10 --json",
|
|
4127
|
+
" parix tb create-transfers db_123 --file ./transfer.json"
|
|
4128
|
+
].join(`
|
|
4129
|
+
`));
|
|
4130
|
+
addCreateAccountsCommand(tb);
|
|
4131
|
+
addCreateTransfersCommand(tb);
|
|
4132
|
+
addLookupCommand(tb, "lookup-accounts", "lookup_accounts", "Lookup accounts");
|
|
4133
|
+
addLookupCommand(tb, "lookup-transfers", "lookup_transfers", "Lookup transfers");
|
|
4134
|
+
addAccountFilterCommand(tb, "get-account-transfers", "get_account_transfers", "Get account transfers");
|
|
4135
|
+
addAccountFilterCommand(tb, "get-account-balances", "get_account_balances", "Get account balances");
|
|
4136
|
+
addQueryCommand(tb, "query-accounts", "query_accounts", "Query accounts");
|
|
4137
|
+
addQueryCommand(tb, "query-transfers", "query_transfers", "Query transfers");
|
|
4138
|
+
return tb;
|
|
4139
|
+
}
|
|
4140
|
+
function addCreateAccountsCommand(parent) {
|
|
4141
|
+
parent.command("create-accounts").description("Create TigerBeetle accounts").argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").option("--payload <json>", "Raw JSON payload override").option("--file <path>", "Read JSON payload from file").option("--id <id>", "Account id (defaults to generated id)").option("--ledger <ledger>", "Ledger id").option("--code <code>", "Account code").option("--flag <flag>", "Account flag name or bitfield value", collectValues2, []).option("--timestamp <nanoseconds>", "Imported timestamp, greater than 0 and less than 2^63").option("--user-data-128 <value>", "user_data_128").option("--user-data-64 <value>", "user_data_64").option("--user-data-32 <value>", "user_data_32").addHelpText("after", [
|
|
4142
|
+
"",
|
|
4143
|
+
"Examples:",
|
|
4144
|
+
" parix tb create-accounts db_123 --id 1000 --ledger 1 --code 1",
|
|
4145
|
+
' parix tb create-accounts db_123 --payload "[{"id":"1000","ledger":"1","code":"1","flags":"0"}]"'
|
|
4146
|
+
].join(`
|
|
4147
|
+
`)).action(async (databaseId, options) => {
|
|
4148
|
+
const payload = await resolveTbPayload(options, () => buildCreateAccountsPayload({
|
|
4149
|
+
code: options.code,
|
|
4150
|
+
flags: options.flag,
|
|
4151
|
+
id: options.id,
|
|
4152
|
+
ledger: options.ledger,
|
|
4153
|
+
timestamp: options.timestamp,
|
|
4154
|
+
userData128: options.userData128,
|
|
4155
|
+
userData32: options.userData32,
|
|
4156
|
+
userData64: options.userData64
|
|
4157
|
+
}));
|
|
4158
|
+
await executeTbOperation(databaseId, "create_accounts", payload, options);
|
|
4159
|
+
});
|
|
4160
|
+
}
|
|
4161
|
+
function addCreateTransfersCommand(parent) {
|
|
4162
|
+
parent.command("create-transfers").description("Create TigerBeetle transfers").argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").option("--payload <json>", "Raw JSON payload override").option("--file <path>", "Read JSON payload from file").option("--id <id>", "Transfer id (defaults to generated id)").option("--from <id>", "Debit account id").option("--to <id>", "Credit account id").option("--amount <amount>", "Transfer amount").option("--ledger <ledger>", "Ledger id").option("--code <code>", "Transfer code").option("--flag <flag>", "Transfer flag name or bitfield value", collectValues2, []).option("--pending-id <id>", "Pending transfer id").option("--timeout <seconds>", "Pending transfer timeout in seconds").option("--timestamp <nanoseconds>", "Imported timestamp, greater than 0 and less than 2^63").option("--user-data-128 <value>", "user_data_128").option("--user-data-64 <value>", "user_data_64").option("--user-data-32 <value>", "user_data_32").addHelpText("after", [
|
|
4163
|
+
"",
|
|
4164
|
+
"Examples:",
|
|
4165
|
+
" parix tb create-transfers db_123 --id 2000 --from 1000 --to 1001 --amount 1 --ledger 1 --code 1",
|
|
4166
|
+
" parix tb create-transfers db_123 --id 2001 --pending-id 2000 --amount 25 --flag post_pending_transfer",
|
|
4167
|
+
" parix tb create-transfers db_123 --id 2001 --pending-id 2000 --flag void_pending_transfer",
|
|
4168
|
+
" parix tb create-transfers db_123 --file ./transfer.json"
|
|
4169
|
+
].join(`
|
|
4170
|
+
`)).action(async (databaseId, options) => {
|
|
4171
|
+
const payload = await resolveTbPayload(options, () => buildCreateTransfersPayload({
|
|
4172
|
+
amount: options.amount,
|
|
4173
|
+
code: options.code,
|
|
4174
|
+
creditAccountId: options.to,
|
|
4175
|
+
debitAccountId: options.from,
|
|
4176
|
+
flags: options.flag,
|
|
4177
|
+
id: options.id,
|
|
4178
|
+
ledger: options.ledger,
|
|
4179
|
+
pendingId: options.pendingId,
|
|
4180
|
+
timestamp: options.timestamp,
|
|
4181
|
+
timeout: options.timeout,
|
|
4182
|
+
userData128: options.userData128,
|
|
4183
|
+
userData32: options.userData32,
|
|
4184
|
+
userData64: options.userData64
|
|
4185
|
+
}));
|
|
4186
|
+
await executeTbOperation(databaseId, "create_transfers", payload, options);
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
function addLookupCommand(parent, name, operation, description) {
|
|
4190
|
+
parent.command(name).description(description).argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").option("--payload <json>", "Raw JSON payload override").option("--file <path>", "Read JSON payload from file").option("--id <id>", "ID to lookup", collectValues2, []).option("--ids <ids>", "Comma-separated IDs to lookup").addHelpText("after", [
|
|
4191
|
+
"",
|
|
4192
|
+
"Examples:",
|
|
4193
|
+
` parix tb ${name} db_123 --id 1000 --id 1001`,
|
|
4194
|
+
` parix tb ${name} db_123 --ids 1000,1001`
|
|
4195
|
+
].join(`
|
|
4196
|
+
`)).action(async (databaseId, options) => {
|
|
4197
|
+
const payload = await resolveTbPayload(options, () => buildLookupPayload({
|
|
4198
|
+
id: options.id,
|
|
4199
|
+
ids: options.ids
|
|
4200
|
+
}));
|
|
4201
|
+
await executeTbOperation(databaseId, operation, payload, options);
|
|
4202
|
+
});
|
|
4203
|
+
}
|
|
4204
|
+
function addAccountFilterCommand(parent, name, operation, description) {
|
|
4205
|
+
parent.command(name).description(description).argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").option("--payload <json>", "Raw JSON payload override").option("--file <path>", "Read JSON payload from file").option("--account-id <id>", "Account id").option("--limit <limit>", "Maximum row count", "100").option("--flag <flag>", "Filter flag name or bitfield value", collectValues2, []).option("--timestamp-min <value>", "Minimum timestamp").option("--timestamp-max <value>", "Maximum timestamp").option("--user-data-128 <value>", "user_data_128").option("--user-data-64 <value>", "user_data_64").option("--user-data-32 <value>", "user_data_32").option("--code <code>", "Filter code").addHelpText("after", [
|
|
4206
|
+
"",
|
|
4207
|
+
"Examples:",
|
|
4208
|
+
` parix tb ${name} db_123 --account-id 1000 --limit 10 --flag debits`,
|
|
4209
|
+
` parix tb ${name} db_123 --file ./filter.json`
|
|
4210
|
+
].join(`
|
|
4211
|
+
`)).action(async (databaseId, options) => {
|
|
4212
|
+
const payload = await resolveTbPayload(options, () => buildAccountFilterPayload({
|
|
4213
|
+
accountId: options.accountId,
|
|
4214
|
+
code: options.code,
|
|
4215
|
+
flags: options.flag,
|
|
4216
|
+
limit: options.limit,
|
|
4217
|
+
timestampMax: options.timestampMax,
|
|
4218
|
+
timestampMin: options.timestampMin,
|
|
4219
|
+
userData128: options.userData128,
|
|
4220
|
+
userData32: options.userData32,
|
|
4221
|
+
userData64: options.userData64
|
|
4222
|
+
}));
|
|
4223
|
+
await executeTbOperation(databaseId, operation, payload, options);
|
|
4224
|
+
});
|
|
4225
|
+
}
|
|
4226
|
+
function addQueryCommand(parent, name, operation, description) {
|
|
4227
|
+
parent.command(name).description(description).argument("<database-id>", "Database id").option("-b, --base-url <url>", "Parix base URL").option("--json", "Print raw JSON").option("--payload <json>", "Raw JSON payload override").option("--file <path>", "Read JSON payload from file").option("--limit <limit>", "Maximum row count", "100").option("--flag <flag>", "Query flag name or bitfield value", collectValues2, []).option("--ledger <ledger>", "Filter ledger").option("--code <code>", "Filter code").option("--timestamp-min <value>", "Minimum timestamp").option("--timestamp-max <value>", "Maximum timestamp").option("--user-data-128 <value>", "user_data_128").option("--user-data-64 <value>", "user_data_64").option("--user-data-32 <value>", "user_data_32").addHelpText("after", [
|
|
4228
|
+
"",
|
|
4229
|
+
"Examples:",
|
|
4230
|
+
` parix tb ${name} db_123 --limit 10`,
|
|
4231
|
+
` parix tb ${name} db_123 --ledger 1 --limit 10 --json`
|
|
4232
|
+
].join(`
|
|
4233
|
+
`)).action(async (databaseId, options) => {
|
|
4234
|
+
const payload = await resolveTbPayload(options, () => buildQueryPayload({
|
|
4235
|
+
code: options.code,
|
|
4236
|
+
flags: options.flag,
|
|
4237
|
+
ledger: options.ledger,
|
|
4238
|
+
limit: options.limit,
|
|
4239
|
+
timestampMax: options.timestampMax,
|
|
4240
|
+
timestampMin: options.timestampMin,
|
|
4241
|
+
userData128: options.userData128,
|
|
4242
|
+
userData32: options.userData32,
|
|
4243
|
+
userData64: options.userData64
|
|
4244
|
+
}));
|
|
4245
|
+
await executeTbOperation(databaseId, operation, payload, options);
|
|
4246
|
+
});
|
|
4247
|
+
}
|
|
4248
|
+
async function executeTbOperation(databaseId, operation, payload, options) {
|
|
4249
|
+
const response = await requestApiJson({
|
|
4250
|
+
baseUrl: options.baseUrl,
|
|
4251
|
+
body: JSON.stringify(payload),
|
|
4252
|
+
headers: {
|
|
4253
|
+
"content-type": "application/json"
|
|
4254
|
+
},
|
|
4255
|
+
method: "POST",
|
|
4256
|
+
path: `/api/v1/databases/${encodeURIComponent(databaseId)}/tb/${operation}`
|
|
4257
|
+
});
|
|
4258
|
+
if (options.json) {
|
|
4259
|
+
printJson(response);
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
me(response.docsUrl, "TigerBeetle docs");
|
|
4263
|
+
me([
|
|
4264
|
+
`Operation: ${response.operationLabel}`,
|
|
4265
|
+
`Database: ${response.databaseName}`,
|
|
4266
|
+
`Provider: ${response.provider}`,
|
|
4267
|
+
`Cluster ID: ${response.clusterId}`,
|
|
4268
|
+
`Target host: ${response.targetHost}`,
|
|
4269
|
+
`Replicas: ${String(response.replicaCount)}`,
|
|
4270
|
+
`Mode: ${response.mode}`,
|
|
4271
|
+
`Persisted: ${String(response.persisted)}`
|
|
4272
|
+
].join(`
|
|
4273
|
+
`), "Execution");
|
|
4274
|
+
if (Array.isArray(response.responsePayload)) {
|
|
4275
|
+
me(String(response.responsePayload.length), "Rows returned");
|
|
4276
|
+
}
|
|
4277
|
+
printJson(response.responsePayload);
|
|
4278
|
+
ge(response.message);
|
|
4279
|
+
}
|
|
4280
|
+
function collectValues2(value, previous) {
|
|
4281
|
+
previous.push(value);
|
|
4282
|
+
return previous;
|
|
4283
|
+
}
|
|
4284
|
+
|
|
4285
|
+
// src/cli.ts
|
|
4286
|
+
var loadPackageJson = import_node_module.createRequire("file:///home/runner/work/cli/cli/src/cli.ts");
|
|
4287
|
+
var packageJson = loadPackageJson("../package.json");
|
|
4288
|
+
async function main() {
|
|
4289
|
+
const program2 = new Command;
|
|
4290
|
+
program2.name("parix").version(packageJson.version, "-v, --version").description("Parix command line interface").showHelpAfterError().addCommand(createAuthCommand()).addCommand(createApiCommand()).addCommand(createDatabaseCommand()).addCommand(createSkillCommand()).addCommand(createTbCommand());
|
|
4291
|
+
await program2.parseAsync(process.argv);
|
|
4292
|
+
}
|
|
4293
|
+
main().then(() => {
|
|
4294
|
+
process.exit(process.exitCode ?? 0);
|
|
4295
|
+
}).catch((error) => {
|
|
4296
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4297
|
+
v2.error(message);
|
|
4298
|
+
process.exit(1);
|
|
38
4299
|
});
|