@v5x/cli 0.0.20 → 0.0.21
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/README.md +2 -0
- package/dist/index.js +785 -2635
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,2144 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
5
3
|
var __defProp = Object.defineProperty;
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var cached = cache.get(mod);
|
|
18
|
-
if (cached)
|
|
19
|
-
return cached;
|
|
20
|
-
}
|
|
21
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
-
for (let key of __getOwnPropNames(mod))
|
|
24
|
-
if (!__hasOwnProp.call(to, key))
|
|
25
|
-
__defProp(to, key, {
|
|
26
|
-
get: __accessProp.bind(mod, key),
|
|
27
|
-
enumerable: true
|
|
28
|
-
});
|
|
29
|
-
if (canCache)
|
|
30
|
-
cache.set(mod, to);
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
-
var __returnValue = (v) => v;
|
|
35
|
-
function __exportSetter(name, newValue) {
|
|
36
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
37
|
-
}
|
|
38
|
-
var __export = (target, all) => {
|
|
39
|
-
for (var name in all)
|
|
40
|
-
__defProp(target, name, {
|
|
41
|
-
get: all[name],
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
set: __exportSetter.bind(all, name)
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
48
|
-
var __require = import.meta.require;
|
|
49
|
-
|
|
50
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/error.js
|
|
51
|
-
var require_error = __commonJS((exports) => {
|
|
52
|
-
class CommanderError extends Error {
|
|
53
|
-
constructor(exitCode, code, message) {
|
|
54
|
-
super(message);
|
|
55
|
-
Error.captureStackTrace(this, this.constructor);
|
|
56
|
-
this.name = this.constructor.name;
|
|
57
|
-
this.code = code;
|
|
58
|
-
this.exitCode = exitCode;
|
|
59
|
-
this.nestedError = undefined;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
class InvalidArgumentError extends CommanderError {
|
|
64
|
-
constructor(message) {
|
|
65
|
-
super(1, "commander.invalidArgument", message);
|
|
66
|
-
Error.captureStackTrace(this, this.constructor);
|
|
67
|
-
this.name = this.constructor.name;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.CommanderError = CommanderError;
|
|
71
|
-
exports.InvalidArgumentError = InvalidArgumentError;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/argument.js
|
|
75
|
-
var require_argument = __commonJS((exports) => {
|
|
76
|
-
var { InvalidArgumentError } = require_error();
|
|
77
|
-
|
|
78
|
-
class Argument {
|
|
79
|
-
constructor(name, description) {
|
|
80
|
-
this.description = description || "";
|
|
81
|
-
this.variadic = false;
|
|
82
|
-
this.parseArg = undefined;
|
|
83
|
-
this.defaultValue = undefined;
|
|
84
|
-
this.defaultValueDescription = undefined;
|
|
85
|
-
this.argChoices = undefined;
|
|
86
|
-
switch (name[0]) {
|
|
87
|
-
case "<":
|
|
88
|
-
this.required = true;
|
|
89
|
-
this._name = name.slice(1, -1);
|
|
90
|
-
break;
|
|
91
|
-
case "[":
|
|
92
|
-
this.required = false;
|
|
93
|
-
this._name = name.slice(1, -1);
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
this.required = true;
|
|
97
|
-
this._name = name;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (this._name.endsWith("...")) {
|
|
101
|
-
this.variadic = true;
|
|
102
|
-
this._name = this._name.slice(0, -3);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
name() {
|
|
106
|
-
return this._name;
|
|
107
|
-
}
|
|
108
|
-
_collectValue(value, previous) {
|
|
109
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
110
|
-
return [value];
|
|
111
|
-
}
|
|
112
|
-
previous.push(value);
|
|
113
|
-
return previous;
|
|
114
|
-
}
|
|
115
|
-
default(value, description) {
|
|
116
|
-
this.defaultValue = value;
|
|
117
|
-
this.defaultValueDescription = description;
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
argParser(fn) {
|
|
121
|
-
this.parseArg = fn;
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
choices(values) {
|
|
125
|
-
this.argChoices = values.slice();
|
|
126
|
-
this.parseArg = (arg, previous) => {
|
|
127
|
-
if (!this.argChoices.includes(arg)) {
|
|
128
|
-
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
129
|
-
}
|
|
130
|
-
if (this.variadic) {
|
|
131
|
-
return this._collectValue(arg, previous);
|
|
132
|
-
}
|
|
133
|
-
return arg;
|
|
134
|
-
};
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
argRequired() {
|
|
138
|
-
this.required = true;
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
argOptional() {
|
|
142
|
-
this.required = false;
|
|
143
|
-
return this;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function humanReadableArgName(arg) {
|
|
147
|
-
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
148
|
-
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
149
|
-
}
|
|
150
|
-
exports.Argument = Argument;
|
|
151
|
-
exports.humanReadableArgName = humanReadableArgName;
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/help.js
|
|
155
|
-
var require_help = __commonJS((exports) => {
|
|
156
|
-
var { humanReadableArgName } = require_argument();
|
|
157
|
-
|
|
158
|
-
class Help {
|
|
159
|
-
constructor() {
|
|
160
|
-
this.helpWidth = undefined;
|
|
161
|
-
this.minWidthToWrap = 40;
|
|
162
|
-
this.sortSubcommands = false;
|
|
163
|
-
this.sortOptions = false;
|
|
164
|
-
this.showGlobalOptions = false;
|
|
165
|
-
}
|
|
166
|
-
prepareContext(contextOptions) {
|
|
167
|
-
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
168
|
-
}
|
|
169
|
-
visibleCommands(cmd) {
|
|
170
|
-
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
171
|
-
const helpCommand = cmd._getHelpCommand();
|
|
172
|
-
if (helpCommand && !helpCommand._hidden) {
|
|
173
|
-
visibleCommands.push(helpCommand);
|
|
174
|
-
}
|
|
175
|
-
if (this.sortSubcommands) {
|
|
176
|
-
visibleCommands.sort((a, b) => {
|
|
177
|
-
return a.name().localeCompare(b.name());
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return visibleCommands;
|
|
181
|
-
}
|
|
182
|
-
compareOptions(a, b) {
|
|
183
|
-
const getSortKey = (option) => {
|
|
184
|
-
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
185
|
-
};
|
|
186
|
-
return getSortKey(a).localeCompare(getSortKey(b));
|
|
187
|
-
}
|
|
188
|
-
visibleOptions(cmd) {
|
|
189
|
-
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
190
|
-
const helpOption = cmd._getHelpOption();
|
|
191
|
-
if (helpOption && !helpOption.hidden) {
|
|
192
|
-
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
193
|
-
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
194
|
-
if (!removeShort && !removeLong) {
|
|
195
|
-
visibleOptions.push(helpOption);
|
|
196
|
-
} else if (helpOption.long && !removeLong) {
|
|
197
|
-
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
198
|
-
} else if (helpOption.short && !removeShort) {
|
|
199
|
-
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (this.sortOptions) {
|
|
203
|
-
visibleOptions.sort(this.compareOptions);
|
|
204
|
-
}
|
|
205
|
-
return visibleOptions;
|
|
206
|
-
}
|
|
207
|
-
visibleGlobalOptions(cmd) {
|
|
208
|
-
if (!this.showGlobalOptions)
|
|
209
|
-
return [];
|
|
210
|
-
const globalOptions = [];
|
|
211
|
-
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
212
|
-
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
213
|
-
globalOptions.push(...visibleOptions);
|
|
214
|
-
}
|
|
215
|
-
if (this.sortOptions) {
|
|
216
|
-
globalOptions.sort(this.compareOptions);
|
|
217
|
-
}
|
|
218
|
-
return globalOptions;
|
|
219
|
-
}
|
|
220
|
-
visibleArguments(cmd) {
|
|
221
|
-
if (cmd._argsDescription) {
|
|
222
|
-
cmd.registeredArguments.forEach((argument) => {
|
|
223
|
-
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
227
|
-
return cmd.registeredArguments;
|
|
228
|
-
}
|
|
229
|
-
return [];
|
|
230
|
-
}
|
|
231
|
-
subcommandTerm(cmd) {
|
|
232
|
-
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
233
|
-
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
234
|
-
}
|
|
235
|
-
optionTerm(option) {
|
|
236
|
-
return option.flags;
|
|
237
|
-
}
|
|
238
|
-
argumentTerm(argument) {
|
|
239
|
-
return argument.name();
|
|
240
|
-
}
|
|
241
|
-
longestSubcommandTermLength(cmd, helper) {
|
|
242
|
-
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
243
|
-
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
244
|
-
}, 0);
|
|
245
|
-
}
|
|
246
|
-
longestOptionTermLength(cmd, helper) {
|
|
247
|
-
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
248
|
-
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
249
|
-
}, 0);
|
|
250
|
-
}
|
|
251
|
-
longestGlobalOptionTermLength(cmd, helper) {
|
|
252
|
-
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
253
|
-
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
254
|
-
}, 0);
|
|
255
|
-
}
|
|
256
|
-
longestArgumentTermLength(cmd, helper) {
|
|
257
|
-
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
258
|
-
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
259
|
-
}, 0);
|
|
260
|
-
}
|
|
261
|
-
commandUsage(cmd) {
|
|
262
|
-
let cmdName = cmd._name;
|
|
263
|
-
if (cmd._aliases[0]) {
|
|
264
|
-
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
265
|
-
}
|
|
266
|
-
let ancestorCmdNames = "";
|
|
267
|
-
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
268
|
-
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
269
|
-
}
|
|
270
|
-
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
271
|
-
}
|
|
272
|
-
commandDescription(cmd) {
|
|
273
|
-
return cmd.description();
|
|
274
|
-
}
|
|
275
|
-
subcommandDescription(cmd) {
|
|
276
|
-
return cmd.summary() || cmd.description();
|
|
277
|
-
}
|
|
278
|
-
optionDescription(option) {
|
|
279
|
-
const extraInfo = [];
|
|
280
|
-
if (option.argChoices) {
|
|
281
|
-
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
282
|
-
}
|
|
283
|
-
if (option.defaultValue !== undefined) {
|
|
284
|
-
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
285
|
-
if (showDefault) {
|
|
286
|
-
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (option.presetArg !== undefined && option.optional) {
|
|
290
|
-
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
291
|
-
}
|
|
292
|
-
if (option.envVar !== undefined) {
|
|
293
|
-
extraInfo.push(`env: ${option.envVar}`);
|
|
294
|
-
}
|
|
295
|
-
if (extraInfo.length > 0) {
|
|
296
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
297
|
-
if (option.description) {
|
|
298
|
-
return `${option.description} ${extraDescription}`;
|
|
299
|
-
}
|
|
300
|
-
return extraDescription;
|
|
301
|
-
}
|
|
302
|
-
return option.description;
|
|
303
|
-
}
|
|
304
|
-
argumentDescription(argument) {
|
|
305
|
-
const extraInfo = [];
|
|
306
|
-
if (argument.argChoices) {
|
|
307
|
-
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
308
|
-
}
|
|
309
|
-
if (argument.defaultValue !== undefined) {
|
|
310
|
-
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
311
|
-
}
|
|
312
|
-
if (extraInfo.length > 0) {
|
|
313
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
314
|
-
if (argument.description) {
|
|
315
|
-
return `${argument.description} ${extraDescription}`;
|
|
316
|
-
}
|
|
317
|
-
return extraDescription;
|
|
318
|
-
}
|
|
319
|
-
return argument.description;
|
|
320
|
-
}
|
|
321
|
-
formatItemList(heading, items, helper) {
|
|
322
|
-
if (items.length === 0)
|
|
323
|
-
return [];
|
|
324
|
-
return [helper.styleTitle(heading), ...items, ""];
|
|
325
|
-
}
|
|
326
|
-
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
327
|
-
const result = new Map;
|
|
328
|
-
unsortedItems.forEach((item) => {
|
|
329
|
-
const group = getGroup(item);
|
|
330
|
-
if (!result.has(group))
|
|
331
|
-
result.set(group, []);
|
|
332
|
-
});
|
|
333
|
-
visibleItems.forEach((item) => {
|
|
334
|
-
const group = getGroup(item);
|
|
335
|
-
if (!result.has(group)) {
|
|
336
|
-
result.set(group, []);
|
|
337
|
-
}
|
|
338
|
-
result.get(group).push(item);
|
|
339
|
-
});
|
|
340
|
-
return result;
|
|
341
|
-
}
|
|
342
|
-
formatHelp(cmd, helper) {
|
|
343
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
344
|
-
const helpWidth = helper.helpWidth ?? 80;
|
|
345
|
-
function callFormatItem(term, description) {
|
|
346
|
-
return helper.formatItem(term, termWidth, description, helper);
|
|
347
|
-
}
|
|
348
|
-
let output = [
|
|
349
|
-
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
350
|
-
""
|
|
351
|
-
];
|
|
352
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
353
|
-
if (commandDescription.length > 0) {
|
|
354
|
-
output = output.concat([
|
|
355
|
-
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
356
|
-
""
|
|
357
|
-
]);
|
|
358
|
-
}
|
|
359
|
-
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
360
|
-
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
361
|
-
});
|
|
362
|
-
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
363
|
-
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
|
|
364
|
-
optionGroups.forEach((options, group) => {
|
|
365
|
-
const optionList = options.map((option) => {
|
|
366
|
-
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
367
|
-
});
|
|
368
|
-
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
369
|
-
});
|
|
370
|
-
if (helper.showGlobalOptions) {
|
|
371
|
-
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
372
|
-
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
373
|
-
});
|
|
374
|
-
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
375
|
-
}
|
|
376
|
-
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
|
|
377
|
-
commandGroups.forEach((commands, group) => {
|
|
378
|
-
const commandList = commands.map((sub) => {
|
|
379
|
-
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
380
|
-
});
|
|
381
|
-
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
382
|
-
});
|
|
383
|
-
return output.join(`
|
|
384
|
-
`);
|
|
385
|
-
}
|
|
386
|
-
displayWidth(str) {
|
|
387
|
-
return stripColor(str).length;
|
|
388
|
-
}
|
|
389
|
-
styleTitle(str) {
|
|
390
|
-
return str;
|
|
391
|
-
}
|
|
392
|
-
styleUsage(str) {
|
|
393
|
-
return str.split(" ").map((word) => {
|
|
394
|
-
if (word === "[options]")
|
|
395
|
-
return this.styleOptionText(word);
|
|
396
|
-
if (word === "[command]")
|
|
397
|
-
return this.styleSubcommandText(word);
|
|
398
|
-
if (word[0] === "[" || word[0] === "<")
|
|
399
|
-
return this.styleArgumentText(word);
|
|
400
|
-
return this.styleCommandText(word);
|
|
401
|
-
}).join(" ");
|
|
402
|
-
}
|
|
403
|
-
styleCommandDescription(str) {
|
|
404
|
-
return this.styleDescriptionText(str);
|
|
405
|
-
}
|
|
406
|
-
styleOptionDescription(str) {
|
|
407
|
-
return this.styleDescriptionText(str);
|
|
408
|
-
}
|
|
409
|
-
styleSubcommandDescription(str) {
|
|
410
|
-
return this.styleDescriptionText(str);
|
|
411
|
-
}
|
|
412
|
-
styleArgumentDescription(str) {
|
|
413
|
-
return this.styleDescriptionText(str);
|
|
414
|
-
}
|
|
415
|
-
styleDescriptionText(str) {
|
|
416
|
-
return str;
|
|
417
|
-
}
|
|
418
|
-
styleOptionTerm(str) {
|
|
419
|
-
return this.styleOptionText(str);
|
|
420
|
-
}
|
|
421
|
-
styleSubcommandTerm(str) {
|
|
422
|
-
return str.split(" ").map((word) => {
|
|
423
|
-
if (word === "[options]")
|
|
424
|
-
return this.styleOptionText(word);
|
|
425
|
-
if (word[0] === "[" || word[0] === "<")
|
|
426
|
-
return this.styleArgumentText(word);
|
|
427
|
-
return this.styleSubcommandText(word);
|
|
428
|
-
}).join(" ");
|
|
429
|
-
}
|
|
430
|
-
styleArgumentTerm(str) {
|
|
431
|
-
return this.styleArgumentText(str);
|
|
432
|
-
}
|
|
433
|
-
styleOptionText(str) {
|
|
434
|
-
return str;
|
|
435
|
-
}
|
|
436
|
-
styleArgumentText(str) {
|
|
437
|
-
return str;
|
|
438
|
-
}
|
|
439
|
-
styleSubcommandText(str) {
|
|
440
|
-
return str;
|
|
441
|
-
}
|
|
442
|
-
styleCommandText(str) {
|
|
443
|
-
return str;
|
|
444
|
-
}
|
|
445
|
-
padWidth(cmd, helper) {
|
|
446
|
-
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
447
|
-
}
|
|
448
|
-
preformatted(str) {
|
|
449
|
-
return /\n[^\S\r\n]/.test(str);
|
|
450
|
-
}
|
|
451
|
-
formatItem(term, termWidth, description, helper) {
|
|
452
|
-
const itemIndent = 2;
|
|
453
|
-
const itemIndentStr = " ".repeat(itemIndent);
|
|
454
|
-
if (!description)
|
|
455
|
-
return itemIndentStr + term;
|
|
456
|
-
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
457
|
-
const spacerWidth = 2;
|
|
458
|
-
const helpWidth = this.helpWidth ?? 80;
|
|
459
|
-
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
460
|
-
let formattedDescription;
|
|
461
|
-
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
462
|
-
formattedDescription = description;
|
|
463
|
-
} else {
|
|
464
|
-
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
465
|
-
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
466
|
-
` + " ".repeat(termWidth + spacerWidth));
|
|
467
|
-
}
|
|
468
|
-
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
469
|
-
${itemIndentStr}`);
|
|
470
|
-
}
|
|
471
|
-
boxWrap(str, width) {
|
|
472
|
-
if (width < this.minWidthToWrap)
|
|
473
|
-
return str;
|
|
474
|
-
const rawLines = str.split(/\r\n|\n/);
|
|
475
|
-
const chunkPattern = /[\s]*[^\s]+/g;
|
|
476
|
-
const wrappedLines = [];
|
|
477
|
-
rawLines.forEach((line) => {
|
|
478
|
-
const chunks = line.match(chunkPattern);
|
|
479
|
-
if (chunks === null) {
|
|
480
|
-
wrappedLines.push("");
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
let sumChunks = [chunks.shift()];
|
|
484
|
-
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
485
|
-
chunks.forEach((chunk) => {
|
|
486
|
-
const visibleWidth = this.displayWidth(chunk);
|
|
487
|
-
if (sumWidth + visibleWidth <= width) {
|
|
488
|
-
sumChunks.push(chunk);
|
|
489
|
-
sumWidth += visibleWidth;
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
wrappedLines.push(sumChunks.join(""));
|
|
493
|
-
const nextChunk = chunk.trimStart();
|
|
494
|
-
sumChunks = [nextChunk];
|
|
495
|
-
sumWidth = this.displayWidth(nextChunk);
|
|
496
|
-
});
|
|
497
|
-
wrappedLines.push(sumChunks.join(""));
|
|
498
|
-
});
|
|
499
|
-
return wrappedLines.join(`
|
|
500
|
-
`);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
function stripColor(str) {
|
|
504
|
-
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
505
|
-
return str.replace(sgrPattern, "");
|
|
506
|
-
}
|
|
507
|
-
exports.Help = Help;
|
|
508
|
-
exports.stripColor = stripColor;
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/option.js
|
|
512
|
-
var require_option = __commonJS((exports) => {
|
|
513
|
-
var { InvalidArgumentError } = require_error();
|
|
514
|
-
|
|
515
|
-
class Option {
|
|
516
|
-
constructor(flags, description) {
|
|
517
|
-
this.flags = flags;
|
|
518
|
-
this.description = description || "";
|
|
519
|
-
this.required = flags.includes("<");
|
|
520
|
-
this.optional = flags.includes("[");
|
|
521
|
-
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
522
|
-
this.mandatory = false;
|
|
523
|
-
const optionFlags = splitOptionFlags(flags);
|
|
524
|
-
this.short = optionFlags.shortFlag;
|
|
525
|
-
this.long = optionFlags.longFlag;
|
|
526
|
-
this.negate = false;
|
|
527
|
-
if (this.long) {
|
|
528
|
-
this.negate = this.long.startsWith("--no-");
|
|
529
|
-
}
|
|
530
|
-
this.defaultValue = undefined;
|
|
531
|
-
this.defaultValueDescription = undefined;
|
|
532
|
-
this.presetArg = undefined;
|
|
533
|
-
this.envVar = undefined;
|
|
534
|
-
this.parseArg = undefined;
|
|
535
|
-
this.hidden = false;
|
|
536
|
-
this.argChoices = undefined;
|
|
537
|
-
this.conflictsWith = [];
|
|
538
|
-
this.implied = undefined;
|
|
539
|
-
this.helpGroupHeading = undefined;
|
|
540
|
-
}
|
|
541
|
-
default(value, description) {
|
|
542
|
-
this.defaultValue = value;
|
|
543
|
-
this.defaultValueDescription = description;
|
|
544
|
-
return this;
|
|
545
|
-
}
|
|
546
|
-
preset(arg) {
|
|
547
|
-
this.presetArg = arg;
|
|
548
|
-
return this;
|
|
549
|
-
}
|
|
550
|
-
conflicts(names) {
|
|
551
|
-
this.conflictsWith = this.conflictsWith.concat(names);
|
|
552
|
-
return this;
|
|
553
|
-
}
|
|
554
|
-
implies(impliedOptionValues) {
|
|
555
|
-
let newImplied = impliedOptionValues;
|
|
556
|
-
if (typeof impliedOptionValues === "string") {
|
|
557
|
-
newImplied = { [impliedOptionValues]: true };
|
|
558
|
-
}
|
|
559
|
-
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
560
|
-
return this;
|
|
561
|
-
}
|
|
562
|
-
env(name) {
|
|
563
|
-
this.envVar = name;
|
|
564
|
-
return this;
|
|
565
|
-
}
|
|
566
|
-
argParser(fn) {
|
|
567
|
-
this.parseArg = fn;
|
|
568
|
-
return this;
|
|
569
|
-
}
|
|
570
|
-
makeOptionMandatory(mandatory = true) {
|
|
571
|
-
this.mandatory = !!mandatory;
|
|
572
|
-
return this;
|
|
573
|
-
}
|
|
574
|
-
hideHelp(hide = true) {
|
|
575
|
-
this.hidden = !!hide;
|
|
576
|
-
return this;
|
|
577
|
-
}
|
|
578
|
-
_collectValue(value, previous) {
|
|
579
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
580
|
-
return [value];
|
|
581
|
-
}
|
|
582
|
-
previous.push(value);
|
|
583
|
-
return previous;
|
|
584
|
-
}
|
|
585
|
-
choices(values) {
|
|
586
|
-
this.argChoices = values.slice();
|
|
587
|
-
this.parseArg = (arg, previous) => {
|
|
588
|
-
if (!this.argChoices.includes(arg)) {
|
|
589
|
-
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
590
|
-
}
|
|
591
|
-
if (this.variadic) {
|
|
592
|
-
return this._collectValue(arg, previous);
|
|
593
|
-
}
|
|
594
|
-
return arg;
|
|
595
|
-
};
|
|
596
|
-
return this;
|
|
597
|
-
}
|
|
598
|
-
name() {
|
|
599
|
-
if (this.long) {
|
|
600
|
-
return this.long.replace(/^--/, "");
|
|
601
|
-
}
|
|
602
|
-
return this.short.replace(/^-/, "");
|
|
603
|
-
}
|
|
604
|
-
attributeName() {
|
|
605
|
-
if (this.negate) {
|
|
606
|
-
return camelcase(this.name().replace(/^no-/, ""));
|
|
607
|
-
}
|
|
608
|
-
return camelcase(this.name());
|
|
609
|
-
}
|
|
610
|
-
helpGroup(heading) {
|
|
611
|
-
this.helpGroupHeading = heading;
|
|
612
|
-
return this;
|
|
613
|
-
}
|
|
614
|
-
is(arg) {
|
|
615
|
-
return this.short === arg || this.long === arg;
|
|
616
|
-
}
|
|
617
|
-
isBoolean() {
|
|
618
|
-
return !this.required && !this.optional && !this.negate;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
class DualOptions {
|
|
623
|
-
constructor(options) {
|
|
624
|
-
this.positiveOptions = new Map;
|
|
625
|
-
this.negativeOptions = new Map;
|
|
626
|
-
this.dualOptions = new Set;
|
|
627
|
-
options.forEach((option) => {
|
|
628
|
-
if (option.negate) {
|
|
629
|
-
this.negativeOptions.set(option.attributeName(), option);
|
|
630
|
-
} else {
|
|
631
|
-
this.positiveOptions.set(option.attributeName(), option);
|
|
632
|
-
}
|
|
633
|
-
});
|
|
634
|
-
this.negativeOptions.forEach((value, key) => {
|
|
635
|
-
if (this.positiveOptions.has(key)) {
|
|
636
|
-
this.dualOptions.add(key);
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
valueFromOption(value, option) {
|
|
641
|
-
const optionKey = option.attributeName();
|
|
642
|
-
if (!this.dualOptions.has(optionKey))
|
|
643
|
-
return true;
|
|
644
|
-
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
645
|
-
const negativeValue = preset !== undefined ? preset : false;
|
|
646
|
-
return option.negate === (negativeValue === value);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
function camelcase(str) {
|
|
650
|
-
return str.split("-").reduce((str2, word) => {
|
|
651
|
-
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
function splitOptionFlags(flags) {
|
|
655
|
-
let shortFlag;
|
|
656
|
-
let longFlag;
|
|
657
|
-
const shortFlagExp = /^-[^-]$/;
|
|
658
|
-
const longFlagExp = /^--[^-]/;
|
|
659
|
-
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
660
|
-
if (shortFlagExp.test(flagParts[0]))
|
|
661
|
-
shortFlag = flagParts.shift();
|
|
662
|
-
if (longFlagExp.test(flagParts[0]))
|
|
663
|
-
longFlag = flagParts.shift();
|
|
664
|
-
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
665
|
-
shortFlag = flagParts.shift();
|
|
666
|
-
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
667
|
-
shortFlag = longFlag;
|
|
668
|
-
longFlag = flagParts.shift();
|
|
669
|
-
}
|
|
670
|
-
if (flagParts[0].startsWith("-")) {
|
|
671
|
-
const unsupportedFlag = flagParts[0];
|
|
672
|
-
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
673
|
-
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
674
|
-
throw new Error(`${baseError}
|
|
675
|
-
- a short flag is a single dash and a single character
|
|
676
|
-
- either use a single dash and a single character (for a short flag)
|
|
677
|
-
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
678
|
-
if (shortFlagExp.test(unsupportedFlag))
|
|
679
|
-
throw new Error(`${baseError}
|
|
680
|
-
- too many short flags`);
|
|
681
|
-
if (longFlagExp.test(unsupportedFlag))
|
|
682
|
-
throw new Error(`${baseError}
|
|
683
|
-
- too many long flags`);
|
|
684
|
-
throw new Error(`${baseError}
|
|
685
|
-
- unrecognised flag format`);
|
|
686
|
-
}
|
|
687
|
-
if (shortFlag === undefined && longFlag === undefined)
|
|
688
|
-
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
689
|
-
return { shortFlag, longFlag };
|
|
690
|
-
}
|
|
691
|
-
exports.Option = Option;
|
|
692
|
-
exports.DualOptions = DualOptions;
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js
|
|
696
|
-
var require_suggestSimilar = __commonJS((exports) => {
|
|
697
|
-
var maxDistance = 3;
|
|
698
|
-
function editDistance(a, b) {
|
|
699
|
-
if (Math.abs(a.length - b.length) > maxDistance)
|
|
700
|
-
return Math.max(a.length, b.length);
|
|
701
|
-
const d = [];
|
|
702
|
-
for (let i = 0;i <= a.length; i++) {
|
|
703
|
-
d[i] = [i];
|
|
704
|
-
}
|
|
705
|
-
for (let j = 0;j <= b.length; j++) {
|
|
706
|
-
d[0][j] = j;
|
|
707
|
-
}
|
|
708
|
-
for (let j = 1;j <= b.length; j++) {
|
|
709
|
-
for (let i = 1;i <= a.length; i++) {
|
|
710
|
-
let cost = 1;
|
|
711
|
-
if (a[i - 1] === b[j - 1]) {
|
|
712
|
-
cost = 0;
|
|
713
|
-
} else {
|
|
714
|
-
cost = 1;
|
|
715
|
-
}
|
|
716
|
-
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
717
|
-
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
718
|
-
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
return d[a.length][b.length];
|
|
723
|
-
}
|
|
724
|
-
function suggestSimilar(word, candidates) {
|
|
725
|
-
if (!candidates || candidates.length === 0)
|
|
726
|
-
return "";
|
|
727
|
-
candidates = Array.from(new Set(candidates));
|
|
728
|
-
const searchingOptions = word.startsWith("--");
|
|
729
|
-
if (searchingOptions) {
|
|
730
|
-
word = word.slice(2);
|
|
731
|
-
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
732
|
-
}
|
|
733
|
-
let similar = [];
|
|
734
|
-
let bestDistance = maxDistance;
|
|
735
|
-
const minSimilarity = 0.4;
|
|
736
|
-
candidates.forEach((candidate) => {
|
|
737
|
-
if (candidate.length <= 1)
|
|
738
|
-
return;
|
|
739
|
-
const distance = editDistance(word, candidate);
|
|
740
|
-
const length = Math.max(word.length, candidate.length);
|
|
741
|
-
const similarity = (length - distance) / length;
|
|
742
|
-
if (similarity > minSimilarity) {
|
|
743
|
-
if (distance < bestDistance) {
|
|
744
|
-
bestDistance = distance;
|
|
745
|
-
similar = [candidate];
|
|
746
|
-
} else if (distance === bestDistance) {
|
|
747
|
-
similar.push(candidate);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
similar.sort((a, b) => a.localeCompare(b));
|
|
752
|
-
if (searchingOptions) {
|
|
753
|
-
similar = similar.map((candidate) => `--${candidate}`);
|
|
754
|
-
}
|
|
755
|
-
if (similar.length > 1) {
|
|
756
|
-
return `
|
|
757
|
-
(Did you mean one of ${similar.join(", ")}?)`;
|
|
758
|
-
}
|
|
759
|
-
if (similar.length === 1) {
|
|
760
|
-
return `
|
|
761
|
-
(Did you mean ${similar[0]}?)`;
|
|
762
|
-
}
|
|
763
|
-
return "";
|
|
764
|
-
}
|
|
765
|
-
exports.suggestSimilar = suggestSimilar;
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/command.js
|
|
769
|
-
var require_command = __commonJS((exports) => {
|
|
770
|
-
var EventEmitter = __require("events").EventEmitter;
|
|
771
|
-
var childProcess = __require("child_process");
|
|
772
|
-
var path = __require("path");
|
|
773
|
-
var fs = __require("fs");
|
|
774
|
-
var process2 = __require("process");
|
|
775
|
-
var { Argument, humanReadableArgName } = require_argument();
|
|
776
|
-
var { CommanderError } = require_error();
|
|
777
|
-
var { Help, stripColor } = require_help();
|
|
778
|
-
var { Option, DualOptions } = require_option();
|
|
779
|
-
var { suggestSimilar } = require_suggestSimilar();
|
|
780
|
-
|
|
781
|
-
class Command extends EventEmitter {
|
|
782
|
-
constructor(name) {
|
|
783
|
-
super();
|
|
784
|
-
this.commands = [];
|
|
785
|
-
this.options = [];
|
|
786
|
-
this.parent = null;
|
|
787
|
-
this._allowUnknownOption = false;
|
|
788
|
-
this._allowExcessArguments = false;
|
|
789
|
-
this.registeredArguments = [];
|
|
790
|
-
this._args = this.registeredArguments;
|
|
791
|
-
this.args = [];
|
|
792
|
-
this.rawArgs = [];
|
|
793
|
-
this.processedArgs = [];
|
|
794
|
-
this._scriptPath = null;
|
|
795
|
-
this._name = name || "";
|
|
796
|
-
this._optionValues = {};
|
|
797
|
-
this._optionValueSources = {};
|
|
798
|
-
this._storeOptionsAsProperties = false;
|
|
799
|
-
this._actionHandler = null;
|
|
800
|
-
this._executableHandler = false;
|
|
801
|
-
this._executableFile = null;
|
|
802
|
-
this._executableDir = null;
|
|
803
|
-
this._defaultCommandName = null;
|
|
804
|
-
this._exitCallback = null;
|
|
805
|
-
this._aliases = [];
|
|
806
|
-
this._combineFlagAndOptionalValue = true;
|
|
807
|
-
this._description = "";
|
|
808
|
-
this._summary = "";
|
|
809
|
-
this._argsDescription = undefined;
|
|
810
|
-
this._enablePositionalOptions = false;
|
|
811
|
-
this._passThroughOptions = false;
|
|
812
|
-
this._lifeCycleHooks = {};
|
|
813
|
-
this._showHelpAfterError = false;
|
|
814
|
-
this._showSuggestionAfterError = true;
|
|
815
|
-
this._savedState = null;
|
|
816
|
-
this._outputConfiguration = {
|
|
817
|
-
writeOut: (str) => process2.stdout.write(str),
|
|
818
|
-
writeErr: (str) => process2.stderr.write(str),
|
|
819
|
-
outputError: (str, write) => write(str),
|
|
820
|
-
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
821
|
-
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
822
|
-
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
823
|
-
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
824
|
-
stripColor: (str) => stripColor(str)
|
|
825
|
-
};
|
|
826
|
-
this._hidden = false;
|
|
827
|
-
this._helpOption = undefined;
|
|
828
|
-
this._addImplicitHelpCommand = undefined;
|
|
829
|
-
this._helpCommand = undefined;
|
|
830
|
-
this._helpConfiguration = {};
|
|
831
|
-
this._helpGroupHeading = undefined;
|
|
832
|
-
this._defaultCommandGroup = undefined;
|
|
833
|
-
this._defaultOptionGroup = undefined;
|
|
834
|
-
}
|
|
835
|
-
copyInheritedSettings(sourceCommand) {
|
|
836
|
-
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
837
|
-
this._helpOption = sourceCommand._helpOption;
|
|
838
|
-
this._helpCommand = sourceCommand._helpCommand;
|
|
839
|
-
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
840
|
-
this._exitCallback = sourceCommand._exitCallback;
|
|
841
|
-
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
842
|
-
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
843
|
-
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
844
|
-
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
845
|
-
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
846
|
-
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
847
|
-
return this;
|
|
848
|
-
}
|
|
849
|
-
_getCommandAndAncestors() {
|
|
850
|
-
const result = [];
|
|
851
|
-
for (let command = this;command; command = command.parent) {
|
|
852
|
-
result.push(command);
|
|
853
|
-
}
|
|
854
|
-
return result;
|
|
855
|
-
}
|
|
856
|
-
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
857
|
-
let desc = actionOptsOrExecDesc;
|
|
858
|
-
let opts = execOpts;
|
|
859
|
-
if (typeof desc === "object" && desc !== null) {
|
|
860
|
-
opts = desc;
|
|
861
|
-
desc = null;
|
|
862
|
-
}
|
|
863
|
-
opts = opts || {};
|
|
864
|
-
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
865
|
-
const cmd = this.createCommand(name);
|
|
866
|
-
if (desc) {
|
|
867
|
-
cmd.description(desc);
|
|
868
|
-
cmd._executableHandler = true;
|
|
869
|
-
}
|
|
870
|
-
if (opts.isDefault)
|
|
871
|
-
this._defaultCommandName = cmd._name;
|
|
872
|
-
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
873
|
-
cmd._executableFile = opts.executableFile || null;
|
|
874
|
-
if (args)
|
|
875
|
-
cmd.arguments(args);
|
|
876
|
-
this._registerCommand(cmd);
|
|
877
|
-
cmd.parent = this;
|
|
878
|
-
cmd.copyInheritedSettings(this);
|
|
879
|
-
if (desc)
|
|
880
|
-
return this;
|
|
881
|
-
return cmd;
|
|
882
|
-
}
|
|
883
|
-
createCommand(name) {
|
|
884
|
-
return new Command(name);
|
|
885
|
-
}
|
|
886
|
-
createHelp() {
|
|
887
|
-
return Object.assign(new Help, this.configureHelp());
|
|
888
|
-
}
|
|
889
|
-
configureHelp(configuration) {
|
|
890
|
-
if (configuration === undefined)
|
|
891
|
-
return this._helpConfiguration;
|
|
892
|
-
this._helpConfiguration = configuration;
|
|
893
|
-
return this;
|
|
894
|
-
}
|
|
895
|
-
configureOutput(configuration) {
|
|
896
|
-
if (configuration === undefined)
|
|
897
|
-
return this._outputConfiguration;
|
|
898
|
-
this._outputConfiguration = {
|
|
899
|
-
...this._outputConfiguration,
|
|
900
|
-
...configuration
|
|
901
|
-
};
|
|
902
|
-
return this;
|
|
903
|
-
}
|
|
904
|
-
showHelpAfterError(displayHelp = true) {
|
|
905
|
-
if (typeof displayHelp !== "string")
|
|
906
|
-
displayHelp = !!displayHelp;
|
|
907
|
-
this._showHelpAfterError = displayHelp;
|
|
908
|
-
return this;
|
|
909
|
-
}
|
|
910
|
-
showSuggestionAfterError(displaySuggestion = true) {
|
|
911
|
-
this._showSuggestionAfterError = !!displaySuggestion;
|
|
912
|
-
return this;
|
|
913
|
-
}
|
|
914
|
-
addCommand(cmd, opts) {
|
|
915
|
-
if (!cmd._name) {
|
|
916
|
-
throw new Error(`Command passed to .addCommand() must have a name
|
|
917
|
-
- specify the name in Command constructor or using .name()`);
|
|
918
|
-
}
|
|
919
|
-
opts = opts || {};
|
|
920
|
-
if (opts.isDefault)
|
|
921
|
-
this._defaultCommandName = cmd._name;
|
|
922
|
-
if (opts.noHelp || opts.hidden)
|
|
923
|
-
cmd._hidden = true;
|
|
924
|
-
this._registerCommand(cmd);
|
|
925
|
-
cmd.parent = this;
|
|
926
|
-
cmd._checkForBrokenPassThrough();
|
|
927
|
-
return this;
|
|
928
|
-
}
|
|
929
|
-
createArgument(name, description) {
|
|
930
|
-
return new Argument(name, description);
|
|
931
|
-
}
|
|
932
|
-
argument(name, description, parseArg, defaultValue) {
|
|
933
|
-
const argument = this.createArgument(name, description);
|
|
934
|
-
if (typeof parseArg === "function") {
|
|
935
|
-
argument.default(defaultValue).argParser(parseArg);
|
|
936
|
-
} else {
|
|
937
|
-
argument.default(parseArg);
|
|
938
|
-
}
|
|
939
|
-
this.addArgument(argument);
|
|
940
|
-
return this;
|
|
941
|
-
}
|
|
942
|
-
arguments(names) {
|
|
943
|
-
names.trim().split(/ +/).forEach((detail) => {
|
|
944
|
-
this.argument(detail);
|
|
945
|
-
});
|
|
946
|
-
return this;
|
|
947
|
-
}
|
|
948
|
-
addArgument(argument) {
|
|
949
|
-
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
950
|
-
if (previousArgument?.variadic) {
|
|
951
|
-
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
952
|
-
}
|
|
953
|
-
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
954
|
-
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
955
|
-
}
|
|
956
|
-
this.registeredArguments.push(argument);
|
|
957
|
-
return this;
|
|
958
|
-
}
|
|
959
|
-
helpCommand(enableOrNameAndArgs, description) {
|
|
960
|
-
if (typeof enableOrNameAndArgs === "boolean") {
|
|
961
|
-
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
962
|
-
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
963
|
-
this._initCommandGroup(this._getHelpCommand());
|
|
964
|
-
}
|
|
965
|
-
return this;
|
|
966
|
-
}
|
|
967
|
-
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
968
|
-
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
969
|
-
const helpDescription = description ?? "display help for command";
|
|
970
|
-
const helpCommand = this.createCommand(helpName);
|
|
971
|
-
helpCommand.helpOption(false);
|
|
972
|
-
if (helpArgs)
|
|
973
|
-
helpCommand.arguments(helpArgs);
|
|
974
|
-
if (helpDescription)
|
|
975
|
-
helpCommand.description(helpDescription);
|
|
976
|
-
this._addImplicitHelpCommand = true;
|
|
977
|
-
this._helpCommand = helpCommand;
|
|
978
|
-
if (enableOrNameAndArgs || description)
|
|
979
|
-
this._initCommandGroup(helpCommand);
|
|
980
|
-
return this;
|
|
981
|
-
}
|
|
982
|
-
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
983
|
-
if (typeof helpCommand !== "object") {
|
|
984
|
-
this.helpCommand(helpCommand, deprecatedDescription);
|
|
985
|
-
return this;
|
|
986
|
-
}
|
|
987
|
-
this._addImplicitHelpCommand = true;
|
|
988
|
-
this._helpCommand = helpCommand;
|
|
989
|
-
this._initCommandGroup(helpCommand);
|
|
990
|
-
return this;
|
|
991
|
-
}
|
|
992
|
-
_getHelpCommand() {
|
|
993
|
-
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
994
|
-
if (hasImplicitHelpCommand) {
|
|
995
|
-
if (this._helpCommand === undefined) {
|
|
996
|
-
this.helpCommand(undefined, undefined);
|
|
997
|
-
}
|
|
998
|
-
return this._helpCommand;
|
|
999
|
-
}
|
|
1000
|
-
return null;
|
|
1001
|
-
}
|
|
1002
|
-
hook(event, listener) {
|
|
1003
|
-
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1004
|
-
if (!allowedValues.includes(event)) {
|
|
1005
|
-
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1006
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1007
|
-
}
|
|
1008
|
-
if (this._lifeCycleHooks[event]) {
|
|
1009
|
-
this._lifeCycleHooks[event].push(listener);
|
|
1010
|
-
} else {
|
|
1011
|
-
this._lifeCycleHooks[event] = [listener];
|
|
1012
|
-
}
|
|
1013
|
-
return this;
|
|
1014
|
-
}
|
|
1015
|
-
exitOverride(fn) {
|
|
1016
|
-
if (fn) {
|
|
1017
|
-
this._exitCallback = fn;
|
|
1018
|
-
} else {
|
|
1019
|
-
this._exitCallback = (err) => {
|
|
1020
|
-
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1021
|
-
throw err;
|
|
1022
|
-
} else {}
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
return this;
|
|
1026
|
-
}
|
|
1027
|
-
_exit(exitCode, code, message) {
|
|
1028
|
-
if (this._exitCallback) {
|
|
1029
|
-
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
1030
|
-
}
|
|
1031
|
-
process2.exit(exitCode);
|
|
1032
|
-
}
|
|
1033
|
-
action(fn) {
|
|
1034
|
-
const listener = (args) => {
|
|
1035
|
-
const expectedArgsCount = this.registeredArguments.length;
|
|
1036
|
-
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1037
|
-
if (this._storeOptionsAsProperties) {
|
|
1038
|
-
actionArgs[expectedArgsCount] = this;
|
|
1039
|
-
} else {
|
|
1040
|
-
actionArgs[expectedArgsCount] = this.opts();
|
|
1041
|
-
}
|
|
1042
|
-
actionArgs.push(this);
|
|
1043
|
-
return fn.apply(this, actionArgs);
|
|
1044
|
-
};
|
|
1045
|
-
this._actionHandler = listener;
|
|
1046
|
-
return this;
|
|
1047
|
-
}
|
|
1048
|
-
createOption(flags, description) {
|
|
1049
|
-
return new Option(flags, description);
|
|
1050
|
-
}
|
|
1051
|
-
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1052
|
-
try {
|
|
1053
|
-
return target.parseArg(value, previous);
|
|
1054
|
-
} catch (err) {
|
|
1055
|
-
if (err.code === "commander.invalidArgument") {
|
|
1056
|
-
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1057
|
-
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1058
|
-
}
|
|
1059
|
-
throw err;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
_registerOption(option) {
|
|
1063
|
-
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1064
|
-
if (matchingOption) {
|
|
1065
|
-
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1066
|
-
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1067
|
-
- already used by option '${matchingOption.flags}'`);
|
|
1068
|
-
}
|
|
1069
|
-
this._initOptionGroup(option);
|
|
1070
|
-
this.options.push(option);
|
|
1071
|
-
}
|
|
1072
|
-
_registerCommand(command) {
|
|
1073
|
-
const knownBy = (cmd) => {
|
|
1074
|
-
return [cmd.name()].concat(cmd.aliases());
|
|
1075
|
-
};
|
|
1076
|
-
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
1077
|
-
if (alreadyUsed) {
|
|
1078
|
-
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1079
|
-
const newCmd = knownBy(command).join("|");
|
|
1080
|
-
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
1081
|
-
}
|
|
1082
|
-
this._initCommandGroup(command);
|
|
1083
|
-
this.commands.push(command);
|
|
1084
|
-
}
|
|
1085
|
-
addOption(option) {
|
|
1086
|
-
this._registerOption(option);
|
|
1087
|
-
const oname = option.name();
|
|
1088
|
-
const name = option.attributeName();
|
|
1089
|
-
if (option.negate) {
|
|
1090
|
-
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1091
|
-
if (!this._findOption(positiveLongFlag)) {
|
|
1092
|
-
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
1093
|
-
}
|
|
1094
|
-
} else if (option.defaultValue !== undefined) {
|
|
1095
|
-
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1096
|
-
}
|
|
1097
|
-
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1098
|
-
if (val == null && option.presetArg !== undefined) {
|
|
1099
|
-
val = option.presetArg;
|
|
1100
|
-
}
|
|
1101
|
-
const oldValue = this.getOptionValue(name);
|
|
1102
|
-
if (val !== null && option.parseArg) {
|
|
1103
|
-
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1104
|
-
} else if (val !== null && option.variadic) {
|
|
1105
|
-
val = option._collectValue(val, oldValue);
|
|
1106
|
-
}
|
|
1107
|
-
if (val == null) {
|
|
1108
|
-
if (option.negate) {
|
|
1109
|
-
val = false;
|
|
1110
|
-
} else if (option.isBoolean() || option.optional) {
|
|
1111
|
-
val = true;
|
|
1112
|
-
} else {
|
|
1113
|
-
val = "";
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
this.setOptionValueWithSource(name, val, valueSource);
|
|
1117
|
-
};
|
|
1118
|
-
this.on("option:" + oname, (val) => {
|
|
1119
|
-
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1120
|
-
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1121
|
-
});
|
|
1122
|
-
if (option.envVar) {
|
|
1123
|
-
this.on("optionEnv:" + oname, (val) => {
|
|
1124
|
-
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1125
|
-
handleOptionValue(val, invalidValueMessage, "env");
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
|
-
return this;
|
|
1129
|
-
}
|
|
1130
|
-
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1131
|
-
if (typeof flags === "object" && flags instanceof Option) {
|
|
1132
|
-
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1133
|
-
}
|
|
1134
|
-
const option = this.createOption(flags, description);
|
|
1135
|
-
option.makeOptionMandatory(!!config.mandatory);
|
|
1136
|
-
if (typeof fn === "function") {
|
|
1137
|
-
option.default(defaultValue).argParser(fn);
|
|
1138
|
-
} else if (fn instanceof RegExp) {
|
|
1139
|
-
const regex = fn;
|
|
1140
|
-
fn = (val, def) => {
|
|
1141
|
-
const m = regex.exec(val);
|
|
1142
|
-
return m ? m[0] : def;
|
|
1143
|
-
};
|
|
1144
|
-
option.default(defaultValue).argParser(fn);
|
|
1145
|
-
} else {
|
|
1146
|
-
option.default(fn);
|
|
1147
|
-
}
|
|
1148
|
-
return this.addOption(option);
|
|
1149
|
-
}
|
|
1150
|
-
option(flags, description, parseArg, defaultValue) {
|
|
1151
|
-
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1152
|
-
}
|
|
1153
|
-
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1154
|
-
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
1155
|
-
}
|
|
1156
|
-
combineFlagAndOptionalValue(combine = true) {
|
|
1157
|
-
this._combineFlagAndOptionalValue = !!combine;
|
|
1158
|
-
return this;
|
|
1159
|
-
}
|
|
1160
|
-
allowUnknownOption(allowUnknown = true) {
|
|
1161
|
-
this._allowUnknownOption = !!allowUnknown;
|
|
1162
|
-
return this;
|
|
1163
|
-
}
|
|
1164
|
-
allowExcessArguments(allowExcess = true) {
|
|
1165
|
-
this._allowExcessArguments = !!allowExcess;
|
|
1166
|
-
return this;
|
|
1167
|
-
}
|
|
1168
|
-
enablePositionalOptions(positional = true) {
|
|
1169
|
-
this._enablePositionalOptions = !!positional;
|
|
1170
|
-
return this;
|
|
1171
|
-
}
|
|
1172
|
-
passThroughOptions(passThrough = true) {
|
|
1173
|
-
this._passThroughOptions = !!passThrough;
|
|
1174
|
-
this._checkForBrokenPassThrough();
|
|
1175
|
-
return this;
|
|
1176
|
-
}
|
|
1177
|
-
_checkForBrokenPassThrough() {
|
|
1178
|
-
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1179
|
-
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1183
|
-
if (this.options.length) {
|
|
1184
|
-
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1185
|
-
}
|
|
1186
|
-
if (Object.keys(this._optionValues).length) {
|
|
1187
|
-
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1188
|
-
}
|
|
1189
|
-
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1190
|
-
return this;
|
|
1191
|
-
}
|
|
1192
|
-
getOptionValue(key) {
|
|
1193
|
-
if (this._storeOptionsAsProperties) {
|
|
1194
|
-
return this[key];
|
|
1195
|
-
}
|
|
1196
|
-
return this._optionValues[key];
|
|
1197
|
-
}
|
|
1198
|
-
setOptionValue(key, value) {
|
|
1199
|
-
return this.setOptionValueWithSource(key, value, undefined);
|
|
1200
|
-
}
|
|
1201
|
-
setOptionValueWithSource(key, value, source) {
|
|
1202
|
-
if (this._storeOptionsAsProperties) {
|
|
1203
|
-
this[key] = value;
|
|
1204
|
-
} else {
|
|
1205
|
-
this._optionValues[key] = value;
|
|
1206
|
-
}
|
|
1207
|
-
this._optionValueSources[key] = source;
|
|
1208
|
-
return this;
|
|
1209
|
-
}
|
|
1210
|
-
getOptionValueSource(key) {
|
|
1211
|
-
return this._optionValueSources[key];
|
|
1212
|
-
}
|
|
1213
|
-
getOptionValueSourceWithGlobals(key) {
|
|
1214
|
-
let source;
|
|
1215
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1216
|
-
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1217
|
-
source = cmd.getOptionValueSource(key);
|
|
1218
|
-
}
|
|
1219
|
-
});
|
|
1220
|
-
return source;
|
|
1221
|
-
}
|
|
1222
|
-
_prepareUserArgs(argv, parseOptions) {
|
|
1223
|
-
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1224
|
-
throw new Error("first parameter to parse must be array or undefined");
|
|
1225
|
-
}
|
|
1226
|
-
parseOptions = parseOptions || {};
|
|
1227
|
-
if (argv === undefined && parseOptions.from === undefined) {
|
|
1228
|
-
if (process2.versions?.electron) {
|
|
1229
|
-
parseOptions.from = "electron";
|
|
1230
|
-
}
|
|
1231
|
-
const execArgv = process2.execArgv ?? [];
|
|
1232
|
-
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1233
|
-
parseOptions.from = "eval";
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
if (argv === undefined) {
|
|
1237
|
-
argv = process2.argv;
|
|
1238
|
-
}
|
|
1239
|
-
this.rawArgs = argv.slice();
|
|
1240
|
-
let userArgs;
|
|
1241
|
-
switch (parseOptions.from) {
|
|
1242
|
-
case undefined:
|
|
1243
|
-
case "node":
|
|
1244
|
-
this._scriptPath = argv[1];
|
|
1245
|
-
userArgs = argv.slice(2);
|
|
1246
|
-
break;
|
|
1247
|
-
case "electron":
|
|
1248
|
-
if (process2.defaultApp) {
|
|
1249
|
-
this._scriptPath = argv[1];
|
|
1250
|
-
userArgs = argv.slice(2);
|
|
1251
|
-
} else {
|
|
1252
|
-
userArgs = argv.slice(1);
|
|
1253
|
-
}
|
|
1254
|
-
break;
|
|
1255
|
-
case "user":
|
|
1256
|
-
userArgs = argv.slice(0);
|
|
1257
|
-
break;
|
|
1258
|
-
case "eval":
|
|
1259
|
-
userArgs = argv.slice(1);
|
|
1260
|
-
break;
|
|
1261
|
-
default:
|
|
1262
|
-
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1263
|
-
}
|
|
1264
|
-
if (!this._name && this._scriptPath)
|
|
1265
|
-
this.nameFromFilename(this._scriptPath);
|
|
1266
|
-
this._name = this._name || "program";
|
|
1267
|
-
return userArgs;
|
|
1268
|
-
}
|
|
1269
|
-
parse(argv, parseOptions) {
|
|
1270
|
-
this._prepareForParse();
|
|
1271
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1272
|
-
this._parseCommand([], userArgs);
|
|
1273
|
-
return this;
|
|
1274
|
-
}
|
|
1275
|
-
async parseAsync(argv, parseOptions) {
|
|
1276
|
-
this._prepareForParse();
|
|
1277
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1278
|
-
await this._parseCommand([], userArgs);
|
|
1279
|
-
return this;
|
|
1280
|
-
}
|
|
1281
|
-
_prepareForParse() {
|
|
1282
|
-
if (this._savedState === null) {
|
|
1283
|
-
this.saveStateBeforeParse();
|
|
1284
|
-
} else {
|
|
1285
|
-
this.restoreStateBeforeParse();
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
saveStateBeforeParse() {
|
|
1289
|
-
this._savedState = {
|
|
1290
|
-
_name: this._name,
|
|
1291
|
-
_optionValues: { ...this._optionValues },
|
|
1292
|
-
_optionValueSources: { ...this._optionValueSources }
|
|
1293
|
-
};
|
|
1294
|
-
}
|
|
1295
|
-
restoreStateBeforeParse() {
|
|
1296
|
-
if (this._storeOptionsAsProperties)
|
|
1297
|
-
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
1298
|
-
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1299
|
-
this._name = this._savedState._name;
|
|
1300
|
-
this._scriptPath = null;
|
|
1301
|
-
this.rawArgs = [];
|
|
1302
|
-
this._optionValues = { ...this._savedState._optionValues };
|
|
1303
|
-
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
1304
|
-
this.args = [];
|
|
1305
|
-
this.processedArgs = [];
|
|
1306
|
-
}
|
|
1307
|
-
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1308
|
-
if (fs.existsSync(executableFile))
|
|
1309
|
-
return;
|
|
1310
|
-
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";
|
|
1311
|
-
const executableMissing = `'${executableFile}' does not exist
|
|
1312
|
-
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1313
|
-
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1314
|
-
- ${executableDirMessage}`;
|
|
1315
|
-
throw new Error(executableMissing);
|
|
1316
|
-
}
|
|
1317
|
-
_executeSubCommand(subcommand, args) {
|
|
1318
|
-
args = args.slice();
|
|
1319
|
-
let launchWithNode = false;
|
|
1320
|
-
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1321
|
-
function findFile(baseDir, baseName) {
|
|
1322
|
-
const localBin = path.resolve(baseDir, baseName);
|
|
1323
|
-
if (fs.existsSync(localBin))
|
|
1324
|
-
return localBin;
|
|
1325
|
-
if (sourceExt.includes(path.extname(baseName)))
|
|
1326
|
-
return;
|
|
1327
|
-
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1328
|
-
if (foundExt)
|
|
1329
|
-
return `${localBin}${foundExt}`;
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
this._checkForMissingMandatoryOptions();
|
|
1333
|
-
this._checkForConflictingOptions();
|
|
1334
|
-
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1335
|
-
let executableDir = this._executableDir || "";
|
|
1336
|
-
if (this._scriptPath) {
|
|
1337
|
-
let resolvedScriptPath;
|
|
1338
|
-
try {
|
|
1339
|
-
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1340
|
-
} catch {
|
|
1341
|
-
resolvedScriptPath = this._scriptPath;
|
|
1342
|
-
}
|
|
1343
|
-
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1344
|
-
}
|
|
1345
|
-
if (executableDir) {
|
|
1346
|
-
let localFile = findFile(executableDir, executableFile);
|
|
1347
|
-
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1348
|
-
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1349
|
-
if (legacyName !== this._name) {
|
|
1350
|
-
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
executableFile = localFile || executableFile;
|
|
1354
|
-
}
|
|
1355
|
-
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1356
|
-
let proc;
|
|
1357
|
-
if (process2.platform !== "win32") {
|
|
1358
|
-
if (launchWithNode) {
|
|
1359
|
-
args.unshift(executableFile);
|
|
1360
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1361
|
-
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1362
|
-
} else {
|
|
1363
|
-
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1364
|
-
}
|
|
1365
|
-
} else {
|
|
1366
|
-
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1367
|
-
args.unshift(executableFile);
|
|
1368
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1369
|
-
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1370
|
-
}
|
|
1371
|
-
if (!proc.killed) {
|
|
1372
|
-
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1373
|
-
signals.forEach((signal) => {
|
|
1374
|
-
process2.on(signal, () => {
|
|
1375
|
-
if (proc.killed === false && proc.exitCode === null) {
|
|
1376
|
-
proc.kill(signal);
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
});
|
|
1380
|
-
}
|
|
1381
|
-
const exitCallback = this._exitCallback;
|
|
1382
|
-
proc.on("close", (code) => {
|
|
1383
|
-
code = code ?? 1;
|
|
1384
|
-
if (!exitCallback) {
|
|
1385
|
-
process2.exit(code);
|
|
1386
|
-
} else {
|
|
1387
|
-
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1388
|
-
}
|
|
1389
|
-
});
|
|
1390
|
-
proc.on("error", (err) => {
|
|
1391
|
-
if (err.code === "ENOENT") {
|
|
1392
|
-
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1393
|
-
} else if (err.code === "EACCES") {
|
|
1394
|
-
throw new Error(`'${executableFile}' not executable`);
|
|
1395
|
-
}
|
|
1396
|
-
if (!exitCallback) {
|
|
1397
|
-
process2.exit(1);
|
|
1398
|
-
} else {
|
|
1399
|
-
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1400
|
-
wrappedError.nestedError = err;
|
|
1401
|
-
exitCallback(wrappedError);
|
|
1402
|
-
}
|
|
1403
|
-
});
|
|
1404
|
-
this.runningCommand = proc;
|
|
1405
|
-
}
|
|
1406
|
-
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1407
|
-
const subCommand = this._findCommand(commandName);
|
|
1408
|
-
if (!subCommand)
|
|
1409
|
-
this.help({ error: true });
|
|
1410
|
-
subCommand._prepareForParse();
|
|
1411
|
-
let promiseChain;
|
|
1412
|
-
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1413
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1414
|
-
if (subCommand._executableHandler) {
|
|
1415
|
-
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1416
|
-
} else {
|
|
1417
|
-
return subCommand._parseCommand(operands, unknown);
|
|
1418
|
-
}
|
|
1419
|
-
});
|
|
1420
|
-
return promiseChain;
|
|
1421
|
-
}
|
|
1422
|
-
_dispatchHelpCommand(subcommandName) {
|
|
1423
|
-
if (!subcommandName) {
|
|
1424
|
-
this.help();
|
|
1425
|
-
}
|
|
1426
|
-
const subCommand = this._findCommand(subcommandName);
|
|
1427
|
-
if (subCommand && !subCommand._executableHandler) {
|
|
1428
|
-
subCommand.help();
|
|
1429
|
-
}
|
|
1430
|
-
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1431
|
-
}
|
|
1432
|
-
_checkNumberOfArguments() {
|
|
1433
|
-
this.registeredArguments.forEach((arg, i) => {
|
|
1434
|
-
if (arg.required && this.args[i] == null) {
|
|
1435
|
-
this.missingArgument(arg.name());
|
|
1436
|
-
}
|
|
1437
|
-
});
|
|
1438
|
-
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1439
|
-
return;
|
|
1440
|
-
}
|
|
1441
|
-
if (this.args.length > this.registeredArguments.length) {
|
|
1442
|
-
this._excessArguments(this.args);
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
_processArguments() {
|
|
1446
|
-
const myParseArg = (argument, value, previous) => {
|
|
1447
|
-
let parsedValue = value;
|
|
1448
|
-
if (value !== null && argument.parseArg) {
|
|
1449
|
-
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1450
|
-
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1451
|
-
}
|
|
1452
|
-
return parsedValue;
|
|
1453
|
-
};
|
|
1454
|
-
this._checkNumberOfArguments();
|
|
1455
|
-
const processedArgs = [];
|
|
1456
|
-
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1457
|
-
let value = declaredArg.defaultValue;
|
|
1458
|
-
if (declaredArg.variadic) {
|
|
1459
|
-
if (index < this.args.length) {
|
|
1460
|
-
value = this.args.slice(index);
|
|
1461
|
-
if (declaredArg.parseArg) {
|
|
1462
|
-
value = value.reduce((processed, v) => {
|
|
1463
|
-
return myParseArg(declaredArg, v, processed);
|
|
1464
|
-
}, declaredArg.defaultValue);
|
|
1465
|
-
}
|
|
1466
|
-
} else if (value === undefined) {
|
|
1467
|
-
value = [];
|
|
1468
|
-
}
|
|
1469
|
-
} else if (index < this.args.length) {
|
|
1470
|
-
value = this.args[index];
|
|
1471
|
-
if (declaredArg.parseArg) {
|
|
1472
|
-
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
processedArgs[index] = value;
|
|
1476
|
-
});
|
|
1477
|
-
this.processedArgs = processedArgs;
|
|
1478
|
-
}
|
|
1479
|
-
_chainOrCall(promise, fn) {
|
|
1480
|
-
if (promise?.then && typeof promise.then === "function") {
|
|
1481
|
-
return promise.then(() => fn());
|
|
1482
|
-
}
|
|
1483
|
-
return fn();
|
|
1484
|
-
}
|
|
1485
|
-
_chainOrCallHooks(promise, event) {
|
|
1486
|
-
let result = promise;
|
|
1487
|
-
const hooks = [];
|
|
1488
|
-
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1489
|
-
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1490
|
-
hooks.push({ hookedCommand, callback });
|
|
1491
|
-
});
|
|
1492
|
-
});
|
|
1493
|
-
if (event === "postAction") {
|
|
1494
|
-
hooks.reverse();
|
|
1495
|
-
}
|
|
1496
|
-
hooks.forEach((hookDetail) => {
|
|
1497
|
-
result = this._chainOrCall(result, () => {
|
|
1498
|
-
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1499
|
-
});
|
|
1500
|
-
});
|
|
1501
|
-
return result;
|
|
1502
|
-
}
|
|
1503
|
-
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1504
|
-
let result = promise;
|
|
1505
|
-
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1506
|
-
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1507
|
-
result = this._chainOrCall(result, () => {
|
|
1508
|
-
return hook(this, subCommand);
|
|
1509
|
-
});
|
|
1510
|
-
});
|
|
1511
|
-
}
|
|
1512
|
-
return result;
|
|
1513
|
-
}
|
|
1514
|
-
_parseCommand(operands, unknown) {
|
|
1515
|
-
const parsed = this.parseOptions(unknown);
|
|
1516
|
-
this._parseOptionsEnv();
|
|
1517
|
-
this._parseOptionsImplied();
|
|
1518
|
-
operands = operands.concat(parsed.operands);
|
|
1519
|
-
unknown = parsed.unknown;
|
|
1520
|
-
this.args = operands.concat(unknown);
|
|
1521
|
-
if (operands && this._findCommand(operands[0])) {
|
|
1522
|
-
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1523
|
-
}
|
|
1524
|
-
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1525
|
-
return this._dispatchHelpCommand(operands[1]);
|
|
1526
|
-
}
|
|
1527
|
-
if (this._defaultCommandName) {
|
|
1528
|
-
this._outputHelpIfRequested(unknown);
|
|
1529
|
-
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1530
|
-
}
|
|
1531
|
-
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1532
|
-
this.help({ error: true });
|
|
1533
|
-
}
|
|
1534
|
-
this._outputHelpIfRequested(parsed.unknown);
|
|
1535
|
-
this._checkForMissingMandatoryOptions();
|
|
1536
|
-
this._checkForConflictingOptions();
|
|
1537
|
-
const checkForUnknownOptions = () => {
|
|
1538
|
-
if (parsed.unknown.length > 0) {
|
|
1539
|
-
this.unknownOption(parsed.unknown[0]);
|
|
1540
|
-
}
|
|
1541
|
-
};
|
|
1542
|
-
const commandEvent = `command:${this.name()}`;
|
|
1543
|
-
if (this._actionHandler) {
|
|
1544
|
-
checkForUnknownOptions();
|
|
1545
|
-
this._processArguments();
|
|
1546
|
-
let promiseChain;
|
|
1547
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1548
|
-
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1549
|
-
if (this.parent) {
|
|
1550
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1551
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1555
|
-
return promiseChain;
|
|
1556
|
-
}
|
|
1557
|
-
if (this.parent?.listenerCount(commandEvent)) {
|
|
1558
|
-
checkForUnknownOptions();
|
|
1559
|
-
this._processArguments();
|
|
1560
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
1561
|
-
} else if (operands.length) {
|
|
1562
|
-
if (this._findCommand("*")) {
|
|
1563
|
-
return this._dispatchSubcommand("*", operands, unknown);
|
|
1564
|
-
}
|
|
1565
|
-
if (this.listenerCount("command:*")) {
|
|
1566
|
-
this.emit("command:*", operands, unknown);
|
|
1567
|
-
} else if (this.commands.length) {
|
|
1568
|
-
this.unknownCommand();
|
|
1569
|
-
} else {
|
|
1570
|
-
checkForUnknownOptions();
|
|
1571
|
-
this._processArguments();
|
|
1572
|
-
}
|
|
1573
|
-
} else if (this.commands.length) {
|
|
1574
|
-
checkForUnknownOptions();
|
|
1575
|
-
this.help({ error: true });
|
|
1576
|
-
} else {
|
|
1577
|
-
checkForUnknownOptions();
|
|
1578
|
-
this._processArguments();
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
_findCommand(name) {
|
|
1582
|
-
if (!name)
|
|
1583
|
-
return;
|
|
1584
|
-
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1585
|
-
}
|
|
1586
|
-
_findOption(arg) {
|
|
1587
|
-
return this.options.find((option) => option.is(arg));
|
|
1588
|
-
}
|
|
1589
|
-
_checkForMissingMandatoryOptions() {
|
|
1590
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1591
|
-
cmd.options.forEach((anOption) => {
|
|
1592
|
-
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1593
|
-
cmd.missingMandatoryOptionValue(anOption);
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
_checkForConflictingLocalOptions() {
|
|
1599
|
-
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1600
|
-
const optionKey = option.attributeName();
|
|
1601
|
-
if (this.getOptionValue(optionKey) === undefined) {
|
|
1602
|
-
return false;
|
|
1603
|
-
}
|
|
1604
|
-
return this.getOptionValueSource(optionKey) !== "default";
|
|
1605
|
-
});
|
|
1606
|
-
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1607
|
-
optionsWithConflicting.forEach((option) => {
|
|
1608
|
-
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1609
|
-
if (conflictingAndDefined) {
|
|
1610
|
-
this._conflictingOption(option, conflictingAndDefined);
|
|
1611
|
-
}
|
|
1612
|
-
});
|
|
1613
|
-
}
|
|
1614
|
-
_checkForConflictingOptions() {
|
|
1615
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1616
|
-
cmd._checkForConflictingLocalOptions();
|
|
1617
|
-
});
|
|
1618
|
-
}
|
|
1619
|
-
parseOptions(args) {
|
|
1620
|
-
const operands = [];
|
|
1621
|
-
const unknown = [];
|
|
1622
|
-
let dest = operands;
|
|
1623
|
-
function maybeOption(arg) {
|
|
1624
|
-
return arg.length > 1 && arg[0] === "-";
|
|
1625
|
-
}
|
|
1626
|
-
const negativeNumberArg = (arg) => {
|
|
1627
|
-
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
|
|
1628
|
-
return false;
|
|
1629
|
-
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
1630
|
-
};
|
|
1631
|
-
let activeVariadicOption = null;
|
|
1632
|
-
let activeGroup = null;
|
|
1633
|
-
let i = 0;
|
|
1634
|
-
while (i < args.length || activeGroup) {
|
|
1635
|
-
const arg = activeGroup ?? args[i++];
|
|
1636
|
-
activeGroup = null;
|
|
1637
|
-
if (arg === "--") {
|
|
1638
|
-
if (dest === unknown)
|
|
1639
|
-
dest.push(arg);
|
|
1640
|
-
dest.push(...args.slice(i));
|
|
1641
|
-
break;
|
|
1642
|
-
}
|
|
1643
|
-
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
1644
|
-
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1645
|
-
continue;
|
|
1646
|
-
}
|
|
1647
|
-
activeVariadicOption = null;
|
|
1648
|
-
if (maybeOption(arg)) {
|
|
1649
|
-
const option = this._findOption(arg);
|
|
1650
|
-
if (option) {
|
|
1651
|
-
if (option.required) {
|
|
1652
|
-
const value = args[i++];
|
|
1653
|
-
if (value === undefined)
|
|
1654
|
-
this.optionMissingArgument(option);
|
|
1655
|
-
this.emit(`option:${option.name()}`, value);
|
|
1656
|
-
} else if (option.optional) {
|
|
1657
|
-
let value = null;
|
|
1658
|
-
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
1659
|
-
value = args[i++];
|
|
1660
|
-
}
|
|
1661
|
-
this.emit(`option:${option.name()}`, value);
|
|
1662
|
-
} else {
|
|
1663
|
-
this.emit(`option:${option.name()}`);
|
|
1664
|
-
}
|
|
1665
|
-
activeVariadicOption = option.variadic ? option : null;
|
|
1666
|
-
continue;
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1670
|
-
const option = this._findOption(`-${arg[1]}`);
|
|
1671
|
-
if (option) {
|
|
1672
|
-
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1673
|
-
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1674
|
-
} else {
|
|
1675
|
-
this.emit(`option:${option.name()}`);
|
|
1676
|
-
activeGroup = `-${arg.slice(2)}`;
|
|
1677
|
-
}
|
|
1678
|
-
continue;
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
if (/^--[^=]+=/.test(arg)) {
|
|
1682
|
-
const index = arg.indexOf("=");
|
|
1683
|
-
const option = this._findOption(arg.slice(0, index));
|
|
1684
|
-
if (option && (option.required || option.optional)) {
|
|
1685
|
-
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1686
|
-
continue;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
1690
|
-
dest = unknown;
|
|
1691
|
-
}
|
|
1692
|
-
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1693
|
-
if (this._findCommand(arg)) {
|
|
1694
|
-
operands.push(arg);
|
|
1695
|
-
unknown.push(...args.slice(i));
|
|
1696
|
-
break;
|
|
1697
|
-
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1698
|
-
operands.push(arg, ...args.slice(i));
|
|
1699
|
-
break;
|
|
1700
|
-
} else if (this._defaultCommandName) {
|
|
1701
|
-
unknown.push(arg, ...args.slice(i));
|
|
1702
|
-
break;
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
if (this._passThroughOptions) {
|
|
1706
|
-
dest.push(arg, ...args.slice(i));
|
|
1707
|
-
break;
|
|
1708
|
-
}
|
|
1709
|
-
dest.push(arg);
|
|
1710
|
-
}
|
|
1711
|
-
return { operands, unknown };
|
|
1712
|
-
}
|
|
1713
|
-
opts() {
|
|
1714
|
-
if (this._storeOptionsAsProperties) {
|
|
1715
|
-
const result = {};
|
|
1716
|
-
const len = this.options.length;
|
|
1717
|
-
for (let i = 0;i < len; i++) {
|
|
1718
|
-
const key = this.options[i].attributeName();
|
|
1719
|
-
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1720
|
-
}
|
|
1721
|
-
return result;
|
|
1722
|
-
}
|
|
1723
|
-
return this._optionValues;
|
|
1724
|
-
}
|
|
1725
|
-
optsWithGlobals() {
|
|
1726
|
-
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1727
|
-
}
|
|
1728
|
-
error(message, errorOptions) {
|
|
1729
|
-
this._outputConfiguration.outputError(`${message}
|
|
1730
|
-
`, this._outputConfiguration.writeErr);
|
|
1731
|
-
if (typeof this._showHelpAfterError === "string") {
|
|
1732
|
-
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1733
|
-
`);
|
|
1734
|
-
} else if (this._showHelpAfterError) {
|
|
1735
|
-
this._outputConfiguration.writeErr(`
|
|
1736
|
-
`);
|
|
1737
|
-
this.outputHelp({ error: true });
|
|
1738
|
-
}
|
|
1739
|
-
const config = errorOptions || {};
|
|
1740
|
-
const exitCode = config.exitCode || 1;
|
|
1741
|
-
const code = config.code || "commander.error";
|
|
1742
|
-
this._exit(exitCode, code, message);
|
|
1743
|
-
}
|
|
1744
|
-
_parseOptionsEnv() {
|
|
1745
|
-
this.options.forEach((option) => {
|
|
1746
|
-
if (option.envVar && option.envVar in process2.env) {
|
|
1747
|
-
const optionKey = option.attributeName();
|
|
1748
|
-
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1749
|
-
if (option.required || option.optional) {
|
|
1750
|
-
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1751
|
-
} else {
|
|
1752
|
-
this.emit(`optionEnv:${option.name()}`);
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
});
|
|
1757
|
-
}
|
|
1758
|
-
_parseOptionsImplied() {
|
|
1759
|
-
const dualHelper = new DualOptions(this.options);
|
|
1760
|
-
const hasCustomOptionValue = (optionKey) => {
|
|
1761
|
-
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1762
|
-
};
|
|
1763
|
-
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1764
|
-
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1765
|
-
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1766
|
-
});
|
|
1767
|
-
});
|
|
1768
|
-
}
|
|
1769
|
-
missingArgument(name) {
|
|
1770
|
-
const message = `error: missing required argument '${name}'`;
|
|
1771
|
-
this.error(message, { code: "commander.missingArgument" });
|
|
1772
|
-
}
|
|
1773
|
-
optionMissingArgument(option) {
|
|
1774
|
-
const message = `error: option '${option.flags}' argument missing`;
|
|
1775
|
-
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1776
|
-
}
|
|
1777
|
-
missingMandatoryOptionValue(option) {
|
|
1778
|
-
const message = `error: required option '${option.flags}' not specified`;
|
|
1779
|
-
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1780
|
-
}
|
|
1781
|
-
_conflictingOption(option, conflictingOption) {
|
|
1782
|
-
const findBestOptionFromValue = (option2) => {
|
|
1783
|
-
const optionKey = option2.attributeName();
|
|
1784
|
-
const optionValue = this.getOptionValue(optionKey);
|
|
1785
|
-
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1786
|
-
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1787
|
-
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1788
|
-
return negativeOption;
|
|
1789
|
-
}
|
|
1790
|
-
return positiveOption || option2;
|
|
1791
|
-
};
|
|
1792
|
-
const getErrorMessage = (option2) => {
|
|
1793
|
-
const bestOption = findBestOptionFromValue(option2);
|
|
1794
|
-
const optionKey = bestOption.attributeName();
|
|
1795
|
-
const source = this.getOptionValueSource(optionKey);
|
|
1796
|
-
if (source === "env") {
|
|
1797
|
-
return `environment variable '${bestOption.envVar}'`;
|
|
1798
|
-
}
|
|
1799
|
-
return `option '${bestOption.flags}'`;
|
|
1800
|
-
};
|
|
1801
|
-
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1802
|
-
this.error(message, { code: "commander.conflictingOption" });
|
|
1803
|
-
}
|
|
1804
|
-
unknownOption(flag) {
|
|
1805
|
-
if (this._allowUnknownOption)
|
|
1806
|
-
return;
|
|
1807
|
-
let suggestion = "";
|
|
1808
|
-
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1809
|
-
let candidateFlags = [];
|
|
1810
|
-
let command = this;
|
|
1811
|
-
do {
|
|
1812
|
-
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1813
|
-
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1814
|
-
command = command.parent;
|
|
1815
|
-
} while (command && !command._enablePositionalOptions);
|
|
1816
|
-
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1817
|
-
}
|
|
1818
|
-
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1819
|
-
this.error(message, { code: "commander.unknownOption" });
|
|
1820
|
-
}
|
|
1821
|
-
_excessArguments(receivedArgs) {
|
|
1822
|
-
if (this._allowExcessArguments)
|
|
1823
|
-
return;
|
|
1824
|
-
const expected = this.registeredArguments.length;
|
|
1825
|
-
const s = expected === 1 ? "" : "s";
|
|
1826
|
-
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1827
|
-
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1828
|
-
this.error(message, { code: "commander.excessArguments" });
|
|
1829
|
-
}
|
|
1830
|
-
unknownCommand() {
|
|
1831
|
-
const unknownName = this.args[0];
|
|
1832
|
-
let suggestion = "";
|
|
1833
|
-
if (this._showSuggestionAfterError) {
|
|
1834
|
-
const candidateNames = [];
|
|
1835
|
-
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1836
|
-
candidateNames.push(command.name());
|
|
1837
|
-
if (command.alias())
|
|
1838
|
-
candidateNames.push(command.alias());
|
|
1839
|
-
});
|
|
1840
|
-
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1841
|
-
}
|
|
1842
|
-
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1843
|
-
this.error(message, { code: "commander.unknownCommand" });
|
|
1844
|
-
}
|
|
1845
|
-
version(str, flags, description) {
|
|
1846
|
-
if (str === undefined)
|
|
1847
|
-
return this._version;
|
|
1848
|
-
this._version = str;
|
|
1849
|
-
flags = flags || "-V, --version";
|
|
1850
|
-
description = description || "output the version number";
|
|
1851
|
-
const versionOption = this.createOption(flags, description);
|
|
1852
|
-
this._versionOptionName = versionOption.attributeName();
|
|
1853
|
-
this._registerOption(versionOption);
|
|
1854
|
-
this.on("option:" + versionOption.name(), () => {
|
|
1855
|
-
this._outputConfiguration.writeOut(`${str}
|
|
1856
|
-
`);
|
|
1857
|
-
this._exit(0, "commander.version", str);
|
|
1858
|
-
});
|
|
1859
|
-
return this;
|
|
1860
|
-
}
|
|
1861
|
-
description(str, argsDescription) {
|
|
1862
|
-
if (str === undefined && argsDescription === undefined)
|
|
1863
|
-
return this._description;
|
|
1864
|
-
this._description = str;
|
|
1865
|
-
if (argsDescription) {
|
|
1866
|
-
this._argsDescription = argsDescription;
|
|
1867
|
-
}
|
|
1868
|
-
return this;
|
|
1869
|
-
}
|
|
1870
|
-
summary(str) {
|
|
1871
|
-
if (str === undefined)
|
|
1872
|
-
return this._summary;
|
|
1873
|
-
this._summary = str;
|
|
1874
|
-
return this;
|
|
1875
|
-
}
|
|
1876
|
-
alias(alias) {
|
|
1877
|
-
if (alias === undefined)
|
|
1878
|
-
return this._aliases[0];
|
|
1879
|
-
let command = this;
|
|
1880
|
-
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1881
|
-
command = this.commands[this.commands.length - 1];
|
|
1882
|
-
}
|
|
1883
|
-
if (alias === command._name)
|
|
1884
|
-
throw new Error("Command alias can't be the same as its name");
|
|
1885
|
-
const matchingCommand = this.parent?._findCommand(alias);
|
|
1886
|
-
if (matchingCommand) {
|
|
1887
|
-
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
1888
|
-
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1889
|
-
}
|
|
1890
|
-
command._aliases.push(alias);
|
|
1891
|
-
return this;
|
|
1892
|
-
}
|
|
1893
|
-
aliases(aliases) {
|
|
1894
|
-
if (aliases === undefined)
|
|
1895
|
-
return this._aliases;
|
|
1896
|
-
aliases.forEach((alias) => this.alias(alias));
|
|
1897
|
-
return this;
|
|
1898
|
-
}
|
|
1899
|
-
usage(str) {
|
|
1900
|
-
if (str === undefined) {
|
|
1901
|
-
if (this._usage)
|
|
1902
|
-
return this._usage;
|
|
1903
|
-
const args = this.registeredArguments.map((arg) => {
|
|
1904
|
-
return humanReadableArgName(arg);
|
|
1905
|
-
});
|
|
1906
|
-
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1907
|
-
}
|
|
1908
|
-
this._usage = str;
|
|
1909
|
-
return this;
|
|
1910
|
-
}
|
|
1911
|
-
name(str) {
|
|
1912
|
-
if (str === undefined)
|
|
1913
|
-
return this._name;
|
|
1914
|
-
this._name = str;
|
|
1915
|
-
return this;
|
|
1916
|
-
}
|
|
1917
|
-
helpGroup(heading) {
|
|
1918
|
-
if (heading === undefined)
|
|
1919
|
-
return this._helpGroupHeading ?? "";
|
|
1920
|
-
this._helpGroupHeading = heading;
|
|
1921
|
-
return this;
|
|
1922
|
-
}
|
|
1923
|
-
commandsGroup(heading) {
|
|
1924
|
-
if (heading === undefined)
|
|
1925
|
-
return this._defaultCommandGroup ?? "";
|
|
1926
|
-
this._defaultCommandGroup = heading;
|
|
1927
|
-
return this;
|
|
1928
|
-
}
|
|
1929
|
-
optionsGroup(heading) {
|
|
1930
|
-
if (heading === undefined)
|
|
1931
|
-
return this._defaultOptionGroup ?? "";
|
|
1932
|
-
this._defaultOptionGroup = heading;
|
|
1933
|
-
return this;
|
|
1934
|
-
}
|
|
1935
|
-
_initOptionGroup(option) {
|
|
1936
|
-
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
1937
|
-
option.helpGroup(this._defaultOptionGroup);
|
|
1938
|
-
}
|
|
1939
|
-
_initCommandGroup(cmd) {
|
|
1940
|
-
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
1941
|
-
cmd.helpGroup(this._defaultCommandGroup);
|
|
1942
|
-
}
|
|
1943
|
-
nameFromFilename(filename) {
|
|
1944
|
-
this._name = path.basename(filename, path.extname(filename));
|
|
1945
|
-
return this;
|
|
1946
|
-
}
|
|
1947
|
-
executableDir(path2) {
|
|
1948
|
-
if (path2 === undefined)
|
|
1949
|
-
return this._executableDir;
|
|
1950
|
-
this._executableDir = path2;
|
|
1951
|
-
return this;
|
|
1952
|
-
}
|
|
1953
|
-
helpInformation(contextOptions) {
|
|
1954
|
-
const helper = this.createHelp();
|
|
1955
|
-
const context = this._getOutputContext(contextOptions);
|
|
1956
|
-
helper.prepareContext({
|
|
1957
|
-
error: context.error,
|
|
1958
|
-
helpWidth: context.helpWidth,
|
|
1959
|
-
outputHasColors: context.hasColors
|
|
1960
|
-
});
|
|
1961
|
-
const text = helper.formatHelp(this, helper);
|
|
1962
|
-
if (context.hasColors)
|
|
1963
|
-
return text;
|
|
1964
|
-
return this._outputConfiguration.stripColor(text);
|
|
1965
|
-
}
|
|
1966
|
-
_getOutputContext(contextOptions) {
|
|
1967
|
-
contextOptions = contextOptions || {};
|
|
1968
|
-
const error = !!contextOptions.error;
|
|
1969
|
-
let baseWrite;
|
|
1970
|
-
let hasColors;
|
|
1971
|
-
let helpWidth;
|
|
1972
|
-
if (error) {
|
|
1973
|
-
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
1974
|
-
hasColors = this._outputConfiguration.getErrHasColors();
|
|
1975
|
-
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
1976
|
-
} else {
|
|
1977
|
-
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
1978
|
-
hasColors = this._outputConfiguration.getOutHasColors();
|
|
1979
|
-
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
1980
|
-
}
|
|
1981
|
-
const write = (str) => {
|
|
1982
|
-
if (!hasColors)
|
|
1983
|
-
str = this._outputConfiguration.stripColor(str);
|
|
1984
|
-
return baseWrite(str);
|
|
1985
|
-
};
|
|
1986
|
-
return { error, write, hasColors, helpWidth };
|
|
1987
|
-
}
|
|
1988
|
-
outputHelp(contextOptions) {
|
|
1989
|
-
let deprecatedCallback;
|
|
1990
|
-
if (typeof contextOptions === "function") {
|
|
1991
|
-
deprecatedCallback = contextOptions;
|
|
1992
|
-
contextOptions = undefined;
|
|
1993
|
-
}
|
|
1994
|
-
const outputContext = this._getOutputContext(contextOptions);
|
|
1995
|
-
const eventContext = {
|
|
1996
|
-
error: outputContext.error,
|
|
1997
|
-
write: outputContext.write,
|
|
1998
|
-
command: this
|
|
1999
|
-
};
|
|
2000
|
-
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
2001
|
-
this.emit("beforeHelp", eventContext);
|
|
2002
|
-
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
2003
|
-
if (deprecatedCallback) {
|
|
2004
|
-
helpInformation = deprecatedCallback(helpInformation);
|
|
2005
|
-
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2006
|
-
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
outputContext.write(helpInformation);
|
|
2010
|
-
if (this._getHelpOption()?.long) {
|
|
2011
|
-
this.emit(this._getHelpOption().long);
|
|
2012
|
-
}
|
|
2013
|
-
this.emit("afterHelp", eventContext);
|
|
2014
|
-
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
2015
|
-
}
|
|
2016
|
-
helpOption(flags, description) {
|
|
2017
|
-
if (typeof flags === "boolean") {
|
|
2018
|
-
if (flags) {
|
|
2019
|
-
if (this._helpOption === null)
|
|
2020
|
-
this._helpOption = undefined;
|
|
2021
|
-
if (this._defaultOptionGroup) {
|
|
2022
|
-
this._initOptionGroup(this._getHelpOption());
|
|
2023
|
-
}
|
|
2024
|
-
} else {
|
|
2025
|
-
this._helpOption = null;
|
|
2026
|
-
}
|
|
2027
|
-
return this;
|
|
2028
|
-
}
|
|
2029
|
-
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
2030
|
-
if (flags || description)
|
|
2031
|
-
this._initOptionGroup(this._helpOption);
|
|
2032
|
-
return this;
|
|
2033
|
-
}
|
|
2034
|
-
_getHelpOption() {
|
|
2035
|
-
if (this._helpOption === undefined) {
|
|
2036
|
-
this.helpOption(undefined, undefined);
|
|
2037
|
-
}
|
|
2038
|
-
return this._helpOption;
|
|
2039
|
-
}
|
|
2040
|
-
addHelpOption(option) {
|
|
2041
|
-
this._helpOption = option;
|
|
2042
|
-
this._initOptionGroup(option);
|
|
2043
|
-
return this;
|
|
2044
|
-
}
|
|
2045
|
-
help(contextOptions) {
|
|
2046
|
-
this.outputHelp(contextOptions);
|
|
2047
|
-
let exitCode = Number(process2.exitCode ?? 0);
|
|
2048
|
-
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
2049
|
-
exitCode = 1;
|
|
2050
|
-
}
|
|
2051
|
-
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2052
|
-
}
|
|
2053
|
-
addHelpText(position, text) {
|
|
2054
|
-
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
2055
|
-
if (!allowedValues.includes(position)) {
|
|
2056
|
-
throw new Error(`Unexpected value for position to addHelpText.
|
|
2057
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2058
|
-
}
|
|
2059
|
-
const helpEvent = `${position}Help`;
|
|
2060
|
-
this.on(helpEvent, (context) => {
|
|
2061
|
-
let helpStr;
|
|
2062
|
-
if (typeof text === "function") {
|
|
2063
|
-
helpStr = text({ error: context.error, command: context.command });
|
|
2064
|
-
} else {
|
|
2065
|
-
helpStr = text;
|
|
2066
|
-
}
|
|
2067
|
-
if (helpStr) {
|
|
2068
|
-
context.write(`${helpStr}
|
|
2069
|
-
`);
|
|
2070
|
-
}
|
|
2071
|
-
});
|
|
2072
|
-
return this;
|
|
2073
|
-
}
|
|
2074
|
-
_outputHelpIfRequested(args) {
|
|
2075
|
-
const helpOption = this._getHelpOption();
|
|
2076
|
-
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
2077
|
-
if (helpRequested) {
|
|
2078
|
-
this.outputHelp();
|
|
2079
|
-
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
function incrementNodeInspectorPort(args) {
|
|
2084
|
-
return args.map((arg) => {
|
|
2085
|
-
if (!arg.startsWith("--inspect")) {
|
|
2086
|
-
return arg;
|
|
2087
|
-
}
|
|
2088
|
-
let debugOption;
|
|
2089
|
-
let debugHost = "127.0.0.1";
|
|
2090
|
-
let debugPort = "9229";
|
|
2091
|
-
let match;
|
|
2092
|
-
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
2093
|
-
debugOption = match[1];
|
|
2094
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
2095
|
-
debugOption = match[1];
|
|
2096
|
-
if (/^\d+$/.test(match[3])) {
|
|
2097
|
-
debugPort = match[3];
|
|
2098
|
-
} else {
|
|
2099
|
-
debugHost = match[3];
|
|
2100
|
-
}
|
|
2101
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
2102
|
-
debugOption = match[1];
|
|
2103
|
-
debugHost = match[3];
|
|
2104
|
-
debugPort = match[4];
|
|
2105
|
-
}
|
|
2106
|
-
if (debugOption && debugPort !== "0") {
|
|
2107
|
-
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
2108
|
-
}
|
|
2109
|
-
return arg;
|
|
4
|
+
var __returnValue = (v) => v;
|
|
5
|
+
function __exportSetter(name, newValue) {
|
|
6
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
7
|
+
}
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
set: __exportSetter.bind(all, name)
|
|
2110
15
|
});
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
2114
|
-
return false;
|
|
2115
|
-
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
|
|
2116
|
-
return true;
|
|
2117
|
-
return;
|
|
2118
|
-
}
|
|
2119
|
-
exports.Command = Command;
|
|
2120
|
-
exports.useColor = useColor;
|
|
2121
|
-
});
|
|
2122
|
-
|
|
2123
|
-
// ../../node_modules/.bun/commander@14.0.3/node_modules/commander/index.js
|
|
2124
|
-
var require_commander = __commonJS((exports) => {
|
|
2125
|
-
var { Argument } = require_argument();
|
|
2126
|
-
var { Command } = require_command();
|
|
2127
|
-
var { CommanderError, InvalidArgumentError } = require_error();
|
|
2128
|
-
var { Help } = require_help();
|
|
2129
|
-
var { Option } = require_option();
|
|
2130
|
-
exports.program = new Command;
|
|
2131
|
-
exports.createCommand = (name) => new Command(name);
|
|
2132
|
-
exports.createOption = (flags, description) => new Option(flags, description);
|
|
2133
|
-
exports.createArgument = (name, description) => new Argument(name, description);
|
|
2134
|
-
exports.Command = Command;
|
|
2135
|
-
exports.Option = Option;
|
|
2136
|
-
exports.Argument = Argument;
|
|
2137
|
-
exports.Help = Help;
|
|
2138
|
-
exports.CommanderError = CommanderError;
|
|
2139
|
-
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2140
|
-
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2141
|
-
});
|
|
16
|
+
};
|
|
17
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
2142
18
|
|
|
2143
19
|
// ../../node_modules/.bun/unzipit@1.4.3/node_modules/unzipit/dist/unzipit.module.js
|
|
2144
20
|
var exports_unzipit_module = {};
|
|
@@ -2277,16 +153,16 @@ function inflate(data, buf) {
|
|
|
2277
153
|
HDIST = bitsE(data, pos + 5, 5) + 1;
|
|
2278
154
|
HCLEN = bitsE(data, pos + 10, 4) + 4;
|
|
2279
155
|
pos += 14;
|
|
2280
|
-
for (var
|
|
2281
|
-
U.itree[
|
|
2282
|
-
U.itree[
|
|
156
|
+
for (var i2 = 0;i2 < 38; i2 += 2) {
|
|
157
|
+
U.itree[i2] = 0;
|
|
158
|
+
U.itree[i2 + 1] = 0;
|
|
2283
159
|
}
|
|
2284
160
|
var tl = 1;
|
|
2285
|
-
for (var
|
|
2286
|
-
var
|
|
2287
|
-
U.itree[(U.ordr[
|
|
2288
|
-
if (
|
|
2289
|
-
tl =
|
|
161
|
+
for (var i2 = 0;i2 < HCLEN; i2++) {
|
|
162
|
+
var l2 = bitsE(data, pos + i2 * 3, 3);
|
|
163
|
+
U.itree[(U.ordr[i2] << 1) + 1] = l2;
|
|
164
|
+
if (l2 > tl)
|
|
165
|
+
tl = l2;
|
|
2290
166
|
}
|
|
2291
167
|
pos += 3 * HCLEN;
|
|
2292
168
|
makeCodes(U.itree, tl);
|
|
@@ -2347,61 +223,61 @@ function _check(buf, len) {
|
|
|
2347
223
|
}
|
|
2348
224
|
function _decodeTiny(lmap, LL, len, data, pos, tree) {
|
|
2349
225
|
var bitsE = _bitsE, get17 = _get17;
|
|
2350
|
-
var
|
|
2351
|
-
while (
|
|
226
|
+
var i2 = 0;
|
|
227
|
+
while (i2 < len) {
|
|
2352
228
|
var code = lmap[get17(data, pos) & LL];
|
|
2353
229
|
pos += code & 15;
|
|
2354
230
|
var lit = code >>> 4;
|
|
2355
231
|
if (lit <= 15) {
|
|
2356
|
-
tree[
|
|
2357
|
-
|
|
232
|
+
tree[i2] = lit;
|
|
233
|
+
i2++;
|
|
2358
234
|
} else {
|
|
2359
|
-
var ll = 0,
|
|
235
|
+
var ll = 0, n2 = 0;
|
|
2360
236
|
if (lit == 16) {
|
|
2361
|
-
|
|
237
|
+
n2 = 3 + bitsE(data, pos, 2);
|
|
2362
238
|
pos += 2;
|
|
2363
|
-
ll = tree[
|
|
239
|
+
ll = tree[i2 - 1];
|
|
2364
240
|
} else if (lit == 17) {
|
|
2365
|
-
|
|
241
|
+
n2 = 3 + bitsE(data, pos, 3);
|
|
2366
242
|
pos += 3;
|
|
2367
243
|
} else if (lit == 18) {
|
|
2368
|
-
|
|
244
|
+
n2 = 11 + bitsE(data, pos, 7);
|
|
2369
245
|
pos += 7;
|
|
2370
246
|
}
|
|
2371
|
-
var ni =
|
|
2372
|
-
while (
|
|
2373
|
-
tree[
|
|
2374
|
-
|
|
247
|
+
var ni = i2 + n2;
|
|
248
|
+
while (i2 < ni) {
|
|
249
|
+
tree[i2] = ll;
|
|
250
|
+
i2++;
|
|
2375
251
|
}
|
|
2376
252
|
}
|
|
2377
253
|
}
|
|
2378
254
|
return pos;
|
|
2379
255
|
}
|
|
2380
256
|
function _copyOut(src, off, len, tree) {
|
|
2381
|
-
var mx = 0,
|
|
2382
|
-
while (
|
|
2383
|
-
var v = src[
|
|
2384
|
-
tree[
|
|
2385
|
-
tree[(
|
|
257
|
+
var mx = 0, i2 = 0, tl = tree.length >>> 1;
|
|
258
|
+
while (i2 < len) {
|
|
259
|
+
var v = src[i2 + off];
|
|
260
|
+
tree[i2 << 1] = 0;
|
|
261
|
+
tree[(i2 << 1) + 1] = v;
|
|
2386
262
|
if (v > mx)
|
|
2387
263
|
mx = v;
|
|
2388
|
-
|
|
264
|
+
i2++;
|
|
2389
265
|
}
|
|
2390
|
-
while (
|
|
2391
|
-
tree[
|
|
2392
|
-
tree[(
|
|
2393
|
-
|
|
266
|
+
while (i2 < tl) {
|
|
267
|
+
tree[i2 << 1] = 0;
|
|
268
|
+
tree[(i2 << 1) + 1] = 0;
|
|
269
|
+
i2++;
|
|
2394
270
|
}
|
|
2395
271
|
return mx;
|
|
2396
272
|
}
|
|
2397
273
|
function makeCodes(tree, MAX_BITS) {
|
|
2398
274
|
var max_code = tree.length;
|
|
2399
|
-
var code, bits,
|
|
275
|
+
var code, bits, n2, i2, len;
|
|
2400
276
|
var bl_count = U.bl_count;
|
|
2401
|
-
for (var
|
|
2402
|
-
bl_count[
|
|
2403
|
-
for (
|
|
2404
|
-
bl_count[tree[
|
|
277
|
+
for (var i2 = 0;i2 <= MAX_BITS; i2++)
|
|
278
|
+
bl_count[i2] = 0;
|
|
279
|
+
for (i2 = 1;i2 < max_code; i2 += 2)
|
|
280
|
+
bl_count[tree[i2]]++;
|
|
2405
281
|
var next_code = U.next_code;
|
|
2406
282
|
code = 0;
|
|
2407
283
|
bl_count[0] = 0;
|
|
@@ -2409,10 +285,10 @@ function makeCodes(tree, MAX_BITS) {
|
|
|
2409
285
|
code = code + bl_count[bits - 1] << 1;
|
|
2410
286
|
next_code[bits] = code;
|
|
2411
287
|
}
|
|
2412
|
-
for (
|
|
2413
|
-
len = tree[
|
|
288
|
+
for (n2 = 0;n2 < max_code; n2 += 2) {
|
|
289
|
+
len = tree[n2 + 1];
|
|
2414
290
|
if (len != 0) {
|
|
2415
|
-
tree[
|
|
291
|
+
tree[n2] = next_code[len];
|
|
2416
292
|
next_code[len]++;
|
|
2417
293
|
}
|
|
2418
294
|
}
|
|
@@ -2420,11 +296,11 @@ function makeCodes(tree, MAX_BITS) {
|
|
|
2420
296
|
function codes2map(tree, MAX_BITS, map) {
|
|
2421
297
|
var max_code = tree.length;
|
|
2422
298
|
var r15 = U.rev15;
|
|
2423
|
-
for (var
|
|
2424
|
-
if (tree[
|
|
2425
|
-
var lit =
|
|
2426
|
-
var cl = tree[
|
|
2427
|
-
var rest = MAX_BITS - cl, i0 = tree[
|
|
299
|
+
for (var i2 = 0;i2 < max_code; i2 += 2)
|
|
300
|
+
if (tree[i2 + 1] != 0) {
|
|
301
|
+
var lit = i2 >> 1;
|
|
302
|
+
var cl = tree[i2 + 1], val = lit << 4 | cl;
|
|
303
|
+
var rest = MAX_BITS - cl, i0 = tree[i2] << rest, i1 = i0 + (1 << rest);
|
|
2428
304
|
while (i0 != i1) {
|
|
2429
305
|
var p0 = r15[i0] >>> 15 - MAX_BITS;
|
|
2430
306
|
map[p0] = val;
|
|
@@ -2434,9 +310,9 @@ function codes2map(tree, MAX_BITS, map) {
|
|
|
2434
310
|
}
|
|
2435
311
|
function revCodes(tree, MAX_BITS) {
|
|
2436
312
|
var r15 = U.rev15, imb = 15 - MAX_BITS;
|
|
2437
|
-
for (var
|
|
2438
|
-
var i0 = tree[
|
|
2439
|
-
tree[
|
|
313
|
+
for (var i2 = 0;i2 < tree.length; i2 += 2) {
|
|
314
|
+
var i0 = tree[i2] << MAX_BITS - tree[i2 + 1];
|
|
315
|
+
tree[i2] = r15[i0] >>> imb;
|
|
2440
316
|
}
|
|
2441
317
|
}
|
|
2442
318
|
function _bitsE(dt, pos, length) {
|
|
@@ -2639,11 +515,11 @@ async function findEndOfCentralDirector(reader, totalLength) {
|
|
|
2639
515
|
const size = Math.min(EOCDR_WITHOUT_COMMENT_SIZE + MAX_COMMENT_SIZE, totalLength);
|
|
2640
516
|
const readStart = totalLength - size;
|
|
2641
517
|
const data = await readAs(reader, readStart, size);
|
|
2642
|
-
for (let
|
|
2643
|
-
if (getUint32LE(data,
|
|
518
|
+
for (let i2 = size - EOCDR_WITHOUT_COMMENT_SIZE;i2 >= 0; --i2) {
|
|
519
|
+
if (getUint32LE(data, i2) !== EOCDR_SIGNATURE) {
|
|
2644
520
|
continue;
|
|
2645
521
|
}
|
|
2646
|
-
const eocdr = new Uint8Array(data.buffer, data.byteOffset +
|
|
522
|
+
const eocdr = new Uint8Array(data.buffer, data.byteOffset + i2, data.byteLength - i2);
|
|
2647
523
|
const diskNumber = getUint16LE(eocdr, 4);
|
|
2648
524
|
if (diskNumber !== 0) {
|
|
2649
525
|
throw new Error(`multi-volume zip files are not supported. This is volume: ${diskNumber}`);
|
|
@@ -2659,7 +535,7 @@ async function findEndOfCentralDirector(reader, totalLength) {
|
|
|
2659
535
|
const commentBytes = new Uint8Array(eocdr.buffer, eocdr.byteOffset + 22, commentLength);
|
|
2660
536
|
const comment = decodeBuffer(commentBytes);
|
|
2661
537
|
if (entryCount === 65535 || centralDirectoryOffset === 4294967295) {
|
|
2662
|
-
return await readZip64CentralDirectory(reader, readStart +
|
|
538
|
+
return await readZip64CentralDirectory(reader, readStart + i2, comment, commentBytes);
|
|
2663
539
|
} else {
|
|
2664
540
|
return await readEntries(reader, centralDirectoryOffset, centralDirectorySize, entryCount, comment, commentBytes);
|
|
2665
541
|
}
|
|
@@ -2719,11 +595,11 @@ async function readEntries(reader, centralDirectoryOffset, centralDirectorySize,
|
|
|
2719
595
|
const fileCommentStart = rawEntry.fileNameLength + rawEntry.extraFieldLength;
|
|
2720
596
|
const extraFieldBuffer = data.slice(rawEntry.fileNameLength, fileCommentStart);
|
|
2721
597
|
rawEntry.extraFields = [];
|
|
2722
|
-
let
|
|
2723
|
-
while (
|
|
2724
|
-
const headerId = getUint16LE(extraFieldBuffer,
|
|
2725
|
-
const dataSize = getUint16LE(extraFieldBuffer,
|
|
2726
|
-
const dataStart =
|
|
598
|
+
let i2 = 0;
|
|
599
|
+
while (i2 < extraFieldBuffer.length - 3) {
|
|
600
|
+
const headerId = getUint16LE(extraFieldBuffer, i2 + 0);
|
|
601
|
+
const dataSize = getUint16LE(extraFieldBuffer, i2 + 2);
|
|
602
|
+
const dataStart = i2 + 4;
|
|
2727
603
|
const dataEnd = dataStart + dataSize;
|
|
2728
604
|
if (dataEnd > extraFieldBuffer.length) {
|
|
2729
605
|
throw new Error("extra field length exceeds extra field buffer size");
|
|
@@ -2732,7 +608,7 @@ async function readEntries(reader, centralDirectoryOffset, centralDirectorySize,
|
|
|
2732
608
|
id: headerId,
|
|
2733
609
|
data: extraFieldBuffer.slice(dataStart, dataEnd)
|
|
2734
610
|
});
|
|
2735
|
-
|
|
611
|
+
i2 = dataEnd;
|
|
2736
612
|
}
|
|
2737
613
|
rawEntry.commentBytes = data.slice(fileCommentStart, fileCommentStart + rawEntry.fileCommentLength);
|
|
2738
614
|
rawEntry.comment = decodeBuffer(rawEntry.commentBytes);
|
|
@@ -2922,21 +798,21 @@ var init_unzipit_module = __esm(() => {
|
|
|
2922
798
|
}();
|
|
2923
799
|
(function() {
|
|
2924
800
|
var len = 1 << 15;
|
|
2925
|
-
for (var
|
|
2926
|
-
var x =
|
|
801
|
+
for (var i2 = 0;i2 < len; i2++) {
|
|
802
|
+
var x = i2;
|
|
2927
803
|
x = (x & 2863311530) >>> 1 | (x & 1431655765) << 1;
|
|
2928
804
|
x = (x & 3435973836) >>> 2 | (x & 858993459) << 2;
|
|
2929
805
|
x = (x & 4042322160) >>> 4 | (x & 252645135) << 4;
|
|
2930
806
|
x = (x & 4278255360) >>> 8 | (x & 16711935) << 8;
|
|
2931
|
-
U.rev15[
|
|
807
|
+
U.rev15[i2] = (x >>> 16 | x << 16) >>> 17;
|
|
2932
808
|
}
|
|
2933
|
-
function pushV(tgt,
|
|
2934
|
-
while (
|
|
809
|
+
function pushV(tgt, n2, sv) {
|
|
810
|
+
while (n2-- != 0)
|
|
2935
811
|
tgt.push(0, sv);
|
|
2936
812
|
}
|
|
2937
|
-
for (var
|
|
2938
|
-
U.ldef[
|
|
2939
|
-
U.ddef[
|
|
813
|
+
for (var i2 = 0;i2 < 32; i2++) {
|
|
814
|
+
U.ldef[i2] = U.of0[i2] << 3 | U.exb[i2];
|
|
815
|
+
U.ddef[i2] = U.df0[i2] << 4 | U.dxb[i2];
|
|
2940
816
|
}
|
|
2941
817
|
pushV(U.fltree, 144, 8);
|
|
2942
818
|
pushV(U.fltree, 255 - 143, 9);
|
|
@@ -2957,25 +833,25 @@ var init_unzipit_module = __esm(() => {
|
|
|
2957
833
|
crc = {
|
|
2958
834
|
table: function() {
|
|
2959
835
|
var tab = new Uint32Array(256);
|
|
2960
|
-
for (var
|
|
2961
|
-
var c =
|
|
836
|
+
for (var n2 = 0;n2 < 256; n2++) {
|
|
837
|
+
var c = n2;
|
|
2962
838
|
for (var k = 0;k < 8; k++) {
|
|
2963
839
|
if (c & 1)
|
|
2964
840
|
c = 3988292384 ^ c >>> 1;
|
|
2965
841
|
else
|
|
2966
842
|
c = c >>> 1;
|
|
2967
843
|
}
|
|
2968
|
-
tab[
|
|
844
|
+
tab[n2] = c;
|
|
2969
845
|
}
|
|
2970
846
|
return tab;
|
|
2971
847
|
}(),
|
|
2972
848
|
update: function(c, buf, off, len) {
|
|
2973
|
-
for (var
|
|
2974
|
-
c = crc.table[(c ^ buf[off +
|
|
849
|
+
for (var i2 = 0;i2 < len; i2++)
|
|
850
|
+
c = crc.table[(c ^ buf[off + i2]) & 255] ^ c >>> 8;
|
|
2975
851
|
return c;
|
|
2976
852
|
},
|
|
2977
|
-
crc: function(b,
|
|
2978
|
-
return crc.update(4294967295, b,
|
|
853
|
+
crc: function(b, o2, l2) {
|
|
854
|
+
return crc.update(4294967295, b, o2, l2) ^ 4294967295;
|
|
2979
855
|
}
|
|
2980
856
|
};
|
|
2981
857
|
config = {
|
|
@@ -3056,26 +932,259 @@ var init_unzipit_module = __esm(() => {
|
|
|
3056
932
|
utf8Decoder = new TextDecoder;
|
|
3057
933
|
});
|
|
3058
934
|
|
|
3059
|
-
// ../../node_modules/.bun/
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
935
|
+
// ../../node_modules/.bun/mri@1.2.0/node_modules/mri/lib/index.mjs
|
|
936
|
+
function toArr(any) {
|
|
937
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
938
|
+
}
|
|
939
|
+
function toVal(out, key, val, opts) {
|
|
940
|
+
var x, old = out[key], nxt = ~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
941
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
942
|
+
}
|
|
943
|
+
function lib_default(args, opts) {
|
|
944
|
+
args = args || [];
|
|
945
|
+
opts = opts || {};
|
|
946
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
947
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
948
|
+
const alibi = opts.alias !== undefined;
|
|
949
|
+
const strict = opts.unknown !== undefined;
|
|
950
|
+
const defaults = opts.default !== undefined;
|
|
951
|
+
opts.alias = opts.alias || {};
|
|
952
|
+
opts.string = toArr(opts.string);
|
|
953
|
+
opts.boolean = toArr(opts.boolean);
|
|
954
|
+
if (alibi) {
|
|
955
|
+
for (k in opts.alias) {
|
|
956
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
957
|
+
for (i = 0;i < arr.length; i++) {
|
|
958
|
+
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
for (i = opts.boolean.length;i-- > 0; ) {
|
|
963
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
964
|
+
for (j = arr.length;j-- > 0; )
|
|
965
|
+
opts.boolean.push(arr[j]);
|
|
966
|
+
}
|
|
967
|
+
for (i = opts.string.length;i-- > 0; ) {
|
|
968
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
969
|
+
for (j = arr.length;j-- > 0; )
|
|
970
|
+
opts.string.push(arr[j]);
|
|
971
|
+
}
|
|
972
|
+
if (defaults) {
|
|
973
|
+
for (k in opts.default) {
|
|
974
|
+
name = typeof opts.default[k];
|
|
975
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
976
|
+
if (opts[name] !== undefined) {
|
|
977
|
+
opts[name].push(k);
|
|
978
|
+
for (i = 0;i < arr.length; i++) {
|
|
979
|
+
opts[name].push(arr[i]);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
985
|
+
for (i = 0;i < len; i++) {
|
|
986
|
+
arg = args[i];
|
|
987
|
+
if (arg === "--") {
|
|
988
|
+
out._ = out._.concat(args.slice(++i));
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
for (j = 0;j < arg.length; j++) {
|
|
992
|
+
if (arg.charCodeAt(j) !== 45)
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
if (j === 0) {
|
|
996
|
+
out._.push(arg);
|
|
997
|
+
} else if (arg.substring(j, j + 3) === "no-") {
|
|
998
|
+
name = arg.substring(j + 3);
|
|
999
|
+
if (strict && !~keys.indexOf(name)) {
|
|
1000
|
+
return opts.unknown(arg);
|
|
1001
|
+
}
|
|
1002
|
+
out[name] = false;
|
|
1003
|
+
} else {
|
|
1004
|
+
for (idx = j + 1;idx < arg.length; idx++) {
|
|
1005
|
+
if (arg.charCodeAt(idx) === 61)
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
name = arg.substring(j, idx);
|
|
1009
|
+
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
|
|
1010
|
+
arr = j === 2 ? [name] : name;
|
|
1011
|
+
for (idx = 0;idx < arr.length; idx++) {
|
|
1012
|
+
name = arr[idx];
|
|
1013
|
+
if (strict && !~keys.indexOf(name))
|
|
1014
|
+
return opts.unknown("-".repeat(j) + name);
|
|
1015
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (defaults) {
|
|
1020
|
+
for (k in opts.default) {
|
|
1021
|
+
if (out[k] === undefined) {
|
|
1022
|
+
out[k] = opts.default[k];
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
if (alibi) {
|
|
1027
|
+
for (k in out) {
|
|
1028
|
+
arr = opts.alias[k] || [];
|
|
1029
|
+
while (arr.length > 0) {
|
|
1030
|
+
out[arr.shift()] = out[k];
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
return out;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// ../../node_modules/.bun/sade@1.8.1/node_modules/sade/lib/index.mjs
|
|
1038
|
+
var t = "__all__";
|
|
1039
|
+
var i = "__default__";
|
|
1040
|
+
var s = `
|
|
1041
|
+
`;
|
|
1042
|
+
function r(e) {
|
|
1043
|
+
if (!e.length)
|
|
1044
|
+
return "";
|
|
1045
|
+
let t2 = function(e2) {
|
|
1046
|
+
let t3 = 0, i2 = 0, s2 = 0, r2 = e2.length;
|
|
1047
|
+
if (r2)
|
|
1048
|
+
for (;r2--; )
|
|
1049
|
+
i2 = e2[r2].length, i2 > t3 && (s2 = r2, t3 = i2);
|
|
1050
|
+
return e2[s2].length;
|
|
1051
|
+
}(e.map((e2) => e2[0])) + 4;
|
|
1052
|
+
return e.map((e2) => e2[0] + " ".repeat(t2 - e2[0].length) + e2[1] + (e2[2] == null ? "" : ` (default ${e2[2]})`));
|
|
1053
|
+
}
|
|
1054
|
+
function n(e) {
|
|
1055
|
+
return e;
|
|
1056
|
+
}
|
|
1057
|
+
function l(e, t2, i2) {
|
|
1058
|
+
if (!t2 || !t2.length)
|
|
1059
|
+
return "";
|
|
1060
|
+
let r2 = 0, n2 = "";
|
|
1061
|
+
for (n2 += `
|
|
1062
|
+
` + e;r2 < t2.length; r2++)
|
|
1063
|
+
n2 += `
|
|
1064
|
+
` + i2(t2[r2]);
|
|
1065
|
+
return n2 + s;
|
|
1066
|
+
}
|
|
1067
|
+
function a(e, t2, i2 = 1) {
|
|
1068
|
+
let s2 = l("ERROR", [t2], n);
|
|
1069
|
+
s2 += `
|
|
1070
|
+
Run \`$ ${e} --help\` for more info.
|
|
1071
|
+
`, console.error(s2), process.exit(i2);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
class o {
|
|
1075
|
+
constructor(e, s2) {
|
|
1076
|
+
let [r2, ...n2] = e.split(/\s+/);
|
|
1077
|
+
s2 = s2 || n2.length > 0, this.bin = r2, this.ver = "0.0.0", this.default = "", this.tree = {}, this.command(t), this.command([i].concat(s2 ? n2 : "<command>").join(" ")), this.single = s2, this.curr = "";
|
|
1078
|
+
}
|
|
1079
|
+
command(e, t2, i2 = {}) {
|
|
1080
|
+
if (this.single)
|
|
1081
|
+
throw new Error('Disable "single" mode to add commands');
|
|
1082
|
+
let s2 = [], r2 = [], n2 = /(\[|<)/;
|
|
1083
|
+
if (e.split(/\s+/).forEach((e2) => {
|
|
1084
|
+
(n2.test(e2.charAt(0)) ? r2 : s2).push(e2);
|
|
1085
|
+
}), s2 = s2.join(" "), s2 in this.tree)
|
|
1086
|
+
throw new Error("Command already exists: " + s2);
|
|
1087
|
+
return s2.includes("__") || r2.unshift(s2), r2 = r2.join(" "), this.curr = s2, i2.default && (this.default = s2), this.tree[s2] = { usage: r2, alibi: [], options: [], alias: {}, default: {}, examples: [] }, i2.alias && this.alias(i2.alias), t2 && this.describe(t2), this;
|
|
1088
|
+
}
|
|
1089
|
+
describe(e) {
|
|
1090
|
+
return this.tree[this.curr || i].describe = Array.isArray(e) ? e : function(e2) {
|
|
1091
|
+
return (e2 || "").replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|");
|
|
1092
|
+
}(e), this;
|
|
1093
|
+
}
|
|
1094
|
+
alias(...e) {
|
|
1095
|
+
if (this.single)
|
|
1096
|
+
throw new Error('Cannot call `alias()` in "single" mode');
|
|
1097
|
+
if (!this.curr)
|
|
1098
|
+
throw new Error("Cannot call `alias()` before defining a command");
|
|
1099
|
+
return (this.tree[this.curr].alibi = this.tree[this.curr].alibi.concat(...e)).forEach((e2) => this.tree[e2] = this.curr), this;
|
|
1100
|
+
}
|
|
1101
|
+
option(e, i2, s2) {
|
|
1102
|
+
let r2 = this.tree[this.curr || t], [n2, l2] = function(e2) {
|
|
1103
|
+
return (e2 || "").split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean);
|
|
1104
|
+
}(e);
|
|
1105
|
+
if (l2 && l2.length > 1 && ([n2, l2] = [l2, n2]), e = "--" + n2, l2 && l2.length > 0) {
|
|
1106
|
+
e = `-${l2}, ${e}`;
|
|
1107
|
+
let t2 = r2.alias[l2];
|
|
1108
|
+
r2.alias[l2] = (t2 || []).concat(n2);
|
|
1109
|
+
}
|
|
1110
|
+
let a2 = [e, i2 || ""];
|
|
1111
|
+
return s2 !== undefined ? (a2.push(s2), r2.default[n2] = s2) : l2 || (r2.default[n2] = undefined), r2.options.push(a2), this;
|
|
1112
|
+
}
|
|
1113
|
+
action(e) {
|
|
1114
|
+
return this.tree[this.curr || i].handler = e, this;
|
|
1115
|
+
}
|
|
1116
|
+
example(e) {
|
|
1117
|
+
return this.tree[this.curr || i].examples.push(e), this;
|
|
1118
|
+
}
|
|
1119
|
+
version(e) {
|
|
1120
|
+
return this.ver = e, this;
|
|
1121
|
+
}
|
|
1122
|
+
parse(s2, r2 = {}) {
|
|
1123
|
+
s2 = s2.slice();
|
|
1124
|
+
let n2, l2, o2, h, u = 2, f = lib_default(s2.slice(u), { alias: { h: "help", v: "version" } }), c = this.single, p = this.bin, d = "";
|
|
1125
|
+
if (c)
|
|
1126
|
+
h = this.tree[i];
|
|
1127
|
+
else {
|
|
1128
|
+
let e, t2 = 1, i2 = f._.length + 1;
|
|
1129
|
+
for (;t2 < i2; t2++)
|
|
1130
|
+
if (n2 = f._.slice(0, t2).join(" "), e = this.tree[n2], typeof e == "string")
|
|
1131
|
+
l2 = (d = e).split(" "), s2.splice(s2.indexOf(f._[0]), t2, ...l2), t2 += l2.length - t2;
|
|
1132
|
+
else if (e)
|
|
1133
|
+
d = n2;
|
|
1134
|
+
else if (d)
|
|
1135
|
+
break;
|
|
1136
|
+
if (h = this.tree[d], o2 = h === undefined, o2) {
|
|
1137
|
+
if (this.default)
|
|
1138
|
+
d = this.default, h = this.tree[d], s2.unshift(d), u++;
|
|
1139
|
+
else if (n2)
|
|
1140
|
+
return a(p, "Invalid command: " + n2);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
if (f.help)
|
|
1144
|
+
return this.help(!c && !o2 && d);
|
|
1145
|
+
if (f.version)
|
|
1146
|
+
return this._version();
|
|
1147
|
+
if (!c && h === undefined)
|
|
1148
|
+
return a(p, "No command specified.");
|
|
1149
|
+
let g = this.tree[t];
|
|
1150
|
+
r2.alias = Object.assign(g.alias, h.alias, r2.alias), r2.default = Object.assign(g.default, h.default, r2.default), n2 = d.split(" "), l2 = s2.indexOf(n2[0], 2), ~l2 && s2.splice(l2, n2.length);
|
|
1151
|
+
let m = lib_default(s2.slice(u), r2);
|
|
1152
|
+
if (!m || typeof m == "string")
|
|
1153
|
+
return a(p, m || "Parsed unknown option flag(s)!");
|
|
1154
|
+
let b = h.usage.split(/\s+/), _ = b.filter((e) => e.charAt(0) === "<"), v = m._.splice(0, _.length);
|
|
1155
|
+
if (v.length < _.length)
|
|
1156
|
+
return d && (p += " " + d), a(p, "Insufficient arguments!");
|
|
1157
|
+
b.filter((e) => e.charAt(0) === "[").forEach((e) => {
|
|
1158
|
+
v.push(m._.shift());
|
|
1159
|
+
}), v.push(m);
|
|
1160
|
+
let $ = h.handler;
|
|
1161
|
+
return r2.lazy ? { args: v, name: d, handler: $ } : $.apply(null, v);
|
|
1162
|
+
}
|
|
1163
|
+
help(e) {
|
|
1164
|
+
console.log(function(e2, a2, o2, h) {
|
|
1165
|
+
let u = "", f = a2[o2], c = "$ " + e2, p = a2[t], d = (e3) => `${c} ${e3}`.replace(/\s+/g, " "), g = [["-h, --help", "Displays this message"]];
|
|
1166
|
+
if (o2 === i && g.unshift(["-v, --version", "Displays current version"]), f.options = (f.options || []).concat(p.options, g), f.options.length > 0 && (f.usage += " [options]"), u += l("Description", f.describe, n), u += l("Usage", [f.usage], d), h || o2 !== i)
|
|
1167
|
+
h || o2 === i || (u += l("Aliases", f.alibi, d));
|
|
1168
|
+
else {
|
|
1169
|
+
let e3, t2 = /^__/, i2 = "", o3 = [];
|
|
1170
|
+
for (e3 in a2)
|
|
1171
|
+
typeof a2[e3] == "string" || t2.test(e3) || o3.push([e3, (a2[e3].describe || [""])[0]]) < 3 && (i2 += `
|
|
1172
|
+
${c} ${e3} --help`);
|
|
1173
|
+
u += l("Available Commands", r(o3), n), u += "\n For more info, run any command with the `--help` flag" + i2 + s;
|
|
1174
|
+
}
|
|
1175
|
+
return u += l("Options", r(f.options), n), u += l("Examples", f.examples.map(d), n), u;
|
|
1176
|
+
}(this.bin, this.tree, e || i, this.single));
|
|
1177
|
+
}
|
|
1178
|
+
_version() {
|
|
1179
|
+
console.log(`${this.bin}, ${this.ver}`);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
var lib_default2 = (e, t2) => new o(e, t2);
|
|
3074
1183
|
// package.json
|
|
3075
1184
|
var package_default = {
|
|
3076
1185
|
name: "@v5x/cli",
|
|
3077
|
-
description: "modern v5
|
|
3078
|
-
version: "0.0.
|
|
1186
|
+
description: "modern v5 tools",
|
|
1187
|
+
version: "0.0.21",
|
|
3079
1188
|
module: "dist/index.js",
|
|
3080
1189
|
type: "module",
|
|
3081
1190
|
bin: {
|
|
@@ -3102,8 +1211,8 @@ var package_default = {
|
|
|
3102
1211
|
"bun-serialport": "^0.1.1",
|
|
3103
1212
|
chalk: "^5.6.2",
|
|
3104
1213
|
"cmd-table": "^1.6.0",
|
|
3105
|
-
|
|
3106
|
-
|
|
1214
|
+
fflate: "^0.8.3",
|
|
1215
|
+
sade: "^1.8.1"
|
|
3107
1216
|
}
|
|
3108
1217
|
};
|
|
3109
1218
|
|
|
@@ -3698,7 +1807,7 @@ class PacketView extends DataView {
|
|
|
3698
1807
|
}
|
|
3699
1808
|
nextString(length) {
|
|
3700
1809
|
let result = "";
|
|
3701
|
-
for (let
|
|
1810
|
+
for (let i2 = 0;i2 < length; i2++) {
|
|
3702
1811
|
result += String.fromCharCode(this.nextUint8());
|
|
3703
1812
|
}
|
|
3704
1813
|
return result;
|
|
@@ -3706,7 +1815,7 @@ class PacketView extends DataView {
|
|
|
3706
1815
|
nextNTBS(length) {
|
|
3707
1816
|
let result = "";
|
|
3708
1817
|
const lastPosition = this.position;
|
|
3709
|
-
for (let
|
|
1818
|
+
for (let i2 = 0;i2 < length; i2++) {
|
|
3710
1819
|
if (this.byteLength <= this.position)
|
|
3711
1820
|
break;
|
|
3712
1821
|
const g = this.nextUint8();
|
|
@@ -3719,7 +1828,7 @@ class PacketView extends DataView {
|
|
|
3719
1828
|
}
|
|
3720
1829
|
nextVarNTBS(length) {
|
|
3721
1830
|
let result = "";
|
|
3722
|
-
for (let
|
|
1831
|
+
for (let i2 = 0;i2 < length; i2++) {
|
|
3723
1832
|
if (this.byteLength <= this.position)
|
|
3724
1833
|
break;
|
|
3725
1834
|
const g = this.nextUint8();
|
|
@@ -4002,37 +2111,37 @@ class CrcGenerator {
|
|
|
4002
2111
|
crc16(buf, initValue) {
|
|
4003
2112
|
const numberOfBytes = buf.byteLength;
|
|
4004
2113
|
let accumulator = initValue;
|
|
4005
|
-
let
|
|
2114
|
+
let i2;
|
|
4006
2115
|
let j;
|
|
4007
2116
|
for (j = 0;j < numberOfBytes; j++) {
|
|
4008
|
-
|
|
4009
|
-
accumulator = (accumulator << 8 ^ CRC16TABLE[
|
|
2117
|
+
i2 = (accumulator >>> 8 ^ buf[j]) & 255;
|
|
2118
|
+
accumulator = (accumulator << 8 ^ CRC16TABLE[i2]) >>> 0;
|
|
4010
2119
|
}
|
|
4011
2120
|
return (accumulator & 65535) >>> 0;
|
|
4012
2121
|
}
|
|
4013
2122
|
crc32GenTable() {
|
|
4014
|
-
let
|
|
2123
|
+
let i2;
|
|
4015
2124
|
let j;
|
|
4016
2125
|
let crcAccumulator;
|
|
4017
|
-
for (
|
|
4018
|
-
crcAccumulator =
|
|
2126
|
+
for (i2 = 0;i2 < 256; i2++) {
|
|
2127
|
+
crcAccumulator = i2 << 24;
|
|
4019
2128
|
for (j = 0;j < 8; j++) {
|
|
4020
2129
|
if ((crcAccumulator & 2147483648) !== 0)
|
|
4021
2130
|
crcAccumulator = crcAccumulator << 1 ^ CrcGenerator.POLYNOMIAL_CRC32;
|
|
4022
2131
|
else
|
|
4023
2132
|
crcAccumulator = crcAccumulator << 1;
|
|
4024
2133
|
}
|
|
4025
|
-
this.crc32Table[
|
|
2134
|
+
this.crc32Table[i2] = crcAccumulator;
|
|
4026
2135
|
}
|
|
4027
2136
|
}
|
|
4028
2137
|
crc32(buf, initValue) {
|
|
4029
2138
|
const numberOfBytes = buf.byteLength;
|
|
4030
2139
|
let crcAccumulator = initValue;
|
|
4031
|
-
let
|
|
2140
|
+
let i2;
|
|
4032
2141
|
let j;
|
|
4033
2142
|
for (j = 0;j < numberOfBytes; j++) {
|
|
4034
|
-
|
|
4035
|
-
crcAccumulator = (crcAccumulator << 8 ^ this.crc32Table[
|
|
2143
|
+
i2 = (crcAccumulator >>> 24 ^ buf[j]) & 255;
|
|
2144
|
+
crcAccumulator = (crcAccumulator << 8 ^ this.crc32Table[i2]) >>> 0;
|
|
4036
2145
|
}
|
|
4037
2146
|
return (crcAccumulator & 4294967295) >>> 0;
|
|
4038
2147
|
}
|
|
@@ -4117,13 +2226,13 @@ class PacketEncoder {
|
|
|
4117
2226
|
return this.crcgen.crc16(message, 0) === lastTwoBytes;
|
|
4118
2227
|
}
|
|
4119
2228
|
getPayloadSize(data) {
|
|
4120
|
-
let
|
|
4121
|
-
let
|
|
4122
|
-
if ((128 &
|
|
4123
|
-
|
|
4124
|
-
|
|
2229
|
+
let t2 = 0;
|
|
2230
|
+
let a2 = data[3];
|
|
2231
|
+
if ((128 & a2) !== 0) {
|
|
2232
|
+
t2 = 127 & a2;
|
|
2233
|
+
a2 = data[4];
|
|
4125
2234
|
}
|
|
4126
|
-
return (
|
|
2235
|
+
return (t2 << 8) + a2;
|
|
4127
2236
|
}
|
|
4128
2237
|
}
|
|
4129
2238
|
PacketEncoder.HEADERS_LENGTH = 4;
|
|
@@ -4215,9 +2324,9 @@ GetRadioModeH2DPacket.COMMAND_ID = 88;
|
|
|
4215
2324
|
GetRadioModeH2DPacket.COMMAND_EXTENDED_ID = 65;
|
|
4216
2325
|
|
|
4217
2326
|
class FileControlH2DPacket extends DeviceBoundPacket {
|
|
4218
|
-
constructor(
|
|
2327
|
+
constructor(a2, b) {
|
|
4219
2328
|
const payload = new Uint8Array(2);
|
|
4220
|
-
payload.set([
|
|
2329
|
+
payload.set([a2, b], 0);
|
|
4221
2330
|
super(payload);
|
|
4222
2331
|
}
|
|
4223
2332
|
}
|
|
@@ -4604,11 +2713,11 @@ class HostBoundPacket extends Packet {
|
|
|
4604
2713
|
super(data);
|
|
4605
2714
|
this.ack = AckType.CDC2_NACK;
|
|
4606
2715
|
this.payloadSize = Packet.ENCODER.getPayloadSize(this.data);
|
|
4607
|
-
const
|
|
4608
|
-
this.ack = this.data[this.ackIndex =
|
|
2716
|
+
const n2 = this.payloadSize > 128 ? 5 : 4;
|
|
2717
|
+
this.ack = this.data[this.ackIndex = n2 + 1];
|
|
4609
2718
|
}
|
|
4610
|
-
static isValidPacket(data,
|
|
4611
|
-
const ack = data[
|
|
2719
|
+
static isValidPacket(data, n2) {
|
|
2720
|
+
const ack = data[n2 + 1];
|
|
4612
2721
|
return ack === AckType.CDC2_ACK || ack === 167;
|
|
4613
2722
|
}
|
|
4614
2723
|
}
|
|
@@ -4651,7 +2760,7 @@ class MatchStatusReplyD2HPacket extends HostBoundPacket {
|
|
|
4651
2760
|
constructor(data) {
|
|
4652
2761
|
super(data);
|
|
4653
2762
|
const dataView = PacketView.fromPacket(this);
|
|
4654
|
-
const
|
|
2763
|
+
const n2 = this.ackIndex;
|
|
4655
2764
|
this.rssi = dataView.nextInt8();
|
|
4656
2765
|
this.systemStatusBits = dataView.nextUint16();
|
|
4657
2766
|
this.radioStatusBits = dataView.nextUint16();
|
|
@@ -4667,9 +2776,9 @@ class MatchStatusReplyD2HPacket extends HostBoundPacket {
|
|
|
4667
2776
|
this.radioChannel = dataView.nextUint8();
|
|
4668
2777
|
this.radioSlot = dataView.nextUint8();
|
|
4669
2778
|
this.robotName = dataView.nextNTBS(10);
|
|
4670
|
-
this.controllerFlags = dataView.getUint8(
|
|
4671
|
-
this.rxSignalQuality = dataView.getUint8(
|
|
4672
|
-
let rawStr = new TextDecoder("UTF-8").decode(data.slice(
|
|
2779
|
+
this.controllerFlags = dataView.getUint8(n2 + 28);
|
|
2780
|
+
this.rxSignalQuality = dataView.getUint8(n2 + 29);
|
|
2781
|
+
let rawStr = new TextDecoder("UTF-8").decode(data.slice(n2 + 18, n2 + this.payloadSize + 28));
|
|
4673
2782
|
const endIdx = rawStr.indexOf("\x00");
|
|
4674
2783
|
if (endIdx > -1) {
|
|
4675
2784
|
rawStr = rawStr.substr(0, endIdx);
|
|
@@ -4711,13 +2820,13 @@ class ReadFileReplyD2HPacket extends HostBoundPacket {
|
|
|
4711
2820
|
constructor(data) {
|
|
4712
2821
|
super(data);
|
|
4713
2822
|
const dataView = PacketView.fromPacket(this);
|
|
4714
|
-
const
|
|
4715
|
-
this.addr = dataView.getUint32(
|
|
2823
|
+
const n2 = this.ackIndex;
|
|
2824
|
+
this.addr = dataView.getUint32(n2, true);
|
|
4716
2825
|
this.length = this.payloadSize - 7;
|
|
4717
|
-
this.buf = data.slice(
|
|
2826
|
+
this.buf = data.slice(n2 + 4, n2 + 4 + this.length);
|
|
4718
2827
|
}
|
|
4719
|
-
static isValidPacket(data,
|
|
4720
|
-
return data[4] === 4 ? data[
|
|
2828
|
+
static isValidPacket(data, n2) {
|
|
2829
|
+
return data[4] === 4 ? data[n2 + 1] === AckType.CDC2_ACK : true;
|
|
4721
2830
|
}
|
|
4722
2831
|
}
|
|
4723
2832
|
ReadFileReplyD2HPacket.COMMAND_ID = 86;
|
|
@@ -4856,7 +2965,7 @@ class GetDeviceStatusReplyD2HPacket extends HostBoundPacket {
|
|
|
4856
2965
|
const dataView = PacketView.fromPacket(this);
|
|
4857
2966
|
this.count = dataView.nextUint8();
|
|
4858
2967
|
this.devices = [];
|
|
4859
|
-
for (let
|
|
2968
|
+
for (let i2 = 0;i2 < this.count; i2++) {
|
|
4860
2969
|
this.devices.push({
|
|
4861
2970
|
port: dataView.nextUint8(),
|
|
4862
2971
|
type: dataView.nextUint8(),
|
|
@@ -4918,7 +3027,7 @@ class GetFdtStatusReplyD2HPacket extends HostBoundPacket {
|
|
|
4918
3027
|
const dataView = PacketView.fromPacket(this);
|
|
4919
3028
|
this.count = dataView.nextUint8();
|
|
4920
3029
|
this.status = [];
|
|
4921
|
-
for (let
|
|
3030
|
+
for (let i2 = 0;i2 < this.count; i2++) {
|
|
4922
3031
|
this.status.push({
|
|
4923
3032
|
index: dataView.nextUint8(),
|
|
4924
3033
|
type: dataView.nextUint8(),
|
|
@@ -4948,13 +3057,13 @@ class ReadLogPageReplyD2HPacket extends HostBoundPacket {
|
|
|
4948
3057
|
constructor(data) {
|
|
4949
3058
|
super(data);
|
|
4950
3059
|
const dataView = PacketView.fromPacket(this);
|
|
4951
|
-
const
|
|
3060
|
+
const n2 = this.ackIndex;
|
|
4952
3061
|
const size = dataView.nextUint8();
|
|
4953
3062
|
this.offset = dataView.nextUint32();
|
|
4954
3063
|
this.count = dataView.nextUint16();
|
|
4955
3064
|
this.entries = [];
|
|
4956
|
-
let j =
|
|
4957
|
-
for (let
|
|
3065
|
+
let j = n2 + 8;
|
|
3066
|
+
for (let i2 = 0;i2 < this.count; i2++) {
|
|
4958
3067
|
this.entries.push({
|
|
4959
3068
|
code: dataView.getUint8(j),
|
|
4960
3069
|
type: dataView.getUint8(j + 1),
|
|
@@ -4973,12 +3082,12 @@ class GetRadioStatusReplyD2HPacket extends HostBoundPacket {
|
|
|
4973
3082
|
constructor(data) {
|
|
4974
3083
|
super(data);
|
|
4975
3084
|
const dataView = PacketView.fromPacket(this);
|
|
4976
|
-
const
|
|
3085
|
+
const n2 = this.ackIndex;
|
|
4977
3086
|
this.device = dataView.nextUint8();
|
|
4978
3087
|
this.quality = dataView.nextUint16();
|
|
4979
3088
|
this.strength = dataView.nextInt16();
|
|
4980
|
-
this.channel = this.data[
|
|
4981
|
-
this.timeslot = this.data[
|
|
3089
|
+
this.channel = this.data[n2 + 6];
|
|
3090
|
+
this.timeslot = this.data[n2 + 7];
|
|
4982
3091
|
}
|
|
4983
3092
|
}
|
|
4984
3093
|
GetRadioStatusReplyD2HPacket.COMMAND_ID = 86;
|
|
@@ -5035,15 +3144,15 @@ class GetSlot1to4InfoReplyD2HPacket extends HostBoundPacket {
|
|
|
5035
3144
|
const dataView = PacketView.fromPacket(this);
|
|
5036
3145
|
this.slotFlags = dataView.nextUint8();
|
|
5037
3146
|
this.slots = [];
|
|
5038
|
-
for (let
|
|
5039
|
-
const hasData = (this.slotFlags & Math.pow(2, start - 1 +
|
|
3147
|
+
for (let i2 = 0;i2 < 4; i2++) {
|
|
3148
|
+
const hasData = (this.slotFlags & Math.pow(2, start - 1 + i2)) !== 0;
|
|
5040
3149
|
if (!hasData)
|
|
5041
3150
|
continue;
|
|
5042
3151
|
const iconNum = dataView.nextUint16();
|
|
5043
3152
|
const nameLen = dataView.nextUint8();
|
|
5044
3153
|
const name = dataView.nextString(nameLen);
|
|
5045
3154
|
this.slots.push({
|
|
5046
|
-
slot: start +
|
|
3155
|
+
slot: start + i2,
|
|
5047
3156
|
icon: iconNum,
|
|
5048
3157
|
name
|
|
5049
3158
|
});
|
|
@@ -5211,14 +3320,14 @@ class VexSerialConnection extends VexEventTarget {
|
|
|
5211
3320
|
if (!thePacketEncoder.validateHeader(cache))
|
|
5212
3321
|
throw new Error("Invalid header");
|
|
5213
3322
|
const payloadExpectedSize = thePacketEncoder.getPayloadSize(cache);
|
|
5214
|
-
const
|
|
5215
|
-
const totalSize =
|
|
3323
|
+
const n2 = payloadExpectedSize > 128 ? 5 : 4;
|
|
3324
|
+
const totalSize = n2 + payloadExpectedSize;
|
|
5216
3325
|
cache = yield this.readData(cache, totalSize);
|
|
5217
3326
|
sliceIdx = totalSize;
|
|
5218
3327
|
const cmdId = cache[2];
|
|
5219
3328
|
const hasExtId = cmdId === 88 || cmdId === 86;
|
|
5220
|
-
const cmdExId = hasExtId ? cache[
|
|
5221
|
-
const ack = cache[
|
|
3329
|
+
const cmdExId = hasExtId ? cache[n2] : undefined;
|
|
3330
|
+
const ack = cache[n2 + 1];
|
|
5222
3331
|
if (hasExtId) {
|
|
5223
3332
|
if (!thePacketEncoder.validateMessageCdc(cache))
|
|
5224
3333
|
throw new Error("Invalid message CDC");
|
|
@@ -5244,7 +3353,7 @@ class VexSerialConnection extends VexEventTarget {
|
|
|
5244
3353
|
if (wantedCmdId === undefined && wantedCmdExId === undefined || PackageType === undefined) {
|
|
5245
3354
|
callbackInfo.callback(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
|
|
5246
3355
|
} else {
|
|
5247
|
-
if (!hasExtId || PackageType.isValidPacket(data,
|
|
3356
|
+
if (!hasExtId || PackageType.isValidPacket(data, n2)) {
|
|
5248
3357
|
callbackInfo.callback(new PackageType(data));
|
|
5249
3358
|
} else {
|
|
5250
3359
|
console.warn("ack", ack);
|
|
@@ -5477,10 +3586,10 @@ function logData(data, limitedSize) {
|
|
|
5477
3586
|
if (data === undefined)
|
|
5478
3587
|
return;
|
|
5479
3588
|
limitedSize || (limitedSize = data.length);
|
|
5480
|
-
let
|
|
5481
|
-
for (let
|
|
5482
|
-
|
|
5483
|
-
limitedSize < data.length && (
|
|
3589
|
+
let a2 = "";
|
|
3590
|
+
for (let n2 = 0;n2 < data.length && n2 < limitedSize; n2++)
|
|
3591
|
+
a2 += ("00" + data[n2].toString(16)).substr(-2, 2) + " ";
|
|
3592
|
+
limitedSize < data.length && (a2 += " ... ");
|
|
5484
3593
|
}
|
|
5485
3594
|
function binaryArrayJoin(left, right) {
|
|
5486
3595
|
const leftSize = left != null ? left.byteLength : 0;
|
|
@@ -5690,8 +3799,8 @@ class V5Brain {
|
|
|
5690
3799
|
if (!(result instanceof GetDirectoryFileCountReplyD2HPacket))
|
|
5691
3800
|
return;
|
|
5692
3801
|
const files = [];
|
|
5693
|
-
for (let
|
|
5694
|
-
const result2 = yield conn.writeDataAsync(new GetDirectoryEntryH2DPacket(
|
|
3802
|
+
for (let i2 = 0;i2 < result.count; i2++) {
|
|
3803
|
+
const result2 = yield conn.writeDataAsync(new GetDirectoryEntryH2DPacket(i2));
|
|
5695
3804
|
if (!(result2 instanceof GetDirectoryEntryReplyD2HPacket))
|
|
5696
3805
|
return;
|
|
5697
3806
|
if (result2.file != null) {
|
|
@@ -5724,30 +3833,30 @@ class V5Brain {
|
|
|
5724
3833
|
var _a2;
|
|
5725
3834
|
return (_a2 = (file === null || file === undefined ? undefined : file.filename.search(/.ini$/)) > 0) !== null && _a2 !== undefined ? _a2 : false;
|
|
5726
3835
|
});
|
|
5727
|
-
for (let
|
|
5728
|
-
const ini = iniFiles[
|
|
3836
|
+
for (let i2 = 0;i2 < iniFiles.length; i2++) {
|
|
3837
|
+
const ini = iniFiles[i2];
|
|
5729
3838
|
if (ini.size === 0)
|
|
5730
3839
|
continue;
|
|
5731
3840
|
const programName = (_b = (_a = /(.+?)(\.[^.]*$|$)/.exec(ini.filename)) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "";
|
|
5732
3841
|
const bin = files.filter((e) => e != null && e.filename === programName + ".bin")[0];
|
|
5733
3842
|
if (bin == null || bin.timestamp === 0 || bin.size === 0)
|
|
5734
3843
|
continue;
|
|
5735
|
-
const
|
|
5736
|
-
|
|
5737
|
-
const
|
|
3844
|
+
const n2 = new Date;
|
|
3845
|
+
n2.setTime(1000 * bin.timestamp);
|
|
3846
|
+
const program = {
|
|
5738
3847
|
name: programName,
|
|
5739
3848
|
binfile: bin.filename,
|
|
5740
3849
|
size: ini.size + bin.size,
|
|
5741
3850
|
slot: -1,
|
|
5742
|
-
time:
|
|
3851
|
+
time: n2,
|
|
5743
3852
|
requestedSlot: -1
|
|
5744
3853
|
};
|
|
5745
|
-
const result2 = yield conn === null || conn === undefined ? undefined : conn.writeDataAsync(new GetProgramSlotInfoH2DPacket(FileVendor.USER,
|
|
3854
|
+
const result2 = yield conn === null || conn === undefined ? undefined : conn.writeDataAsync(new GetProgramSlotInfoH2DPacket(FileVendor.USER, program.binfile));
|
|
5746
3855
|
if (result2 instanceof GetProgramSlotInfoReplyD2HPacket) {
|
|
5747
|
-
|
|
5748
|
-
|
|
3856
|
+
program.slot = result2.slot;
|
|
3857
|
+
program.requestedSlot = result2.requestedSlot;
|
|
5749
3858
|
}
|
|
5750
|
-
programList.push(
|
|
3859
|
+
programList.push(program);
|
|
5751
3860
|
}
|
|
5752
3861
|
return programList;
|
|
5753
3862
|
});
|
|
@@ -5848,8 +3957,8 @@ class V5Brain {
|
|
|
5848
3957
|
autoRun: true,
|
|
5849
3958
|
linkedFile: undefined
|
|
5850
3959
|
};
|
|
5851
|
-
const result2 = yield conn.uploadFileToDevice(bootWriteRequest, (c,
|
|
5852
|
-
pcb("UPLOAD BOOT", c,
|
|
3960
|
+
const result2 = yield conn.uploadFileToDevice(bootWriteRequest, (c, t2) => {
|
|
3961
|
+
pcb("UPLOAD BOOT", c, t2);
|
|
5853
3962
|
});
|
|
5854
3963
|
if (!result2)
|
|
5855
3964
|
return false;
|
|
@@ -5891,8 +4000,8 @@ class V5Brain {
|
|
|
5891
4000
|
autoRun: true,
|
|
5892
4001
|
linkedFile: undefined
|
|
5893
4002
|
};
|
|
5894
|
-
const result6 = yield conn.uploadFileToDevice(assertWriteRequest, (c,
|
|
5895
|
-
pcb("UPLOAD ASSERT", c,
|
|
4003
|
+
const result6 = yield conn.uploadFileToDevice(assertWriteRequest, (c, t2) => {
|
|
4004
|
+
pcb("UPLOAD ASSERT", c, t2);
|
|
5896
4005
|
});
|
|
5897
4006
|
if (!result6)
|
|
5898
4007
|
return false;
|
|
@@ -6007,11 +4116,11 @@ class V5Brain {
|
|
|
6007
4116
|
}, FileDownloadTarget.FILE_TARGET_CBUF, progressCallback);
|
|
6008
4117
|
if (buf == null)
|
|
6009
4118
|
return;
|
|
6010
|
-
buf = buf.filter((_byte,
|
|
6011
|
-
for (let
|
|
6012
|
-
const px = buf.slice(
|
|
4119
|
+
buf = buf.filter((_byte, i2) => i2 % (messageWidth * messageChannels) < width * messageChannels).filter((_byte, i2) => (i2 + 1) % messageChannels !== 0);
|
|
4120
|
+
for (let i2 = 0;i2 < buf.length; i2 += channels) {
|
|
4121
|
+
const px = buf.slice(i2, i2 + channels).reverse();
|
|
6013
4122
|
for (let j = 0;j < px.length; j++) {
|
|
6014
|
-
buf[
|
|
4123
|
+
buf[i2 + j] = px[j];
|
|
6015
4124
|
}
|
|
6016
4125
|
}
|
|
6017
4126
|
return buf;
|
|
@@ -6165,9 +4274,9 @@ class V5SerialDevice extends VexSerialDevice {
|
|
|
6165
4274
|
}
|
|
6166
4275
|
get devices() {
|
|
6167
4276
|
const rtn = [];
|
|
6168
|
-
for (let
|
|
6169
|
-
if (this.state.devices[
|
|
6170
|
-
rtn.push(new V5SmartDevice(this.state,
|
|
4277
|
+
for (let i2 = 1;i2 <= this.state.devices.length; i2++) {
|
|
4278
|
+
if (this.state.devices[i2] != null)
|
|
4279
|
+
rtn.push(new V5SmartDevice(this.state, i2));
|
|
6171
4280
|
}
|
|
6172
4281
|
return rtn;
|
|
6173
4282
|
}
|
|
@@ -6359,8 +4468,8 @@ class V5SerialDevice extends VexSerialDevice {
|
|
|
6359
4468
|
if (dsPacket == null)
|
|
6360
4469
|
return false;
|
|
6361
4470
|
let missingPorts = this.state.devices.map((d) => d === null || d === undefined ? undefined : d.port).filter((p) => p !== undefined);
|
|
6362
|
-
for (let
|
|
6363
|
-
const device = dsPacket.devices[
|
|
4471
|
+
for (let i2 = 0;i2 < dsPacket.devices.length; i2++) {
|
|
4472
|
+
const device = dsPacket.devices[i2];
|
|
6364
4473
|
this.state.devices[device.port] = device;
|
|
6365
4474
|
missingPorts = missingPorts.filter((p) => p !== device.port);
|
|
6366
4475
|
}
|
|
@@ -6677,8 +4786,8 @@ function openPort(path, options) {
|
|
|
6677
4786
|
writeFlag(termiosView, off.c_oflag, 0);
|
|
6678
4787
|
writeFlag(termiosView, off.c_lflag, 0);
|
|
6679
4788
|
const ccOffset = off.c_cc;
|
|
6680
|
-
for (let
|
|
6681
|
-
termiosBytes[ccOffset +
|
|
4789
|
+
for (let i2 = 0;i2 < NCCS; i2++)
|
|
4790
|
+
termiosBytes[ccOffset + i2] = 0;
|
|
6682
4791
|
termiosBytes[ccOffset + VMIN] = 1;
|
|
6683
4792
|
termiosBytes[ccOffset + VTIME] = 0;
|
|
6684
4793
|
const baudCode = encodeBaudRate(baudRate);
|
|
@@ -6729,14 +4838,14 @@ function writePort(fd, data) {
|
|
|
6729
4838
|
return offset;
|
|
6730
4839
|
}
|
|
6731
4840
|
function readPort(fd, buffer) {
|
|
6732
|
-
const
|
|
6733
|
-
if (
|
|
4841
|
+
const n2 = Number(libc.symbols.read(fd, ptr(buffer), BigInt(buffer.length)));
|
|
4842
|
+
if (n2 < 0) {
|
|
6734
4843
|
const code = getErrno();
|
|
6735
4844
|
if (code === 11 || code === 35)
|
|
6736
4845
|
return 0;
|
|
6737
4846
|
throw errnoError("read");
|
|
6738
4847
|
}
|
|
6739
|
-
return
|
|
4848
|
+
return n2;
|
|
6740
4849
|
}
|
|
6741
4850
|
function updateBaudRate(fd, baudRate) {
|
|
6742
4851
|
const termiosBuf = new ArrayBuffer(TERMIOS_SIZE);
|
|
@@ -6927,9 +5036,9 @@ class SerialPort extends EventEmitter {
|
|
|
6927
5036
|
if (!this.#isOpen || this.#isClosing)
|
|
6928
5037
|
return;
|
|
6929
5038
|
try {
|
|
6930
|
-
const
|
|
6931
|
-
if (
|
|
6932
|
-
const data = this.#readBuf.slice(0,
|
|
5039
|
+
const n2 = readPort(this.#fd, this.#readBuf);
|
|
5040
|
+
if (n2 > 0) {
|
|
5041
|
+
const data = this.#readBuf.slice(0, n2);
|
|
6933
5042
|
this.emit("data", data);
|
|
6934
5043
|
}
|
|
6935
5044
|
} catch (err) {
|
|
@@ -7005,7 +5114,7 @@ async function listLinux() {
|
|
|
7005
5114
|
}
|
|
7006
5115
|
async function findUsbParent(devicePath) {
|
|
7007
5116
|
let current = devicePath;
|
|
7008
|
-
for (let
|
|
5117
|
+
for (let i2 = 0;i2 < 10; i2++) {
|
|
7009
5118
|
current = join(current, "..");
|
|
7010
5119
|
if (await exists(join(current, "idVendor")))
|
|
7011
5120
|
return current;
|
|
@@ -7133,10 +5242,10 @@ class WebSerialAdapter extends EventTarget {
|
|
|
7133
5242
|
const info = { path: `/dev/${name}` };
|
|
7134
5243
|
if (subsystem.includes("usb")) {
|
|
7135
5244
|
let current = realDevicePath;
|
|
7136
|
-
for (let
|
|
5245
|
+
for (let i2 = 0;i2 < 5; i2++) {
|
|
7137
5246
|
try {
|
|
7138
|
-
const vendorId = await Bun.file(join2(current, "idVendor")).text().then((
|
|
7139
|
-
const productId = await Bun.file(join2(current, "idProduct")).text().then((
|
|
5247
|
+
const vendorId = await Bun.file(join2(current, "idVendor")).text().then((t2) => t2.trim());
|
|
5248
|
+
const productId = await Bun.file(join2(current, "idProduct")).text().then((t2) => t2.trim());
|
|
7140
5249
|
info.vendorId = vendorId;
|
|
7141
5250
|
info.productId = productId;
|
|
7142
5251
|
break;
|
|
@@ -7189,33 +5298,35 @@ async function connectV5Device() {
|
|
|
7189
5298
|
}
|
|
7190
5299
|
|
|
7191
5300
|
// src/commands/kv.ts
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
5301
|
+
function registerKvCommand(program) {
|
|
5302
|
+
program.command("kv", "access a brain's system key/value configuration").action(() => {});
|
|
5303
|
+
program.command("kv get <key>", "get the value of a system variable on a brain").action(async (key) => {
|
|
5304
|
+
const device = await connectV5Device();
|
|
5305
|
+
const value = await device.brain.getValue(key);
|
|
5306
|
+
console.log(value);
|
|
5307
|
+
await device.dispose();
|
|
5308
|
+
});
|
|
5309
|
+
program.command("kv set <key> <value>", "set a system variable on a brain").action(async (key, value) => {
|
|
5310
|
+
const device = await connectV5Device();
|
|
5311
|
+
const ok = await device.brain.setValue(key, value);
|
|
5312
|
+
if (ok)
|
|
5313
|
+
console.log(`set ${key} to ${value}`);
|
|
5314
|
+
else
|
|
5315
|
+
console.error(`failed to set ${key} to ${value}`);
|
|
5316
|
+
await device.dispose();
|
|
5317
|
+
});
|
|
5318
|
+
}
|
|
7209
5319
|
|
|
7210
5320
|
// src/commands/cat.ts
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
5321
|
+
function registerCatCommand(program) {
|
|
5322
|
+
program.command("cat <file>", "read a file from flash").action(async (file) => {
|
|
5323
|
+
const device = await connectV5Device();
|
|
5324
|
+
const decoder = new TextDecoder;
|
|
5325
|
+
const content = await device.brain.readFile(file);
|
|
5326
|
+
console.log(decoder.decode(content));
|
|
5327
|
+
await device.dispose();
|
|
5328
|
+
});
|
|
5329
|
+
}
|
|
7219
5330
|
|
|
7220
5331
|
// ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
7221
5332
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
@@ -7747,12 +5858,12 @@ async function detectProgramType(path) {
|
|
|
7747
5858
|
|
|
7748
5859
|
// src/utils/process.ts
|
|
7749
5860
|
async function runProcess(command, cwd) {
|
|
7750
|
-
const [
|
|
7751
|
-
if (
|
|
5861
|
+
const [program, ...args] = command;
|
|
5862
|
+
if (program === undefined)
|
|
7752
5863
|
throw new Error("cannot run an empty command");
|
|
7753
|
-
const executable = Bun.which(
|
|
5864
|
+
const executable = Bun.which(program);
|
|
7754
5865
|
if (executable === null) {
|
|
7755
|
-
throw new Error(`${
|
|
5866
|
+
throw new Error(`${program} is not installed or is not available on PATH`);
|
|
7756
5867
|
}
|
|
7757
5868
|
const process3 = Bun.spawn({
|
|
7758
5869
|
cmd: [executable, ...args],
|
|
@@ -7922,12 +6033,14 @@ function createProgramConfig(options) {
|
|
|
7922
6033
|
}
|
|
7923
6034
|
|
|
7924
6035
|
// src/commands/build.ts
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
});
|
|
7930
|
-
|
|
6036
|
+
function registerBuildCommand(program) {
|
|
6037
|
+
program.command("build [path]", "build a program for the V5 brain", { alias: "b" }).action(async (path) => {
|
|
6038
|
+
path ??= process.cwd();
|
|
6039
|
+
const project = await inspectProject(path);
|
|
6040
|
+
console.log(source_default.yellow(`building ${project.type} program...`));
|
|
6041
|
+
await buildProject(project);
|
|
6042
|
+
});
|
|
6043
|
+
}
|
|
7931
6044
|
|
|
7932
6045
|
// ../../node_modules/.bun/cmd-table@1.6.0/node_modules/cmd-table/dist/chunk-G76XL7PC.mjs
|
|
7933
6046
|
var Column = class {
|
|
@@ -8033,9 +6146,9 @@ var LayoutManager = class {
|
|
|
8033
6146
|
if (table.columns.length && colIndex + cell.colSpan > table.columns.length) {
|
|
8034
6147
|
throw new Error(`Row ${rowIndex} exceeds defined column count (${table.columns.length}).`);
|
|
8035
6148
|
}
|
|
8036
|
-
for (let
|
|
6149
|
+
for (let r2 = 0;r2 < cell.rowSpan; r2++) {
|
|
8037
6150
|
for (let c = 0;c < cell.colSpan; c++) {
|
|
8038
|
-
if (isOccupied(colIndex + c, rowIndex +
|
|
6151
|
+
if (isOccupied(colIndex + c, rowIndex + r2)) {
|
|
8039
6152
|
throw new Error(`Cell span conflict at row ${rowIndex}, col ${colIndex}.`);
|
|
8040
6153
|
}
|
|
8041
6154
|
}
|
|
@@ -8048,17 +6161,17 @@ var LayoutManager = class {
|
|
|
8048
6161
|
realRowSpan: cell.rowSpan
|
|
8049
6162
|
};
|
|
8050
6163
|
grid[rowIndex][colIndex] = gridCell;
|
|
8051
|
-
for (let
|
|
6164
|
+
for (let r2 = 0;r2 < cell.rowSpan; r2++) {
|
|
8052
6165
|
for (let c = 0;c < cell.colSpan; c++) {
|
|
8053
|
-
markOccupied(colIndex + c, rowIndex +
|
|
8054
|
-
if (
|
|
6166
|
+
markOccupied(colIndex + c, rowIndex + r2);
|
|
6167
|
+
if (r2 === 0 && c === 0)
|
|
8055
6168
|
continue;
|
|
8056
|
-
if (!grid[rowIndex +
|
|
8057
|
-
grid[rowIndex +
|
|
8058
|
-
grid[rowIndex +
|
|
6169
|
+
if (!grid[rowIndex + r2])
|
|
6170
|
+
grid[rowIndex + r2] = [];
|
|
6171
|
+
grid[rowIndex + r2][colIndex + c] = {
|
|
8059
6172
|
cell: gridCell.cell,
|
|
8060
6173
|
x: colIndex + c,
|
|
8061
|
-
y: rowIndex +
|
|
6174
|
+
y: rowIndex + r2,
|
|
8062
6175
|
realColSpan: gridCell.realColSpan,
|
|
8063
6176
|
realRowSpan: gridCell.realRowSpan,
|
|
8064
6177
|
hidden: true
|
|
@@ -8070,27 +6183,27 @@ var LayoutManager = class {
|
|
|
8070
6183
|
});
|
|
8071
6184
|
});
|
|
8072
6185
|
const columnCount = table.columns.length || maxColumns;
|
|
8073
|
-
for (let
|
|
8074
|
-
if (!grid[
|
|
8075
|
-
grid[
|
|
6186
|
+
for (let r2 = 0;r2 < grid.length; r2++) {
|
|
6187
|
+
if (!grid[r2])
|
|
6188
|
+
grid[r2] = [];
|
|
8076
6189
|
for (let c = 0;c < columnCount; c++) {
|
|
8077
|
-
if (grid[
|
|
6190
|
+
if (grid[r2][c])
|
|
8078
6191
|
continue;
|
|
8079
|
-
if (isOccupied(c,
|
|
8080
|
-
grid[
|
|
6192
|
+
if (isOccupied(c, r2)) {
|
|
6193
|
+
grid[r2][c] = {
|
|
8081
6194
|
cell: new Cell(""),
|
|
8082
6195
|
x: c,
|
|
8083
|
-
y:
|
|
6196
|
+
y: r2,
|
|
8084
6197
|
realColSpan: 1,
|
|
8085
6198
|
realRowSpan: 1,
|
|
8086
6199
|
hidden: true
|
|
8087
6200
|
};
|
|
8088
6201
|
continue;
|
|
8089
6202
|
}
|
|
8090
|
-
grid[
|
|
6203
|
+
grid[r2][c] = {
|
|
8091
6204
|
cell: new Cell(""),
|
|
8092
6205
|
x: c,
|
|
8093
|
-
y:
|
|
6206
|
+
y: r2,
|
|
8094
6207
|
realColSpan: 1,
|
|
8095
6208
|
realRowSpan: 1
|
|
8096
6209
|
};
|
|
@@ -8122,12 +6235,12 @@ function stringWidth(str) {
|
|
|
8122
6235
|
const stripped = stripAnsi(str);
|
|
8123
6236
|
let width = 0;
|
|
8124
6237
|
let inEmojiZwjSequence = false;
|
|
8125
|
-
for (let
|
|
8126
|
-
const code = stripped.codePointAt(
|
|
6238
|
+
for (let i2 = 0;i2 < stripped.length; i2++) {
|
|
6239
|
+
const code = stripped.codePointAt(i2);
|
|
8127
6240
|
if (!code)
|
|
8128
6241
|
continue;
|
|
8129
6242
|
if (code > 65535) {
|
|
8130
|
-
|
|
6243
|
+
i2++;
|
|
8131
6244
|
}
|
|
8132
6245
|
if (code <= 31 || 127 <= code && code <= 159) {
|
|
8133
6246
|
continue;
|
|
@@ -8493,9 +6606,9 @@ var Table = class _Table {
|
|
|
8493
6606
|
if (op === "count")
|
|
8494
6607
|
footer[name] = values.length;
|
|
8495
6608
|
else if (op === "avg")
|
|
8496
|
-
footer[name] = values.length ? Number((values.reduce((
|
|
6609
|
+
footer[name] = values.length ? Number((values.reduce((a2, b) => a2 + b, 0) / values.length).toFixed(2)) : 0;
|
|
8497
6610
|
else
|
|
8498
|
-
footer[name] = values.reduce((
|
|
6611
|
+
footer[name] = values.reduce((a2, b) => a2 + b, 0);
|
|
8499
6612
|
});
|
|
8500
6613
|
this.footer = footer;
|
|
8501
6614
|
return this;
|
|
@@ -8523,8 +6636,8 @@ var Table = class _Table {
|
|
|
8523
6636
|
getPages(pageSize) {
|
|
8524
6637
|
const pages = [];
|
|
8525
6638
|
const totalPages = Math.ceil(this.rows.length / pageSize);
|
|
8526
|
-
for (let
|
|
8527
|
-
pages.push(this.paginate(
|
|
6639
|
+
for (let i2 = 1;i2 <= totalPages; i2++) {
|
|
6640
|
+
pages.push(this.paginate(i2, pageSize));
|
|
8528
6641
|
}
|
|
8529
6642
|
return pages;
|
|
8530
6643
|
}
|
|
@@ -8558,8 +6671,8 @@ var Table = class _Table {
|
|
|
8558
6671
|
const colIndex = this.columns.findIndex((c) => c.name === columnName || c.key === columnName);
|
|
8559
6672
|
if (colIndex === -1)
|
|
8560
6673
|
return this;
|
|
8561
|
-
this.rows.sort((
|
|
8562
|
-
const cellA =
|
|
6674
|
+
this.rows.sort((a2, b) => {
|
|
6675
|
+
const cellA = a2.cells[colIndex];
|
|
8563
6676
|
const cellB = b.cells[colIndex];
|
|
8564
6677
|
const valA = cellA ? cellA.content : "";
|
|
8565
6678
|
const valB = cellB ? cellB.content : "";
|
|
@@ -8633,7 +6746,7 @@ var Table = class _Table {
|
|
|
8633
6746
|
if (primaryKey) {
|
|
8634
6747
|
oldData.forEach((oldObj, oldIdx) => {
|
|
8635
6748
|
const pkValue = oldObj[primaryKey];
|
|
8636
|
-
const newIdx = newData.findIndex((
|
|
6749
|
+
const newIdx = newData.findIndex((n2) => n2[primaryKey] === pkValue);
|
|
8637
6750
|
if (newIdx !== -1) {
|
|
8638
6751
|
compareAndAdd(oldObj, newData[newIdx]);
|
|
8639
6752
|
processedOldIndices.add(oldIdx);
|
|
@@ -8654,9 +6767,9 @@ var Table = class _Table {
|
|
|
8654
6767
|
});
|
|
8655
6768
|
} else {
|
|
8656
6769
|
const maxLength = Math.max(oldData.length, newData.length);
|
|
8657
|
-
for (let
|
|
8658
|
-
const oldObj = oldData[
|
|
8659
|
-
const newObj = newData[
|
|
6770
|
+
for (let i2 = 0;i2 < maxLength; i2++) {
|
|
6771
|
+
const oldObj = oldData[i2];
|
|
6772
|
+
const newObj = newData[i2];
|
|
8660
6773
|
if (oldObj && newObj) {
|
|
8661
6774
|
compareAndAdd(oldObj, newObj);
|
|
8662
6775
|
} else if (oldObj && !newObj) {
|
|
@@ -8690,13 +6803,13 @@ var Table = class _Table {
|
|
|
8690
6803
|
nodes.forEach((node) => processNode(node, 0));
|
|
8691
6804
|
}
|
|
8692
6805
|
mergeAdjacent(columns) {
|
|
8693
|
-
const colIndices = columns ? columns.map((name) => this.columns.findIndex((c) => c.name === name || c.key === name)).filter((
|
|
6806
|
+
const colIndices = columns ? columns.map((name) => this.columns.findIndex((c) => c.name === name || c.key === name)).filter((i2) => i2 >= 0) : this.columns.map((_, i2) => i2);
|
|
8694
6807
|
if (colIndices.length === 0)
|
|
8695
6808
|
return;
|
|
8696
6809
|
colIndices.forEach((colIndex) => {
|
|
8697
6810
|
let lastCell = this.rows[0]?.cells[colIndex];
|
|
8698
|
-
for (let
|
|
8699
|
-
const currentCell = this.rows[
|
|
6811
|
+
for (let i2 = 1;i2 < this.rows.length; i2++) {
|
|
6812
|
+
const currentCell = this.rows[i2].cells[colIndex];
|
|
8700
6813
|
if (lastCell && currentCell && lastCell.content === currentCell.content) {
|
|
8701
6814
|
lastCell.rowSpan = (lastCell.rowSpan || 1) + 1;
|
|
8702
6815
|
currentCell.merged = true;
|
|
@@ -8709,7 +6822,7 @@ var Table = class _Table {
|
|
|
8709
6822
|
transpose() {
|
|
8710
6823
|
const newColumns = [
|
|
8711
6824
|
{ name: "Field", key: "field" },
|
|
8712
|
-
...this.rows.map((_,
|
|
6825
|
+
...this.rows.map((_, i2) => ({ name: `Row ${i2 + 1}`, key: `_row_${i2}` }))
|
|
8713
6826
|
];
|
|
8714
6827
|
const transposed = new _Table({
|
|
8715
6828
|
theme: this.theme,
|
|
@@ -8836,7 +6949,7 @@ var StringRenderer = class {
|
|
|
8836
6949
|
const total = this.calculateTableWidth(widths, this.getVisibleColumns(next), next.theme);
|
|
8837
6950
|
if (total <= terminalWidth)
|
|
8838
6951
|
return this.buildVisibleTable(next);
|
|
8839
|
-
const sorted = next.columns.map((column, index) => ({ index, priority: column.priority })).sort((
|
|
6952
|
+
const sorted = next.columns.map((column, index) => ({ index, priority: column.priority })).sort((a2, b) => b.priority - a2.priority);
|
|
8840
6953
|
for (const col of sorted) {
|
|
8841
6954
|
next.columns[col.index].hidden = true;
|
|
8842
6955
|
if (this.getVisibleColumns(next).length === 0)
|
|
@@ -8991,11 +7104,11 @@ var StringRenderer = class {
|
|
|
8991
7104
|
return;
|
|
8992
7105
|
let remaining = desired - current;
|
|
8993
7106
|
let candidates = [];
|
|
8994
|
-
for (let
|
|
8995
|
-
const column = columns[start +
|
|
7107
|
+
for (let i2 = 0;i2 < span; i2++) {
|
|
7108
|
+
const column = columns[start + i2];
|
|
8996
7109
|
if (!column || column.width !== undefined)
|
|
8997
7110
|
continue;
|
|
8998
|
-
candidates.push(start +
|
|
7111
|
+
candidates.push(start + i2);
|
|
8999
7112
|
}
|
|
9000
7113
|
if (candidates.length === 0)
|
|
9001
7114
|
return;
|
|
@@ -9033,19 +7146,19 @@ var StringRenderer = class {
|
|
|
9033
7146
|
let padLeft = 1;
|
|
9034
7147
|
let padRight = 1;
|
|
9035
7148
|
let internalPadding = 0;
|
|
9036
|
-
for (let
|
|
9037
|
-
const column = columns[start +
|
|
7149
|
+
for (let i2 = 0;i2 < span; i2++) {
|
|
7150
|
+
const column = columns[start + i2];
|
|
9038
7151
|
const left = column?.paddingLeft ?? 1;
|
|
9039
7152
|
const right = column?.paddingRight ?? 1;
|
|
9040
|
-
if (
|
|
7153
|
+
if (i2 === 0)
|
|
9041
7154
|
padLeft = left;
|
|
9042
7155
|
else
|
|
9043
7156
|
internalPadding += left;
|
|
9044
|
-
if (
|
|
7157
|
+
if (i2 === span - 1)
|
|
9045
7158
|
padRight = right;
|
|
9046
7159
|
else
|
|
9047
7160
|
internalPadding += right;
|
|
9048
|
-
contentWidth += widths[start +
|
|
7161
|
+
contentWidth += widths[start + i2] || 0;
|
|
9049
7162
|
}
|
|
9050
7163
|
return {
|
|
9051
7164
|
contentWidth: contentWidth + internalPadding + joinWidth * Math.max(0, span - 1),
|
|
@@ -9057,8 +7170,8 @@ var StringRenderer = class {
|
|
|
9057
7170
|
const visibleCols = widths.length;
|
|
9058
7171
|
const joinWidth = this.strWidth(theme.bodyJoin);
|
|
9059
7172
|
const cellLines = [];
|
|
9060
|
-
for (let
|
|
9061
|
-
const gridCell = row[
|
|
7173
|
+
for (let i2 = 0;i2 < visibleCols; i2++) {
|
|
7174
|
+
const gridCell = row[i2];
|
|
9062
7175
|
if (!gridCell || gridCell.hidden)
|
|
9063
7176
|
continue;
|
|
9064
7177
|
const col = gridCell.x;
|
|
@@ -9082,7 +7195,7 @@ var StringRenderer = class {
|
|
|
9082
7195
|
contentWidth: metrics.contentWidth,
|
|
9083
7196
|
color: gridCell.cell.color
|
|
9084
7197
|
});
|
|
9085
|
-
|
|
7198
|
+
i2 += gridCell.realColSpan - 1;
|
|
9086
7199
|
}
|
|
9087
7200
|
const rowHeight = Math.max(1, ...cellLines.map((entry) => entry.lines.length));
|
|
9088
7201
|
const lines = [];
|
|
@@ -9200,8 +7313,8 @@ var StringRenderer = class {
|
|
|
9200
7313
|
}
|
|
9201
7314
|
sumWidths(widths, start, span, joinWidth) {
|
|
9202
7315
|
let sum = 0;
|
|
9203
|
-
for (let
|
|
9204
|
-
sum += widths[start +
|
|
7316
|
+
for (let i2 = 0;i2 < span; i2++)
|
|
7317
|
+
sum += widths[start + i2] || 0;
|
|
9205
7318
|
return sum + Math.max(0, span - 1) * joinWidth;
|
|
9206
7319
|
}
|
|
9207
7320
|
strWidth(value) {
|
|
@@ -9292,24 +7405,25 @@ function formatVersion(version) {
|
|
|
9292
7405
|
const patch = version & 255;
|
|
9293
7406
|
return `${major}.${minor}.${patch}`;
|
|
9294
7407
|
}
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
|
|
7408
|
+
function registerDevicesCommand(program) {
|
|
7409
|
+
program.command("devices", "list devices connected to brain", { alias: "lsdev" }).action(async () => {
|
|
7410
|
+
const device = await connectV5Device();
|
|
7411
|
+
const smartDevices = device.devices;
|
|
7412
|
+
const table = new Table({ compact: true });
|
|
7413
|
+
table.addColumn("port");
|
|
7414
|
+
table.addColumn("type");
|
|
7415
|
+
table.addColumn("version");
|
|
7416
|
+
smartDevices.forEach((d) => {
|
|
7417
|
+
table.addRow([
|
|
7418
|
+
d.port.toString(),
|
|
7419
|
+
SMART_DEVICE_LABELS[d.type],
|
|
7420
|
+
formatVersion(d.version)
|
|
7421
|
+
]);
|
|
7422
|
+
});
|
|
7423
|
+
console.log(table.render());
|
|
7424
|
+
await device.dispose();
|
|
9308
7425
|
});
|
|
9309
|
-
|
|
9310
|
-
await device.dispose();
|
|
9311
|
-
});
|
|
9312
|
-
var devices_default = devicesCommand;
|
|
7426
|
+
}
|
|
9313
7427
|
|
|
9314
7428
|
// src/commands/dir.ts
|
|
9315
7429
|
var VENDORS = [
|
|
@@ -9370,38 +7484,39 @@ function formatSize(bytes) {
|
|
|
9370
7484
|
}
|
|
9371
7485
|
return `${size.toFixed(size < 10 && unit > 0 ? 1 : 0)} ${units[unit]}`;
|
|
9372
7486
|
}
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
const
|
|
9378
|
-
|
|
9379
|
-
...file
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
7487
|
+
function registerDirCommand(program) {
|
|
7488
|
+
program.command("dir", "list files on flash", { alias: "ls" }).action(async () => {
|
|
7489
|
+
const device = await connectV5Device();
|
|
7490
|
+
const files = [];
|
|
7491
|
+
for (const vendor of VENDORS) {
|
|
7492
|
+
const vendorFiles = await device.brain.listFiles(vendor) ?? [];
|
|
7493
|
+
files.push(...vendorFiles.map((file) => ({
|
|
7494
|
+
...file,
|
|
7495
|
+
vendor
|
|
7496
|
+
})));
|
|
7497
|
+
}
|
|
7498
|
+
const table = new Table({
|
|
7499
|
+
compact: true
|
|
7500
|
+
});
|
|
7501
|
+
table.addColumn("name");
|
|
7502
|
+
table.addColumn("size");
|
|
7503
|
+
table.addColumn("load address");
|
|
7504
|
+
table.addColumn("timestamp");
|
|
7505
|
+
table.addColumn("crc32");
|
|
7506
|
+
files.forEach(({ vendor, filename, size, loadAddress, timestamp, crc32 }) => {
|
|
7507
|
+
const date = new Date(timestamp * 1000);
|
|
7508
|
+
table.addRow([
|
|
7509
|
+
vendorPrefix(vendor) + filename,
|
|
7510
|
+
formatSize(size),
|
|
7511
|
+
`0x${loadAddress.toString(16)}`,
|
|
7512
|
+
formatDate(date),
|
|
7513
|
+
`0x${crc32.toString(16)}`
|
|
7514
|
+
]);
|
|
7515
|
+
});
|
|
7516
|
+
console.log(table.render());
|
|
7517
|
+
await device.dispose();
|
|
9400
7518
|
});
|
|
9401
|
-
|
|
9402
|
-
await device.dispose();
|
|
9403
|
-
});
|
|
9404
|
-
var dir_default = dirCommand;
|
|
7519
|
+
}
|
|
9405
7520
|
|
|
9406
7521
|
// src/utils/upload.ts
|
|
9407
7522
|
async function uploadProgram(options) {
|
|
@@ -9443,34 +7558,42 @@ async function uploadProgram(options) {
|
|
|
9443
7558
|
}
|
|
9444
7559
|
|
|
9445
7560
|
// src/commands/upload.ts
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
7561
|
+
function registerUploadCommand(program) {
|
|
7562
|
+
program.command("upload [path]", "build and upload a program to the V5 brain", {
|
|
7563
|
+
alias: "u"
|
|
7564
|
+
}).option("-s, --slot", "program slot", "1").option("-n, --name", "program name shown on the brain").option("-d, --description", "program description").option("-i, --icon", "program icon file", "default.bmp").option("-f, --file", "upload an existing .bin artifact").option("--no-build", "skip building the project").option("--run", "start the program after uploading").action(async (path, options) => {
|
|
7565
|
+
path ??= process.cwd();
|
|
7566
|
+
await uploadProgram({
|
|
7567
|
+
path,
|
|
7568
|
+
slot: Number(options.slot),
|
|
7569
|
+
name: options.name,
|
|
7570
|
+
description: options.description,
|
|
7571
|
+
icon: options.icon,
|
|
7572
|
+
artifact: options.file,
|
|
7573
|
+
build: options.build ?? true,
|
|
7574
|
+
run: options.run ?? false
|
|
7575
|
+
});
|
|
9456
7576
|
});
|
|
9457
|
-
}
|
|
9458
|
-
var upload_default = uploadCommand;
|
|
7577
|
+
}
|
|
9459
7578
|
|
|
9460
7579
|
// src/commands/run.ts
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
7580
|
+
function registerRunCommand(program) {
|
|
7581
|
+
program.command("run [path]", "build, upload, and run a program on a V5 brain", {
|
|
7582
|
+
alias: "r"
|
|
7583
|
+
}).option("-s, --slot", "program slot", "1").option("-n, --name", "program name shown on the brain").option("-d, --description", "program description").option("-i, --icon", "program icon file", "default.bmp").option("-f, --file", "upload an existing .bin artifact").option("--no-build", "skip building the project").action(async (path, options) => {
|
|
7584
|
+
path ??= process.cwd();
|
|
7585
|
+
await uploadProgram({
|
|
7586
|
+
path,
|
|
7587
|
+
slot: Number(options.slot),
|
|
7588
|
+
name: options.name,
|
|
7589
|
+
description: options.description,
|
|
7590
|
+
icon: options.icon,
|
|
7591
|
+
artifact: options.file,
|
|
7592
|
+
build: options.build ?? true,
|
|
7593
|
+
run: true
|
|
7594
|
+
});
|
|
9471
7595
|
});
|
|
9472
|
-
}
|
|
9473
|
-
var run_default = runCommand;
|
|
7596
|
+
}
|
|
9474
7597
|
|
|
9475
7598
|
// src/commands/new.ts
|
|
9476
7599
|
import { join as join6 } from "path";
|
|
@@ -9496,16 +7619,16 @@ var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9
|
|
|
9496
7619
|
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
9497
7620
|
var freb = function(eb, start) {
|
|
9498
7621
|
var b = new u16(31);
|
|
9499
|
-
for (var
|
|
9500
|
-
b[
|
|
7622
|
+
for (var i2 = 0;i2 < 31; ++i2) {
|
|
7623
|
+
b[i2] = start += 1 << eb[i2 - 1];
|
|
9501
7624
|
}
|
|
9502
|
-
var
|
|
9503
|
-
for (var
|
|
9504
|
-
for (var j = b[
|
|
9505
|
-
|
|
7625
|
+
var r2 = new i32(b[30]);
|
|
7626
|
+
for (var i2 = 1;i2 < 30; ++i2) {
|
|
7627
|
+
for (var j = b[i2];j < b[i2 + 1]; ++j) {
|
|
7628
|
+
r2[j] = j - b[i2] << 5 | i2;
|
|
9506
7629
|
}
|
|
9507
7630
|
}
|
|
9508
|
-
return { b, r };
|
|
7631
|
+
return { b, r: r2 };
|
|
9509
7632
|
};
|
|
9510
7633
|
var _a = freb(fleb, 2);
|
|
9511
7634
|
var fl = _a.b;
|
|
@@ -9515,94 +7638,94 @@ var _b = freb(fdeb, 0);
|
|
|
9515
7638
|
var fd = _b.b;
|
|
9516
7639
|
var revfd = _b.r;
|
|
9517
7640
|
var rev = new u16(32768);
|
|
9518
|
-
for (
|
|
9519
|
-
x = (
|
|
7641
|
+
for (i2 = 0;i2 < 32768; ++i2) {
|
|
7642
|
+
x = (i2 & 43690) >> 1 | (i2 & 21845) << 1;
|
|
9520
7643
|
x = (x & 52428) >> 2 | (x & 13107) << 2;
|
|
9521
7644
|
x = (x & 61680) >> 4 | (x & 3855) << 4;
|
|
9522
|
-
rev[
|
|
7645
|
+
rev[i2] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
|
|
9523
7646
|
}
|
|
9524
7647
|
var x;
|
|
9525
|
-
var
|
|
9526
|
-
var hMap = function(cd, mb,
|
|
9527
|
-
var
|
|
9528
|
-
var
|
|
9529
|
-
var
|
|
9530
|
-
for (;
|
|
9531
|
-
if (cd[
|
|
9532
|
-
++
|
|
7648
|
+
var i2;
|
|
7649
|
+
var hMap = function(cd, mb, r2) {
|
|
7650
|
+
var s2 = cd.length;
|
|
7651
|
+
var i3 = 0;
|
|
7652
|
+
var l2 = new u16(mb);
|
|
7653
|
+
for (;i3 < s2; ++i3) {
|
|
7654
|
+
if (cd[i3])
|
|
7655
|
+
++l2[cd[i3] - 1];
|
|
9533
7656
|
}
|
|
9534
7657
|
var le = new u16(mb);
|
|
9535
|
-
for (
|
|
9536
|
-
le[
|
|
7658
|
+
for (i3 = 1;i3 < mb; ++i3) {
|
|
7659
|
+
le[i3] = le[i3 - 1] + l2[i3 - 1] << 1;
|
|
9537
7660
|
}
|
|
9538
7661
|
var co;
|
|
9539
|
-
if (
|
|
7662
|
+
if (r2) {
|
|
9540
7663
|
co = new u16(1 << mb);
|
|
9541
7664
|
var rvb = 15 - mb;
|
|
9542
|
-
for (
|
|
9543
|
-
if (cd[
|
|
9544
|
-
var sv =
|
|
9545
|
-
var r_1 = mb - cd[
|
|
9546
|
-
var v = le[cd[
|
|
7665
|
+
for (i3 = 0;i3 < s2; ++i3) {
|
|
7666
|
+
if (cd[i3]) {
|
|
7667
|
+
var sv = i3 << 4 | cd[i3];
|
|
7668
|
+
var r_1 = mb - cd[i3];
|
|
7669
|
+
var v = le[cd[i3] - 1]++ << r_1;
|
|
9547
7670
|
for (var m = v | (1 << r_1) - 1;v <= m; ++v) {
|
|
9548
7671
|
co[rev[v] >> rvb] = sv;
|
|
9549
7672
|
}
|
|
9550
7673
|
}
|
|
9551
7674
|
}
|
|
9552
7675
|
} else {
|
|
9553
|
-
co = new u16(
|
|
9554
|
-
for (
|
|
9555
|
-
if (cd[
|
|
9556
|
-
co[
|
|
7676
|
+
co = new u16(s2);
|
|
7677
|
+
for (i3 = 0;i3 < s2; ++i3) {
|
|
7678
|
+
if (cd[i3]) {
|
|
7679
|
+
co[i3] = rev[le[cd[i3] - 1]++] >> 15 - cd[i3];
|
|
9557
7680
|
}
|
|
9558
7681
|
}
|
|
9559
7682
|
}
|
|
9560
7683
|
return co;
|
|
9561
7684
|
};
|
|
9562
7685
|
var flt = new u8(288);
|
|
9563
|
-
for (
|
|
9564
|
-
flt[
|
|
9565
|
-
var
|
|
9566
|
-
for (
|
|
9567
|
-
flt[
|
|
9568
|
-
var
|
|
9569
|
-
for (
|
|
9570
|
-
flt[
|
|
9571
|
-
var
|
|
9572
|
-
for (
|
|
9573
|
-
flt[
|
|
9574
|
-
var
|
|
7686
|
+
for (i2 = 0;i2 < 144; ++i2)
|
|
7687
|
+
flt[i2] = 8;
|
|
7688
|
+
var i2;
|
|
7689
|
+
for (i2 = 144;i2 < 256; ++i2)
|
|
7690
|
+
flt[i2] = 9;
|
|
7691
|
+
var i2;
|
|
7692
|
+
for (i2 = 256;i2 < 280; ++i2)
|
|
7693
|
+
flt[i2] = 7;
|
|
7694
|
+
var i2;
|
|
7695
|
+
for (i2 = 280;i2 < 288; ++i2)
|
|
7696
|
+
flt[i2] = 8;
|
|
7697
|
+
var i2;
|
|
9575
7698
|
var fdt = new u8(32);
|
|
9576
|
-
for (
|
|
9577
|
-
fdt[
|
|
9578
|
-
var
|
|
7699
|
+
for (i2 = 0;i2 < 32; ++i2)
|
|
7700
|
+
fdt[i2] = 5;
|
|
7701
|
+
var i2;
|
|
9579
7702
|
var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
|
|
9580
7703
|
var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
|
|
9581
|
-
var max = function(
|
|
9582
|
-
var m =
|
|
9583
|
-
for (var
|
|
9584
|
-
if (
|
|
9585
|
-
m =
|
|
7704
|
+
var max = function(a2) {
|
|
7705
|
+
var m = a2[0];
|
|
7706
|
+
for (var i3 = 1;i3 < a2.length; ++i3) {
|
|
7707
|
+
if (a2[i3] > m)
|
|
7708
|
+
m = a2[i3];
|
|
9586
7709
|
}
|
|
9587
7710
|
return m;
|
|
9588
7711
|
};
|
|
9589
7712
|
var bits = function(d, p, m) {
|
|
9590
|
-
var
|
|
9591
|
-
return (d[
|
|
7713
|
+
var o2 = p / 8 | 0;
|
|
7714
|
+
return (d[o2] | d[o2 + 1] << 8) >> (p & 7) & m;
|
|
9592
7715
|
};
|
|
9593
7716
|
var bits16 = function(d, p) {
|
|
9594
|
-
var
|
|
9595
|
-
return (d[
|
|
7717
|
+
var o2 = p / 8 | 0;
|
|
7718
|
+
return (d[o2] | d[o2 + 1] << 8 | d[o2 + 2] << 16) >> (p & 7);
|
|
9596
7719
|
};
|
|
9597
7720
|
var shft = function(p) {
|
|
9598
7721
|
return (p + 7) / 8 | 0;
|
|
9599
7722
|
};
|
|
9600
|
-
var slc = function(v,
|
|
9601
|
-
if (
|
|
9602
|
-
|
|
7723
|
+
var slc = function(v, s2, e) {
|
|
7724
|
+
if (s2 == null || s2 < 0)
|
|
7725
|
+
s2 = 0;
|
|
9603
7726
|
if (e == null || e > v.length)
|
|
9604
7727
|
e = v.length;
|
|
9605
|
-
return new u8(v.subarray(
|
|
7728
|
+
return new u8(v.subarray(s2, e));
|
|
9606
7729
|
};
|
|
9607
7730
|
var ec = [
|
|
9608
7731
|
"unexpected EOF",
|
|
@@ -9638,10 +7761,10 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
9638
7761
|
var noSt = st.i;
|
|
9639
7762
|
if (noBuf)
|
|
9640
7763
|
buf = new u8(sl * 3);
|
|
9641
|
-
var cbuf = function(
|
|
7764
|
+
var cbuf = function(l3) {
|
|
9642
7765
|
var bl = buf.length;
|
|
9643
|
-
if (
|
|
9644
|
-
var nbuf = new u8(Math.max(bl * 2,
|
|
7766
|
+
if (l3 > bl) {
|
|
7767
|
+
var nbuf = new u8(Math.max(bl * 2, l3));
|
|
9645
7768
|
nbuf.set(buf);
|
|
9646
7769
|
buf = nbuf;
|
|
9647
7770
|
}
|
|
@@ -9654,16 +7777,16 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
9654
7777
|
var type = bits(dat, pos + 1, 3);
|
|
9655
7778
|
pos += 3;
|
|
9656
7779
|
if (!type) {
|
|
9657
|
-
var
|
|
9658
|
-
if (
|
|
7780
|
+
var s2 = shft(pos) + 4, l2 = dat[s2 - 4] | dat[s2 - 3] << 8, t2 = s2 + l2;
|
|
7781
|
+
if (t2 > sl) {
|
|
9659
7782
|
if (noSt)
|
|
9660
7783
|
err(0);
|
|
9661
7784
|
break;
|
|
9662
7785
|
}
|
|
9663
7786
|
if (resize)
|
|
9664
|
-
cbuf(bt +
|
|
9665
|
-
buf.set(dat.subarray(
|
|
9666
|
-
st.b = bt +=
|
|
7787
|
+
cbuf(bt + l2);
|
|
7788
|
+
buf.set(dat.subarray(s2, t2), bt);
|
|
7789
|
+
st.b = bt += l2, st.p = pos = t2 * 8, st.f = final;
|
|
9667
7790
|
continue;
|
|
9668
7791
|
} else if (type == 1)
|
|
9669
7792
|
lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
|
|
@@ -9673,28 +7796,28 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
9673
7796
|
pos += 14;
|
|
9674
7797
|
var ldt = new u8(tl);
|
|
9675
7798
|
var clt = new u8(19);
|
|
9676
|
-
for (var
|
|
9677
|
-
clt[clim[
|
|
7799
|
+
for (var i3 = 0;i3 < hcLen; ++i3) {
|
|
7800
|
+
clt[clim[i3]] = bits(dat, pos + i3 * 3, 7);
|
|
9678
7801
|
}
|
|
9679
7802
|
pos += hcLen * 3;
|
|
9680
7803
|
var clb = max(clt), clbmsk = (1 << clb) - 1;
|
|
9681
7804
|
var clm = hMap(clt, clb, 1);
|
|
9682
|
-
for (var
|
|
9683
|
-
var
|
|
9684
|
-
pos +=
|
|
9685
|
-
var
|
|
9686
|
-
if (
|
|
9687
|
-
ldt[
|
|
7805
|
+
for (var i3 = 0;i3 < tl; ) {
|
|
7806
|
+
var r2 = clm[bits(dat, pos, clbmsk)];
|
|
7807
|
+
pos += r2 & 15;
|
|
7808
|
+
var s2 = r2 >> 4;
|
|
7809
|
+
if (s2 < 16) {
|
|
7810
|
+
ldt[i3++] = s2;
|
|
9688
7811
|
} else {
|
|
9689
|
-
var c = 0,
|
|
9690
|
-
if (
|
|
9691
|
-
|
|
9692
|
-
else if (
|
|
9693
|
-
|
|
9694
|
-
else if (
|
|
9695
|
-
|
|
9696
|
-
while (
|
|
9697
|
-
ldt[
|
|
7812
|
+
var c = 0, n2 = 0;
|
|
7813
|
+
if (s2 == 16)
|
|
7814
|
+
n2 = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i3 - 1];
|
|
7815
|
+
else if (s2 == 17)
|
|
7816
|
+
n2 = 3 + bits(dat, pos, 7), pos += 3;
|
|
7817
|
+
else if (s2 == 18)
|
|
7818
|
+
n2 = 11 + bits(dat, pos, 127), pos += 7;
|
|
7819
|
+
while (n2--)
|
|
7820
|
+
ldt[i3++] = c;
|
|
9698
7821
|
}
|
|
9699
7822
|
}
|
|
9700
7823
|
var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
|
|
@@ -9732,8 +7855,8 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
9732
7855
|
} else {
|
|
9733
7856
|
var add = sym - 254;
|
|
9734
7857
|
if (sym > 264) {
|
|
9735
|
-
var
|
|
9736
|
-
add = bits(dat, pos, (1 << b) - 1) + fl[
|
|
7858
|
+
var i3 = sym - 257, b = fleb[i3];
|
|
7859
|
+
add = bits(dat, pos, (1 << b) - 1) + fl[i3];
|
|
9737
7860
|
pos += b;
|
|
9738
7861
|
}
|
|
9739
7862
|
var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
|
|
@@ -9790,34 +7913,34 @@ try {
|
|
|
9790
7913
|
tds = 1;
|
|
9791
7914
|
} catch (e) {}
|
|
9792
7915
|
var dutf8 = function(d) {
|
|
9793
|
-
for (var
|
|
9794
|
-
var c = d[
|
|
7916
|
+
for (var r2 = "", i3 = 0;; ) {
|
|
7917
|
+
var c = d[i3++];
|
|
9795
7918
|
var eb = (c > 127) + (c > 223) + (c > 239);
|
|
9796
|
-
if (
|
|
9797
|
-
return { s:
|
|
7919
|
+
if (i3 + eb > d.length)
|
|
7920
|
+
return { s: r2, r: slc(d, i3 - 1) };
|
|
9798
7921
|
if (!eb)
|
|
9799
|
-
|
|
7922
|
+
r2 += String.fromCharCode(c);
|
|
9800
7923
|
else if (eb == 3) {
|
|
9801
|
-
c = ((c & 15) << 18 | (d[
|
|
7924
|
+
c = ((c & 15) << 18 | (d[i3++] & 63) << 12 | (d[i3++] & 63) << 6 | d[i3++] & 63) - 65536, r2 += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
|
|
9802
7925
|
} else if (eb & 1)
|
|
9803
|
-
|
|
7926
|
+
r2 += String.fromCharCode((c & 31) << 6 | d[i3++] & 63);
|
|
9804
7927
|
else
|
|
9805
|
-
|
|
7928
|
+
r2 += String.fromCharCode((c & 15) << 12 | (d[i3++] & 63) << 6 | d[i3++] & 63);
|
|
9806
7929
|
}
|
|
9807
7930
|
};
|
|
9808
7931
|
function strFromU8(dat, latin1) {
|
|
9809
7932
|
if (latin1) {
|
|
9810
|
-
var
|
|
9811
|
-
for (var
|
|
9812
|
-
|
|
9813
|
-
return
|
|
7933
|
+
var r2 = "";
|
|
7934
|
+
for (var i3 = 0;i3 < dat.length; i3 += 16384)
|
|
7935
|
+
r2 += String.fromCharCode.apply(null, dat.subarray(i3, i3 + 16384));
|
|
7936
|
+
return r2;
|
|
9814
7937
|
} else if (td) {
|
|
9815
7938
|
return td.decode(dat);
|
|
9816
7939
|
} else {
|
|
9817
|
-
var _a2 = dutf8(dat),
|
|
9818
|
-
if (
|
|
7940
|
+
var _a2 = dutf8(dat), s2 = _a2.s, r2 = _a2.r;
|
|
7941
|
+
if (r2.length)
|
|
9819
7942
|
err(8);
|
|
9820
|
-
return
|
|
7943
|
+
return s2;
|
|
9821
7944
|
}
|
|
9822
7945
|
}
|
|
9823
7946
|
var slzh = function(d, b) {
|
|
@@ -9828,8 +7951,8 @@ var zh = function(d, b, z) {
|
|
|
9828
7951
|
var _a2 = z64hs(d, es, efl, z, b4(d, b + 20), b4(d, b + 24), b4(d, b + 42)), sc = _a2[0], su = _a2[1], off = _a2[2];
|
|
9829
7952
|
return [b2(d, b + 10), sc, su, fn, es + efl + b2(d, b + 32), off];
|
|
9830
7953
|
};
|
|
9831
|
-
var z64hs = function(d, b,
|
|
9832
|
-
var nsc = sc == 4294967295, nsu = su == 4294967295, noff = off == 4294967295, e = b +
|
|
7954
|
+
var z64hs = function(d, b, l2, z, sc, su, off) {
|
|
7955
|
+
var nsc = sc == 4294967295, nsu = su == 4294967295, noff = off == 4294967295, e = b + l2;
|
|
9833
7956
|
var nf = nsc + nsu + noff;
|
|
9834
7957
|
if (z && nf) {
|
|
9835
7958
|
for (;b + 4 < e; b += 4 + b2(d, b + 2)) {
|
|
@@ -9857,20 +7980,20 @@ function unzipSync(data, opts) {
|
|
|
9857
7980
|
var c = b2(data, e + 8);
|
|
9858
7981
|
if (!c)
|
|
9859
7982
|
return {};
|
|
9860
|
-
var
|
|
7983
|
+
var o2 = b4(data, e + 16);
|
|
9861
7984
|
var z = b4(data, e - 20) == 117853008;
|
|
9862
7985
|
if (z) {
|
|
9863
7986
|
var ze = b4(data, e - 12);
|
|
9864
7987
|
z = b4(data, ze) == 101075792;
|
|
9865
7988
|
if (z) {
|
|
9866
7989
|
c = b4(data, ze + 32);
|
|
9867
|
-
|
|
7990
|
+
o2 = b4(data, ze + 48);
|
|
9868
7991
|
}
|
|
9869
7992
|
}
|
|
9870
7993
|
var fltr = opts && opts.filter;
|
|
9871
|
-
for (var
|
|
9872
|
-
var _a2 = zh(data,
|
|
9873
|
-
|
|
7994
|
+
for (var i3 = 0;i3 < c; ++i3) {
|
|
7995
|
+
var _a2 = zh(data, o2, z), c_2 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off);
|
|
7996
|
+
o2 = no;
|
|
9874
7997
|
if (!fltr || fltr({
|
|
9875
7998
|
name: fn,
|
|
9876
7999
|
size: sc,
|
|
@@ -10042,32 +8165,42 @@ async function createProject(inputPath, toolchain, name = basename2(resolve2(inp
|
|
|
10042
8165
|
}
|
|
10043
8166
|
|
|
10044
8167
|
// src/commands/new.ts
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
8168
|
+
function registerNewCommand(program) {
|
|
8169
|
+
program.command("new <name>", "create a new V5 program", { alias: "n" }).option("-t, --type", "project toolchain").action(async (name, options) => {
|
|
8170
|
+
if (options.type !== "pros" && options.type !== "vexide") {
|
|
8171
|
+
throw new Error("--type must be either pros or vexide");
|
|
8172
|
+
}
|
|
8173
|
+
const path = await createProject(join6(process.cwd(), name), options.type, name);
|
|
8174
|
+
console.log(`created ${options.type} project at ${path}`);
|
|
8175
|
+
});
|
|
8176
|
+
}
|
|
10050
8177
|
|
|
10051
8178
|
// src/commands/init.ts
|
|
10052
8179
|
import { basename as basename3, resolve as resolve3 } from "path";
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
8180
|
+
function registerInitCommand(program) {
|
|
8181
|
+
program.command("init [path]", "create a new V5 program in an empty directory").option("-t, --type", "project toolchain").action(async (inputPath, options) => {
|
|
8182
|
+
inputPath ??= process.cwd();
|
|
8183
|
+
if (options.type !== "pros" && options.type !== "vexide") {
|
|
8184
|
+
throw new Error("--type must be either pros or vexide");
|
|
8185
|
+
}
|
|
8186
|
+
const path = resolve3(inputPath);
|
|
8187
|
+
await createProject(path, options.type, basename3(path));
|
|
8188
|
+
console.log(`created ${options.type} project at ${path}`);
|
|
8189
|
+
});
|
|
8190
|
+
}
|
|
10059
8191
|
|
|
10060
8192
|
// src/commands/rm.ts
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
8193
|
+
function registerRmCommand(program) {
|
|
8194
|
+
program.command("rm <file>", "erase a file from flash").action(async (file) => {
|
|
8195
|
+
const device = await connectV5Device();
|
|
8196
|
+
const ok = await device.brain.removeFile(file);
|
|
8197
|
+
if (ok)
|
|
8198
|
+
console.log(`erased ${file}`);
|
|
8199
|
+
else
|
|
8200
|
+
console.log(`failed to erase ${file}`);
|
|
8201
|
+
await device.dispose();
|
|
8202
|
+
});
|
|
8203
|
+
}
|
|
10071
8204
|
|
|
10072
8205
|
// src/commands/screenshot.ts
|
|
10073
8206
|
function printKittyRGB(bytes) {
|
|
@@ -10080,45 +8213,62 @@ function printKittyRGB(bytes) {
|
|
|
10080
8213
|
process.stdout.write(`\x1B_G` + `a=T,` + `f=24,` + `s=${WIDTH},` + `v=${HEIGHT},` + `c=40;` + base64 + `\x1B\\
|
|
10081
8214
|
`);
|
|
10082
8215
|
}
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
8216
|
+
function registerScreenshotCommand(program) {
|
|
8217
|
+
program.command("screenshot", "take a screen capture of the brain", {
|
|
8218
|
+
alias: "sc"
|
|
8219
|
+
}).action(async () => {
|
|
8220
|
+
const device = await connectV5Device();
|
|
8221
|
+
const data = await device.brain.captureScreen();
|
|
8222
|
+
if (data)
|
|
8223
|
+
printKittyRGB(data);
|
|
8224
|
+
await device.dispose();
|
|
8225
|
+
});
|
|
8226
|
+
}
|
|
10091
8227
|
|
|
10092
8228
|
// src/commands/install.ts
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
}
|
|
10108
|
-
var install_default = installCommand;
|
|
8229
|
+
function registerInstallCommand(program) {
|
|
8230
|
+
program.command("install <toolchain>", "install a V5 development toolchain").action(async (toolchain) => {
|
|
8231
|
+
if (toolchain !== "pros" && toolchain !== "vexide") {
|
|
8232
|
+
throw new Error("toolchain must be either pros or vexide");
|
|
8233
|
+
}
|
|
8234
|
+
if (toolchain === "vexide") {
|
|
8235
|
+
await runProcess(["cargo", "install", "cargo-v5"], process.cwd());
|
|
8236
|
+
return;
|
|
8237
|
+
}
|
|
8238
|
+
const python = Bun.which("python3") ?? Bun.which("python");
|
|
8239
|
+
if (python === null)
|
|
8240
|
+
throw new Error("Python is required to install PROS");
|
|
8241
|
+
await runProcess([python, "-m", "pip", "install", "--user", "pros-cli"], process.cwd());
|
|
8242
|
+
});
|
|
8243
|
+
}
|
|
10109
8244
|
|
|
10110
8245
|
// src/commands/clean.ts
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
});
|
|
10116
|
-
|
|
8246
|
+
function registerCleanCommand(program) {
|
|
8247
|
+
program.command("clean [path]", "clean build outputs", { alias: "cl" }).action(async (path) => {
|
|
8248
|
+
path ??= process.cwd();
|
|
8249
|
+
const project = await inspectProject(path);
|
|
8250
|
+
console.log(source_default.yellow(`cleaning ${project.type} program...`));
|
|
8251
|
+
await cleanProject(project);
|
|
8252
|
+
});
|
|
8253
|
+
}
|
|
10117
8254
|
|
|
10118
8255
|
// src/index.ts
|
|
10119
|
-
program
|
|
8256
|
+
var program = lib_default2("v5x").version(package_default.version).describe(package_default.description);
|
|
8257
|
+
registerBuildCommand(program);
|
|
8258
|
+
registerCleanCommand(program);
|
|
8259
|
+
registerUploadCommand(program);
|
|
8260
|
+
registerRunCommand(program);
|
|
8261
|
+
registerNewCommand(program);
|
|
8262
|
+
registerInitCommand(program);
|
|
8263
|
+
registerDirCommand(program);
|
|
8264
|
+
registerCatCommand(program);
|
|
8265
|
+
registerRmCommand(program);
|
|
8266
|
+
registerDevicesCommand(program);
|
|
8267
|
+
registerScreenshotCommand(program);
|
|
8268
|
+
registerInstallCommand(program);
|
|
8269
|
+
registerKvCommand(program);
|
|
10120
8270
|
try {
|
|
10121
|
-
await program.
|
|
8271
|
+
await program.parse(process.argv);
|
|
10122
8272
|
} catch (error) {
|
|
10123
8273
|
console.error(error instanceof Error ? error.message : String(error));
|
|
10124
8274
|
process.exitCode = 1;
|