@ork.so/ork-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.js +4897 -0
- package/package.json +40 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4897 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __ork_cr } from 'node:module';
|
|
3
|
+
const require = __ork_cr(import.meta.url);
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __require = /* @__PURE__ */ ((x3) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x3, {
|
|
11
|
+
get: (a3, b3) => (typeof require !== "undefined" ? require : a3)[b3]
|
|
12
|
+
}) : x3)(function(x3) {
|
|
13
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
|
+
throw Error('Dynamic require of "' + x3 + '" is not supported');
|
|
15
|
+
});
|
|
16
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/commander/lib/error.js
|
|
37
|
+
var require_error = __commonJS({
|
|
38
|
+
"../../node_modules/commander/lib/error.js"(exports) {
|
|
39
|
+
var CommanderError2 = class extends Error {
|
|
40
|
+
/**
|
|
41
|
+
* Constructs the CommanderError class
|
|
42
|
+
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
43
|
+
* @param {string} code an id string representing the error
|
|
44
|
+
* @param {string} message human-readable description of the error
|
|
45
|
+
*/
|
|
46
|
+
constructor(exitCode, code, message) {
|
|
47
|
+
super(message);
|
|
48
|
+
Error.captureStackTrace(this, this.constructor);
|
|
49
|
+
this.name = this.constructor.name;
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.exitCode = exitCode;
|
|
52
|
+
this.nestedError = void 0;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
56
|
+
/**
|
|
57
|
+
* Constructs the InvalidArgumentError class
|
|
58
|
+
* @param {string} [message] explanation of why argument is invalid
|
|
59
|
+
*/
|
|
60
|
+
constructor(message) {
|
|
61
|
+
super(1, "commander.invalidArgument", message);
|
|
62
|
+
Error.captureStackTrace(this, this.constructor);
|
|
63
|
+
this.name = this.constructor.name;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.CommanderError = CommanderError2;
|
|
67
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// ../../node_modules/commander/lib/argument.js
|
|
72
|
+
var require_argument = __commonJS({
|
|
73
|
+
"../../node_modules/commander/lib/argument.js"(exports) {
|
|
74
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
75
|
+
var Argument2 = class {
|
|
76
|
+
/**
|
|
77
|
+
* Initialize a new command argument with the given name and description.
|
|
78
|
+
* The default is that the argument is required, and you can explicitly
|
|
79
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} name
|
|
82
|
+
* @param {string} [description]
|
|
83
|
+
*/
|
|
84
|
+
constructor(name, description) {
|
|
85
|
+
this.description = description || "";
|
|
86
|
+
this.variadic = false;
|
|
87
|
+
this.parseArg = void 0;
|
|
88
|
+
this.defaultValue = void 0;
|
|
89
|
+
this.defaultValueDescription = void 0;
|
|
90
|
+
this.argChoices = void 0;
|
|
91
|
+
switch (name[0]) {
|
|
92
|
+
case "<":
|
|
93
|
+
this.required = true;
|
|
94
|
+
this._name = name.slice(1, -1);
|
|
95
|
+
break;
|
|
96
|
+
case "[":
|
|
97
|
+
this.required = false;
|
|
98
|
+
this._name = name.slice(1, -1);
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
this.required = true;
|
|
102
|
+
this._name = name;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
106
|
+
this.variadic = true;
|
|
107
|
+
this._name = this._name.slice(0, -3);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Return argument name.
|
|
112
|
+
*
|
|
113
|
+
* @return {string}
|
|
114
|
+
*/
|
|
115
|
+
name() {
|
|
116
|
+
return this._name;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @package
|
|
120
|
+
*/
|
|
121
|
+
_concatValue(value, previous) {
|
|
122
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
123
|
+
return [value];
|
|
124
|
+
}
|
|
125
|
+
return previous.concat(value);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
129
|
+
*
|
|
130
|
+
* @param {*} value
|
|
131
|
+
* @param {string} [description]
|
|
132
|
+
* @return {Argument}
|
|
133
|
+
*/
|
|
134
|
+
default(value, description) {
|
|
135
|
+
this.defaultValue = value;
|
|
136
|
+
this.defaultValueDescription = description;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set the custom handler for processing CLI command arguments into argument values.
|
|
141
|
+
*
|
|
142
|
+
* @param {Function} [fn]
|
|
143
|
+
* @return {Argument}
|
|
144
|
+
*/
|
|
145
|
+
argParser(fn) {
|
|
146
|
+
this.parseArg = fn;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Only allow argument value to be one of choices.
|
|
151
|
+
*
|
|
152
|
+
* @param {string[]} values
|
|
153
|
+
* @return {Argument}
|
|
154
|
+
*/
|
|
155
|
+
choices(values) {
|
|
156
|
+
this.argChoices = values.slice();
|
|
157
|
+
this.parseArg = (arg, previous) => {
|
|
158
|
+
if (!this.argChoices.includes(arg)) {
|
|
159
|
+
throw new InvalidArgumentError2(
|
|
160
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (this.variadic) {
|
|
164
|
+
return this._concatValue(arg, previous);
|
|
165
|
+
}
|
|
166
|
+
return arg;
|
|
167
|
+
};
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Make argument required.
|
|
172
|
+
*
|
|
173
|
+
* @returns {Argument}
|
|
174
|
+
*/
|
|
175
|
+
argRequired() {
|
|
176
|
+
this.required = true;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Make argument optional.
|
|
181
|
+
*
|
|
182
|
+
* @returns {Argument}
|
|
183
|
+
*/
|
|
184
|
+
argOptional() {
|
|
185
|
+
this.required = false;
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
function humanReadableArgName(arg) {
|
|
190
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
191
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
192
|
+
}
|
|
193
|
+
exports.Argument = Argument2;
|
|
194
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// ../../node_modules/commander/lib/help.js
|
|
199
|
+
var require_help = __commonJS({
|
|
200
|
+
"../../node_modules/commander/lib/help.js"(exports) {
|
|
201
|
+
var { humanReadableArgName } = require_argument();
|
|
202
|
+
var Help2 = class {
|
|
203
|
+
constructor() {
|
|
204
|
+
this.helpWidth = void 0;
|
|
205
|
+
this.sortSubcommands = false;
|
|
206
|
+
this.sortOptions = false;
|
|
207
|
+
this.showGlobalOptions = false;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
211
|
+
*
|
|
212
|
+
* @param {Command} cmd
|
|
213
|
+
* @returns {Command[]}
|
|
214
|
+
*/
|
|
215
|
+
visibleCommands(cmd) {
|
|
216
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
217
|
+
const helpCommand = cmd._getHelpCommand();
|
|
218
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
219
|
+
visibleCommands.push(helpCommand);
|
|
220
|
+
}
|
|
221
|
+
if (this.sortSubcommands) {
|
|
222
|
+
visibleCommands.sort((a3, b3) => {
|
|
223
|
+
return a3.name().localeCompare(b3.name());
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return visibleCommands;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Compare options for sort.
|
|
230
|
+
*
|
|
231
|
+
* @param {Option} a
|
|
232
|
+
* @param {Option} b
|
|
233
|
+
* @returns {number}
|
|
234
|
+
*/
|
|
235
|
+
compareOptions(a3, b3) {
|
|
236
|
+
const getSortKey = (option) => {
|
|
237
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
238
|
+
};
|
|
239
|
+
return getSortKey(a3).localeCompare(getSortKey(b3));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
243
|
+
*
|
|
244
|
+
* @param {Command} cmd
|
|
245
|
+
* @returns {Option[]}
|
|
246
|
+
*/
|
|
247
|
+
visibleOptions(cmd) {
|
|
248
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
249
|
+
const helpOption = cmd._getHelpOption();
|
|
250
|
+
if (helpOption && !helpOption.hidden) {
|
|
251
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
252
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
253
|
+
if (!removeShort && !removeLong) {
|
|
254
|
+
visibleOptions.push(helpOption);
|
|
255
|
+
} else if (helpOption.long && !removeLong) {
|
|
256
|
+
visibleOptions.push(
|
|
257
|
+
cmd.createOption(helpOption.long, helpOption.description)
|
|
258
|
+
);
|
|
259
|
+
} else if (helpOption.short && !removeShort) {
|
|
260
|
+
visibleOptions.push(
|
|
261
|
+
cmd.createOption(helpOption.short, helpOption.description)
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (this.sortOptions) {
|
|
266
|
+
visibleOptions.sort(this.compareOptions);
|
|
267
|
+
}
|
|
268
|
+
return visibleOptions;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get an array of the visible global options. (Not including help.)
|
|
272
|
+
*
|
|
273
|
+
* @param {Command} cmd
|
|
274
|
+
* @returns {Option[]}
|
|
275
|
+
*/
|
|
276
|
+
visibleGlobalOptions(cmd) {
|
|
277
|
+
if (!this.showGlobalOptions) return [];
|
|
278
|
+
const globalOptions = [];
|
|
279
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
280
|
+
const visibleOptions = ancestorCmd.options.filter(
|
|
281
|
+
(option) => !option.hidden
|
|
282
|
+
);
|
|
283
|
+
globalOptions.push(...visibleOptions);
|
|
284
|
+
}
|
|
285
|
+
if (this.sortOptions) {
|
|
286
|
+
globalOptions.sort(this.compareOptions);
|
|
287
|
+
}
|
|
288
|
+
return globalOptions;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Get an array of the arguments if any have a description.
|
|
292
|
+
*
|
|
293
|
+
* @param {Command} cmd
|
|
294
|
+
* @returns {Argument[]}
|
|
295
|
+
*/
|
|
296
|
+
visibleArguments(cmd) {
|
|
297
|
+
if (cmd._argsDescription) {
|
|
298
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
299
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
303
|
+
return cmd.registeredArguments;
|
|
304
|
+
}
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get the command term to show in the list of subcommands.
|
|
309
|
+
*
|
|
310
|
+
* @param {Command} cmd
|
|
311
|
+
* @returns {string}
|
|
312
|
+
*/
|
|
313
|
+
subcommandTerm(cmd) {
|
|
314
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
315
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
316
|
+
(args ? " " + args : "");
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get the option term to show in the list of options.
|
|
320
|
+
*
|
|
321
|
+
* @param {Option} option
|
|
322
|
+
* @returns {string}
|
|
323
|
+
*/
|
|
324
|
+
optionTerm(option) {
|
|
325
|
+
return option.flags;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the argument term to show in the list of arguments.
|
|
329
|
+
*
|
|
330
|
+
* @param {Argument} argument
|
|
331
|
+
* @returns {string}
|
|
332
|
+
*/
|
|
333
|
+
argumentTerm(argument) {
|
|
334
|
+
return argument.name();
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get the longest command term length.
|
|
338
|
+
*
|
|
339
|
+
* @param {Command} cmd
|
|
340
|
+
* @param {Help} helper
|
|
341
|
+
* @returns {number}
|
|
342
|
+
*/
|
|
343
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
344
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
345
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
346
|
+
}, 0);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Get the longest option term length.
|
|
350
|
+
*
|
|
351
|
+
* @param {Command} cmd
|
|
352
|
+
* @param {Help} helper
|
|
353
|
+
* @returns {number}
|
|
354
|
+
*/
|
|
355
|
+
longestOptionTermLength(cmd, helper) {
|
|
356
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
357
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
358
|
+
}, 0);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Get the longest global option term length.
|
|
362
|
+
*
|
|
363
|
+
* @param {Command} cmd
|
|
364
|
+
* @param {Help} helper
|
|
365
|
+
* @returns {number}
|
|
366
|
+
*/
|
|
367
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
368
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
369
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
370
|
+
}, 0);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get the longest argument term length.
|
|
374
|
+
*
|
|
375
|
+
* @param {Command} cmd
|
|
376
|
+
* @param {Help} helper
|
|
377
|
+
* @returns {number}
|
|
378
|
+
*/
|
|
379
|
+
longestArgumentTermLength(cmd, helper) {
|
|
380
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
381
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
382
|
+
}, 0);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
386
|
+
*
|
|
387
|
+
* @param {Command} cmd
|
|
388
|
+
* @returns {string}
|
|
389
|
+
*/
|
|
390
|
+
commandUsage(cmd) {
|
|
391
|
+
let cmdName = cmd._name;
|
|
392
|
+
if (cmd._aliases[0]) {
|
|
393
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
394
|
+
}
|
|
395
|
+
let ancestorCmdNames = "";
|
|
396
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
397
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
398
|
+
}
|
|
399
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Get the description for the command.
|
|
403
|
+
*
|
|
404
|
+
* @param {Command} cmd
|
|
405
|
+
* @returns {string}
|
|
406
|
+
*/
|
|
407
|
+
commandDescription(cmd) {
|
|
408
|
+
return cmd.description();
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
412
|
+
* (Fallback to description for backwards compatibility.)
|
|
413
|
+
*
|
|
414
|
+
* @param {Command} cmd
|
|
415
|
+
* @returns {string}
|
|
416
|
+
*/
|
|
417
|
+
subcommandDescription(cmd) {
|
|
418
|
+
return cmd.summary() || cmd.description();
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Get the option description to show in the list of options.
|
|
422
|
+
*
|
|
423
|
+
* @param {Option} option
|
|
424
|
+
* @return {string}
|
|
425
|
+
*/
|
|
426
|
+
optionDescription(option) {
|
|
427
|
+
const extraInfo = [];
|
|
428
|
+
if (option.argChoices) {
|
|
429
|
+
extraInfo.push(
|
|
430
|
+
// use stringify to match the display of the default value
|
|
431
|
+
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
if (option.defaultValue !== void 0) {
|
|
435
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
436
|
+
if (showDefault) {
|
|
437
|
+
extraInfo.push(
|
|
438
|
+
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (option.presetArg !== void 0 && option.optional) {
|
|
443
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
444
|
+
}
|
|
445
|
+
if (option.envVar !== void 0) {
|
|
446
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
447
|
+
}
|
|
448
|
+
if (extraInfo.length > 0) {
|
|
449
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
450
|
+
}
|
|
451
|
+
return option.description;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Get the argument description to show in the list of arguments.
|
|
455
|
+
*
|
|
456
|
+
* @param {Argument} argument
|
|
457
|
+
* @return {string}
|
|
458
|
+
*/
|
|
459
|
+
argumentDescription(argument) {
|
|
460
|
+
const extraInfo = [];
|
|
461
|
+
if (argument.argChoices) {
|
|
462
|
+
extraInfo.push(
|
|
463
|
+
// use stringify to match the display of the default value
|
|
464
|
+
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
if (argument.defaultValue !== void 0) {
|
|
468
|
+
extraInfo.push(
|
|
469
|
+
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
if (extraInfo.length > 0) {
|
|
473
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
474
|
+
if (argument.description) {
|
|
475
|
+
return `${argument.description} ${extraDescripton}`;
|
|
476
|
+
}
|
|
477
|
+
return extraDescripton;
|
|
478
|
+
}
|
|
479
|
+
return argument.description;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Generate the built-in help text.
|
|
483
|
+
*
|
|
484
|
+
* @param {Command} cmd
|
|
485
|
+
* @param {Help} helper
|
|
486
|
+
* @returns {string}
|
|
487
|
+
*/
|
|
488
|
+
formatHelp(cmd, helper) {
|
|
489
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
490
|
+
const helpWidth = helper.helpWidth || 80;
|
|
491
|
+
const itemIndentWidth = 2;
|
|
492
|
+
const itemSeparatorWidth = 2;
|
|
493
|
+
function formatItem(term, description) {
|
|
494
|
+
if (description) {
|
|
495
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
496
|
+
return helper.wrap(
|
|
497
|
+
fullText,
|
|
498
|
+
helpWidth - itemIndentWidth,
|
|
499
|
+
termWidth + itemSeparatorWidth
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
return term;
|
|
503
|
+
}
|
|
504
|
+
function formatList(textArray) {
|
|
505
|
+
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
506
|
+
}
|
|
507
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
508
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
509
|
+
if (commandDescription.length > 0) {
|
|
510
|
+
output = output.concat([
|
|
511
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
512
|
+
""
|
|
513
|
+
]);
|
|
514
|
+
}
|
|
515
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
516
|
+
return formatItem(
|
|
517
|
+
helper.argumentTerm(argument),
|
|
518
|
+
helper.argumentDescription(argument)
|
|
519
|
+
);
|
|
520
|
+
});
|
|
521
|
+
if (argumentList.length > 0) {
|
|
522
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
523
|
+
}
|
|
524
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
525
|
+
return formatItem(
|
|
526
|
+
helper.optionTerm(option),
|
|
527
|
+
helper.optionDescription(option)
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
if (optionList.length > 0) {
|
|
531
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
532
|
+
}
|
|
533
|
+
if (this.showGlobalOptions) {
|
|
534
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
535
|
+
return formatItem(
|
|
536
|
+
helper.optionTerm(option),
|
|
537
|
+
helper.optionDescription(option)
|
|
538
|
+
);
|
|
539
|
+
});
|
|
540
|
+
if (globalOptionList.length > 0) {
|
|
541
|
+
output = output.concat([
|
|
542
|
+
"Global Options:",
|
|
543
|
+
formatList(globalOptionList),
|
|
544
|
+
""
|
|
545
|
+
]);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
549
|
+
return formatItem(
|
|
550
|
+
helper.subcommandTerm(cmd2),
|
|
551
|
+
helper.subcommandDescription(cmd2)
|
|
552
|
+
);
|
|
553
|
+
});
|
|
554
|
+
if (commandList.length > 0) {
|
|
555
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
556
|
+
}
|
|
557
|
+
return output.join("\n");
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Calculate the pad width from the maximum term length.
|
|
561
|
+
*
|
|
562
|
+
* @param {Command} cmd
|
|
563
|
+
* @param {Help} helper
|
|
564
|
+
* @returns {number}
|
|
565
|
+
*/
|
|
566
|
+
padWidth(cmd, helper) {
|
|
567
|
+
return Math.max(
|
|
568
|
+
helper.longestOptionTermLength(cmd, helper),
|
|
569
|
+
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
570
|
+
helper.longestSubcommandTermLength(cmd, helper),
|
|
571
|
+
helper.longestArgumentTermLength(cmd, helper)
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Wrap the given string to width characters per line, with lines after the first indented.
|
|
576
|
+
* Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
|
|
577
|
+
*
|
|
578
|
+
* @param {string} str
|
|
579
|
+
* @param {number} width
|
|
580
|
+
* @param {number} indent
|
|
581
|
+
* @param {number} [minColumnWidth=40]
|
|
582
|
+
* @return {string}
|
|
583
|
+
*
|
|
584
|
+
*/
|
|
585
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
586
|
+
const indents = " \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF";
|
|
587
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
588
|
+
if (str.match(manualIndent)) return str;
|
|
589
|
+
const columnWidth = width - indent;
|
|
590
|
+
if (columnWidth < minColumnWidth) return str;
|
|
591
|
+
const leadingStr = str.slice(0, indent);
|
|
592
|
+
const columnText = str.slice(indent).replace("\r\n", "\n");
|
|
593
|
+
const indentString = " ".repeat(indent);
|
|
594
|
+
const zeroWidthSpace = "\u200B";
|
|
595
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
596
|
+
const regex = new RegExp(
|
|
597
|
+
`
|
|
598
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
|
|
599
|
+
"g"
|
|
600
|
+
);
|
|
601
|
+
const lines = columnText.match(regex) || [];
|
|
602
|
+
return leadingStr + lines.map((line, i) => {
|
|
603
|
+
if (line === "\n") return "";
|
|
604
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
605
|
+
}).join("\n");
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
exports.Help = Help2;
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
// ../../node_modules/commander/lib/option.js
|
|
613
|
+
var require_option = __commonJS({
|
|
614
|
+
"../../node_modules/commander/lib/option.js"(exports) {
|
|
615
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
616
|
+
var Option2 = class {
|
|
617
|
+
/**
|
|
618
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
619
|
+
*
|
|
620
|
+
* @param {string} flags
|
|
621
|
+
* @param {string} [description]
|
|
622
|
+
*/
|
|
623
|
+
constructor(flags, description) {
|
|
624
|
+
this.flags = flags;
|
|
625
|
+
this.description = description || "";
|
|
626
|
+
this.required = flags.includes("<");
|
|
627
|
+
this.optional = flags.includes("[");
|
|
628
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
629
|
+
this.mandatory = false;
|
|
630
|
+
const optionFlags = splitOptionFlags(flags);
|
|
631
|
+
this.short = optionFlags.shortFlag;
|
|
632
|
+
this.long = optionFlags.longFlag;
|
|
633
|
+
this.negate = false;
|
|
634
|
+
if (this.long) {
|
|
635
|
+
this.negate = this.long.startsWith("--no-");
|
|
636
|
+
}
|
|
637
|
+
this.defaultValue = void 0;
|
|
638
|
+
this.defaultValueDescription = void 0;
|
|
639
|
+
this.presetArg = void 0;
|
|
640
|
+
this.envVar = void 0;
|
|
641
|
+
this.parseArg = void 0;
|
|
642
|
+
this.hidden = false;
|
|
643
|
+
this.argChoices = void 0;
|
|
644
|
+
this.conflictsWith = [];
|
|
645
|
+
this.implied = void 0;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
649
|
+
*
|
|
650
|
+
* @param {*} value
|
|
651
|
+
* @param {string} [description]
|
|
652
|
+
* @return {Option}
|
|
653
|
+
*/
|
|
654
|
+
default(value, description) {
|
|
655
|
+
this.defaultValue = value;
|
|
656
|
+
this.defaultValueDescription = description;
|
|
657
|
+
return this;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
661
|
+
* The custom processing (parseArg) is called.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* new Option('--color').default('GREYSCALE').preset('RGB');
|
|
665
|
+
* new Option('--donate [amount]').preset('20').argParser(parseFloat);
|
|
666
|
+
*
|
|
667
|
+
* @param {*} arg
|
|
668
|
+
* @return {Option}
|
|
669
|
+
*/
|
|
670
|
+
preset(arg) {
|
|
671
|
+
this.presetArg = arg;
|
|
672
|
+
return this;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Add option name(s) that conflict with this option.
|
|
676
|
+
* An error will be displayed if conflicting options are found during parsing.
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* new Option('--rgb').conflicts('cmyk');
|
|
680
|
+
* new Option('--js').conflicts(['ts', 'jsx']);
|
|
681
|
+
*
|
|
682
|
+
* @param {(string | string[])} names
|
|
683
|
+
* @return {Option}
|
|
684
|
+
*/
|
|
685
|
+
conflicts(names) {
|
|
686
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
687
|
+
return this;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Specify implied option values for when this option is set and the implied options are not.
|
|
691
|
+
*
|
|
692
|
+
* The custom processing (parseArg) is not called on the implied values.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* program
|
|
696
|
+
* .addOption(new Option('--log', 'write logging information to file'))
|
|
697
|
+
* .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
|
|
698
|
+
*
|
|
699
|
+
* @param {object} impliedOptionValues
|
|
700
|
+
* @return {Option}
|
|
701
|
+
*/
|
|
702
|
+
implies(impliedOptionValues) {
|
|
703
|
+
let newImplied = impliedOptionValues;
|
|
704
|
+
if (typeof impliedOptionValues === "string") {
|
|
705
|
+
newImplied = { [impliedOptionValues]: true };
|
|
706
|
+
}
|
|
707
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
708
|
+
return this;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Set environment variable to check for option value.
|
|
712
|
+
*
|
|
713
|
+
* An environment variable is only used if when processed the current option value is
|
|
714
|
+
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
|
|
715
|
+
*
|
|
716
|
+
* @param {string} name
|
|
717
|
+
* @return {Option}
|
|
718
|
+
*/
|
|
719
|
+
env(name) {
|
|
720
|
+
this.envVar = name;
|
|
721
|
+
return this;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Set the custom handler for processing CLI option arguments into option values.
|
|
725
|
+
*
|
|
726
|
+
* @param {Function} [fn]
|
|
727
|
+
* @return {Option}
|
|
728
|
+
*/
|
|
729
|
+
argParser(fn) {
|
|
730
|
+
this.parseArg = fn;
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Whether the option is mandatory and must have a value after parsing.
|
|
735
|
+
*
|
|
736
|
+
* @param {boolean} [mandatory=true]
|
|
737
|
+
* @return {Option}
|
|
738
|
+
*/
|
|
739
|
+
makeOptionMandatory(mandatory = true) {
|
|
740
|
+
this.mandatory = !!mandatory;
|
|
741
|
+
return this;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Hide option in help.
|
|
745
|
+
*
|
|
746
|
+
* @param {boolean} [hide=true]
|
|
747
|
+
* @return {Option}
|
|
748
|
+
*/
|
|
749
|
+
hideHelp(hide = true) {
|
|
750
|
+
this.hidden = !!hide;
|
|
751
|
+
return this;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* @package
|
|
755
|
+
*/
|
|
756
|
+
_concatValue(value, previous) {
|
|
757
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
758
|
+
return [value];
|
|
759
|
+
}
|
|
760
|
+
return previous.concat(value);
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Only allow option value to be one of choices.
|
|
764
|
+
*
|
|
765
|
+
* @param {string[]} values
|
|
766
|
+
* @return {Option}
|
|
767
|
+
*/
|
|
768
|
+
choices(values) {
|
|
769
|
+
this.argChoices = values.slice();
|
|
770
|
+
this.parseArg = (arg, previous) => {
|
|
771
|
+
if (!this.argChoices.includes(arg)) {
|
|
772
|
+
throw new InvalidArgumentError2(
|
|
773
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
if (this.variadic) {
|
|
777
|
+
return this._concatValue(arg, previous);
|
|
778
|
+
}
|
|
779
|
+
return arg;
|
|
780
|
+
};
|
|
781
|
+
return this;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Return option name.
|
|
785
|
+
*
|
|
786
|
+
* @return {string}
|
|
787
|
+
*/
|
|
788
|
+
name() {
|
|
789
|
+
if (this.long) {
|
|
790
|
+
return this.long.replace(/^--/, "");
|
|
791
|
+
}
|
|
792
|
+
return this.short.replace(/^-/, "");
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Return option name, in a camelcase format that can be used
|
|
796
|
+
* as a object attribute key.
|
|
797
|
+
*
|
|
798
|
+
* @return {string}
|
|
799
|
+
*/
|
|
800
|
+
attributeName() {
|
|
801
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Check if `arg` matches the short or long flag.
|
|
805
|
+
*
|
|
806
|
+
* @param {string} arg
|
|
807
|
+
* @return {boolean}
|
|
808
|
+
* @package
|
|
809
|
+
*/
|
|
810
|
+
is(arg) {
|
|
811
|
+
return this.short === arg || this.long === arg;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Return whether a boolean option.
|
|
815
|
+
*
|
|
816
|
+
* Options are one of boolean, negated, required argument, or optional argument.
|
|
817
|
+
*
|
|
818
|
+
* @return {boolean}
|
|
819
|
+
* @package
|
|
820
|
+
*/
|
|
821
|
+
isBoolean() {
|
|
822
|
+
return !this.required && !this.optional && !this.negate;
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
var DualOptions = class {
|
|
826
|
+
/**
|
|
827
|
+
* @param {Option[]} options
|
|
828
|
+
*/
|
|
829
|
+
constructor(options) {
|
|
830
|
+
this.positiveOptions = /* @__PURE__ */ new Map();
|
|
831
|
+
this.negativeOptions = /* @__PURE__ */ new Map();
|
|
832
|
+
this.dualOptions = /* @__PURE__ */ new Set();
|
|
833
|
+
options.forEach((option) => {
|
|
834
|
+
if (option.negate) {
|
|
835
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
836
|
+
} else {
|
|
837
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
this.negativeOptions.forEach((value, key) => {
|
|
841
|
+
if (this.positiveOptions.has(key)) {
|
|
842
|
+
this.dualOptions.add(key);
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Did the value come from the option, and not from possible matching dual option?
|
|
848
|
+
*
|
|
849
|
+
* @param {*} value
|
|
850
|
+
* @param {Option} option
|
|
851
|
+
* @returns {boolean}
|
|
852
|
+
*/
|
|
853
|
+
valueFromOption(value, option) {
|
|
854
|
+
const optionKey = option.attributeName();
|
|
855
|
+
if (!this.dualOptions.has(optionKey)) return true;
|
|
856
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
857
|
+
const negativeValue = preset !== void 0 ? preset : false;
|
|
858
|
+
return option.negate === (negativeValue === value);
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
function camelcase(str) {
|
|
862
|
+
return str.split("-").reduce((str2, word) => {
|
|
863
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
function splitOptionFlags(flags) {
|
|
867
|
+
let shortFlag;
|
|
868
|
+
let longFlag;
|
|
869
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
870
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
871
|
+
shortFlag = flagParts.shift();
|
|
872
|
+
longFlag = flagParts.shift();
|
|
873
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
874
|
+
shortFlag = longFlag;
|
|
875
|
+
longFlag = void 0;
|
|
876
|
+
}
|
|
877
|
+
return { shortFlag, longFlag };
|
|
878
|
+
}
|
|
879
|
+
exports.Option = Option2;
|
|
880
|
+
exports.DualOptions = DualOptions;
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
// ../../node_modules/commander/lib/suggestSimilar.js
|
|
885
|
+
var require_suggestSimilar = __commonJS({
|
|
886
|
+
"../../node_modules/commander/lib/suggestSimilar.js"(exports) {
|
|
887
|
+
var maxDistance = 3;
|
|
888
|
+
function editDistance(a3, b3) {
|
|
889
|
+
if (Math.abs(a3.length - b3.length) > maxDistance)
|
|
890
|
+
return Math.max(a3.length, b3.length);
|
|
891
|
+
const d3 = [];
|
|
892
|
+
for (let i = 0; i <= a3.length; i++) {
|
|
893
|
+
d3[i] = [i];
|
|
894
|
+
}
|
|
895
|
+
for (let j2 = 0; j2 <= b3.length; j2++) {
|
|
896
|
+
d3[0][j2] = j2;
|
|
897
|
+
}
|
|
898
|
+
for (let j2 = 1; j2 <= b3.length; j2++) {
|
|
899
|
+
for (let i = 1; i <= a3.length; i++) {
|
|
900
|
+
let cost = 1;
|
|
901
|
+
if (a3[i - 1] === b3[j2 - 1]) {
|
|
902
|
+
cost = 0;
|
|
903
|
+
} else {
|
|
904
|
+
cost = 1;
|
|
905
|
+
}
|
|
906
|
+
d3[i][j2] = Math.min(
|
|
907
|
+
d3[i - 1][j2] + 1,
|
|
908
|
+
// deletion
|
|
909
|
+
d3[i][j2 - 1] + 1,
|
|
910
|
+
// insertion
|
|
911
|
+
d3[i - 1][j2 - 1] + cost
|
|
912
|
+
// substitution
|
|
913
|
+
);
|
|
914
|
+
if (i > 1 && j2 > 1 && a3[i - 1] === b3[j2 - 2] && a3[i - 2] === b3[j2 - 1]) {
|
|
915
|
+
d3[i][j2] = Math.min(d3[i][j2], d3[i - 2][j2 - 2] + 1);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return d3[a3.length][b3.length];
|
|
920
|
+
}
|
|
921
|
+
function suggestSimilar(word, candidates) {
|
|
922
|
+
if (!candidates || candidates.length === 0) return "";
|
|
923
|
+
candidates = Array.from(new Set(candidates));
|
|
924
|
+
const searchingOptions = word.startsWith("--");
|
|
925
|
+
if (searchingOptions) {
|
|
926
|
+
word = word.slice(2);
|
|
927
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
928
|
+
}
|
|
929
|
+
let similar = [];
|
|
930
|
+
let bestDistance = maxDistance;
|
|
931
|
+
const minSimilarity = 0.4;
|
|
932
|
+
candidates.forEach((candidate) => {
|
|
933
|
+
if (candidate.length <= 1) return;
|
|
934
|
+
const distance = editDistance(word, candidate);
|
|
935
|
+
const length = Math.max(word.length, candidate.length);
|
|
936
|
+
const similarity = (length - distance) / length;
|
|
937
|
+
if (similarity > minSimilarity) {
|
|
938
|
+
if (distance < bestDistance) {
|
|
939
|
+
bestDistance = distance;
|
|
940
|
+
similar = [candidate];
|
|
941
|
+
} else if (distance === bestDistance) {
|
|
942
|
+
similar.push(candidate);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
similar.sort((a3, b3) => a3.localeCompare(b3));
|
|
947
|
+
if (searchingOptions) {
|
|
948
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
949
|
+
}
|
|
950
|
+
if (similar.length > 1) {
|
|
951
|
+
return `
|
|
952
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
953
|
+
}
|
|
954
|
+
if (similar.length === 1) {
|
|
955
|
+
return `
|
|
956
|
+
(Did you mean ${similar[0]}?)`;
|
|
957
|
+
}
|
|
958
|
+
return "";
|
|
959
|
+
}
|
|
960
|
+
exports.suggestSimilar = suggestSimilar;
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
// ../../node_modules/commander/lib/command.js
|
|
965
|
+
var require_command = __commonJS({
|
|
966
|
+
"../../node_modules/commander/lib/command.js"(exports) {
|
|
967
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
968
|
+
var childProcess = __require("node:child_process");
|
|
969
|
+
var path = __require("node:path");
|
|
970
|
+
var fs = __require("node:fs");
|
|
971
|
+
var process2 = __require("node:process");
|
|
972
|
+
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
973
|
+
var { CommanderError: CommanderError2 } = require_error();
|
|
974
|
+
var { Help: Help2 } = require_help();
|
|
975
|
+
var { Option: Option2, DualOptions } = require_option();
|
|
976
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
977
|
+
var Command2 = class _Command extends EventEmitter {
|
|
978
|
+
/**
|
|
979
|
+
* Initialize a new `Command`.
|
|
980
|
+
*
|
|
981
|
+
* @param {string} [name]
|
|
982
|
+
*/
|
|
983
|
+
constructor(name) {
|
|
984
|
+
super();
|
|
985
|
+
this.commands = [];
|
|
986
|
+
this.options = [];
|
|
987
|
+
this.parent = null;
|
|
988
|
+
this._allowUnknownOption = false;
|
|
989
|
+
this._allowExcessArguments = true;
|
|
990
|
+
this.registeredArguments = [];
|
|
991
|
+
this._args = this.registeredArguments;
|
|
992
|
+
this.args = [];
|
|
993
|
+
this.rawArgs = [];
|
|
994
|
+
this.processedArgs = [];
|
|
995
|
+
this._scriptPath = null;
|
|
996
|
+
this._name = name || "";
|
|
997
|
+
this._optionValues = {};
|
|
998
|
+
this._optionValueSources = {};
|
|
999
|
+
this._storeOptionsAsProperties = false;
|
|
1000
|
+
this._actionHandler = null;
|
|
1001
|
+
this._executableHandler = false;
|
|
1002
|
+
this._executableFile = null;
|
|
1003
|
+
this._executableDir = null;
|
|
1004
|
+
this._defaultCommandName = null;
|
|
1005
|
+
this._exitCallback = null;
|
|
1006
|
+
this._aliases = [];
|
|
1007
|
+
this._combineFlagAndOptionalValue = true;
|
|
1008
|
+
this._description = "";
|
|
1009
|
+
this._summary = "";
|
|
1010
|
+
this._argsDescription = void 0;
|
|
1011
|
+
this._enablePositionalOptions = false;
|
|
1012
|
+
this._passThroughOptions = false;
|
|
1013
|
+
this._lifeCycleHooks = {};
|
|
1014
|
+
this._showHelpAfterError = false;
|
|
1015
|
+
this._showSuggestionAfterError = true;
|
|
1016
|
+
this._outputConfiguration = {
|
|
1017
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
1018
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
1019
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : void 0,
|
|
1020
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : void 0,
|
|
1021
|
+
outputError: (str, write) => write(str)
|
|
1022
|
+
};
|
|
1023
|
+
this._hidden = false;
|
|
1024
|
+
this._helpOption = void 0;
|
|
1025
|
+
this._addImplicitHelpCommand = void 0;
|
|
1026
|
+
this._helpCommand = void 0;
|
|
1027
|
+
this._helpConfiguration = {};
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
1031
|
+
*
|
|
1032
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
1033
|
+
*
|
|
1034
|
+
* @param {Command} sourceCommand
|
|
1035
|
+
* @return {Command} `this` command for chaining
|
|
1036
|
+
*/
|
|
1037
|
+
copyInheritedSettings(sourceCommand) {
|
|
1038
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1039
|
+
this._helpOption = sourceCommand._helpOption;
|
|
1040
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
1041
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1042
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
1043
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1044
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1045
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1046
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1047
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1048
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1049
|
+
return this;
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* @returns {Command[]}
|
|
1053
|
+
* @private
|
|
1054
|
+
*/
|
|
1055
|
+
_getCommandAndAncestors() {
|
|
1056
|
+
const result = [];
|
|
1057
|
+
for (let command = this; command; command = command.parent) {
|
|
1058
|
+
result.push(command);
|
|
1059
|
+
}
|
|
1060
|
+
return result;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Define a command.
|
|
1064
|
+
*
|
|
1065
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
1069
|
+
* program
|
|
1070
|
+
* .command('clone <source> [destination]')
|
|
1071
|
+
* .description('clone a repository into a newly created directory')
|
|
1072
|
+
* .action((source, destination) => {
|
|
1073
|
+
* console.log('clone command called');
|
|
1074
|
+
* });
|
|
1075
|
+
*
|
|
1076
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
1077
|
+
* program
|
|
1078
|
+
* .command('start <service>', 'start named service')
|
|
1079
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
1080
|
+
*
|
|
1081
|
+
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
1082
|
+
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
1083
|
+
* @param {object} [execOpts] - configuration options (for executable)
|
|
1084
|
+
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
1085
|
+
*/
|
|
1086
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1087
|
+
let desc = actionOptsOrExecDesc;
|
|
1088
|
+
let opts = execOpts;
|
|
1089
|
+
if (typeof desc === "object" && desc !== null) {
|
|
1090
|
+
opts = desc;
|
|
1091
|
+
desc = null;
|
|
1092
|
+
}
|
|
1093
|
+
opts = opts || {};
|
|
1094
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1095
|
+
const cmd = this.createCommand(name);
|
|
1096
|
+
if (desc) {
|
|
1097
|
+
cmd.description(desc);
|
|
1098
|
+
cmd._executableHandler = true;
|
|
1099
|
+
}
|
|
1100
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1101
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1102
|
+
cmd._executableFile = opts.executableFile || null;
|
|
1103
|
+
if (args) cmd.arguments(args);
|
|
1104
|
+
this._registerCommand(cmd);
|
|
1105
|
+
cmd.parent = this;
|
|
1106
|
+
cmd.copyInheritedSettings(this);
|
|
1107
|
+
if (desc) return this;
|
|
1108
|
+
return cmd;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Factory routine to create a new unattached command.
|
|
1112
|
+
*
|
|
1113
|
+
* See .command() for creating an attached subcommand, which uses this routine to
|
|
1114
|
+
* create the command. You can override createCommand to customise subcommands.
|
|
1115
|
+
*
|
|
1116
|
+
* @param {string} [name]
|
|
1117
|
+
* @return {Command} new command
|
|
1118
|
+
*/
|
|
1119
|
+
createCommand(name) {
|
|
1120
|
+
return new _Command(name);
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
1124
|
+
* or by overriding Help properties using configureHelp().
|
|
1125
|
+
*
|
|
1126
|
+
* @return {Help}
|
|
1127
|
+
*/
|
|
1128
|
+
createHelp() {
|
|
1129
|
+
return Object.assign(new Help2(), this.configureHelp());
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
1133
|
+
* or with a subclass of Help by overriding createHelp().
|
|
1134
|
+
*
|
|
1135
|
+
* @param {object} [configuration] - configuration options
|
|
1136
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1137
|
+
*/
|
|
1138
|
+
configureHelp(configuration) {
|
|
1139
|
+
if (configuration === void 0) return this._helpConfiguration;
|
|
1140
|
+
this._helpConfiguration = configuration;
|
|
1141
|
+
return this;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* The default output goes to stdout and stderr. You can customise this for special
|
|
1145
|
+
* applications. You can also customise the display of errors by overriding outputError.
|
|
1146
|
+
*
|
|
1147
|
+
* The configuration properties are all functions:
|
|
1148
|
+
*
|
|
1149
|
+
* // functions to change where being written, stdout and stderr
|
|
1150
|
+
* writeOut(str)
|
|
1151
|
+
* writeErr(str)
|
|
1152
|
+
* // matching functions to specify width for wrapping help
|
|
1153
|
+
* getOutHelpWidth()
|
|
1154
|
+
* getErrHelpWidth()
|
|
1155
|
+
* // functions based on what is being written out
|
|
1156
|
+
* outputError(str, write) // used for displaying errors, and not used for displaying help
|
|
1157
|
+
*
|
|
1158
|
+
* @param {object} [configuration] - configuration options
|
|
1159
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1160
|
+
*/
|
|
1161
|
+
configureOutput(configuration) {
|
|
1162
|
+
if (configuration === void 0) return this._outputConfiguration;
|
|
1163
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
1164
|
+
return this;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Display the help or a custom message after an error occurs.
|
|
1168
|
+
*
|
|
1169
|
+
* @param {(boolean|string)} [displayHelp]
|
|
1170
|
+
* @return {Command} `this` command for chaining
|
|
1171
|
+
*/
|
|
1172
|
+
showHelpAfterError(displayHelp = true) {
|
|
1173
|
+
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
1174
|
+
this._showHelpAfterError = displayHelp;
|
|
1175
|
+
return this;
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
1179
|
+
*
|
|
1180
|
+
* @param {boolean} [displaySuggestion]
|
|
1181
|
+
* @return {Command} `this` command for chaining
|
|
1182
|
+
*/
|
|
1183
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1184
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1185
|
+
return this;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Add a prepared subcommand.
|
|
1189
|
+
*
|
|
1190
|
+
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
1191
|
+
*
|
|
1192
|
+
* @param {Command} cmd - new subcommand
|
|
1193
|
+
* @param {object} [opts] - configuration options
|
|
1194
|
+
* @return {Command} `this` command for chaining
|
|
1195
|
+
*/
|
|
1196
|
+
addCommand(cmd, opts) {
|
|
1197
|
+
if (!cmd._name) {
|
|
1198
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
1199
|
+
- specify the name in Command constructor or using .name()`);
|
|
1200
|
+
}
|
|
1201
|
+
opts = opts || {};
|
|
1202
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1203
|
+
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
1204
|
+
this._registerCommand(cmd);
|
|
1205
|
+
cmd.parent = this;
|
|
1206
|
+
cmd._checkForBrokenPassThrough();
|
|
1207
|
+
return this;
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Factory routine to create a new unattached argument.
|
|
1211
|
+
*
|
|
1212
|
+
* See .argument() for creating an attached argument, which uses this routine to
|
|
1213
|
+
* create the argument. You can override createArgument to return a custom argument.
|
|
1214
|
+
*
|
|
1215
|
+
* @param {string} name
|
|
1216
|
+
* @param {string} [description]
|
|
1217
|
+
* @return {Argument} new argument
|
|
1218
|
+
*/
|
|
1219
|
+
createArgument(name, description) {
|
|
1220
|
+
return new Argument2(name, description);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Define argument syntax for command.
|
|
1224
|
+
*
|
|
1225
|
+
* The default is that the argument is required, and you can explicitly
|
|
1226
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* program.argument('<input-file>');
|
|
1230
|
+
* program.argument('[output-file]');
|
|
1231
|
+
*
|
|
1232
|
+
* @param {string} name
|
|
1233
|
+
* @param {string} [description]
|
|
1234
|
+
* @param {(Function|*)} [fn] - custom argument processing function
|
|
1235
|
+
* @param {*} [defaultValue]
|
|
1236
|
+
* @return {Command} `this` command for chaining
|
|
1237
|
+
*/
|
|
1238
|
+
argument(name, description, fn, defaultValue) {
|
|
1239
|
+
const argument = this.createArgument(name, description);
|
|
1240
|
+
if (typeof fn === "function") {
|
|
1241
|
+
argument.default(defaultValue).argParser(fn);
|
|
1242
|
+
} else {
|
|
1243
|
+
argument.default(fn);
|
|
1244
|
+
}
|
|
1245
|
+
this.addArgument(argument);
|
|
1246
|
+
return this;
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
1250
|
+
*
|
|
1251
|
+
* See also .argument().
|
|
1252
|
+
*
|
|
1253
|
+
* @example
|
|
1254
|
+
* program.arguments('<cmd> [env]');
|
|
1255
|
+
*
|
|
1256
|
+
* @param {string} names
|
|
1257
|
+
* @return {Command} `this` command for chaining
|
|
1258
|
+
*/
|
|
1259
|
+
arguments(names) {
|
|
1260
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
1261
|
+
this.argument(detail);
|
|
1262
|
+
});
|
|
1263
|
+
return this;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Define argument syntax for command, adding a prepared argument.
|
|
1267
|
+
*
|
|
1268
|
+
* @param {Argument} argument
|
|
1269
|
+
* @return {Command} `this` command for chaining
|
|
1270
|
+
*/
|
|
1271
|
+
addArgument(argument) {
|
|
1272
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1273
|
+
if (previousArgument && previousArgument.variadic) {
|
|
1274
|
+
throw new Error(
|
|
1275
|
+
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
1279
|
+
throw new Error(
|
|
1280
|
+
`a default value for a required argument is never used: '${argument.name()}'`
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
this.registeredArguments.push(argument);
|
|
1284
|
+
return this;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* program.helpCommand('help [cmd]');
|
|
1291
|
+
* program.helpCommand('help [cmd]', 'show help');
|
|
1292
|
+
* program.helpCommand(false); // suppress default help command
|
|
1293
|
+
* program.helpCommand(true); // add help command even if no subcommands
|
|
1294
|
+
*
|
|
1295
|
+
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
1296
|
+
* @param {string} [description] - custom description
|
|
1297
|
+
* @return {Command} `this` command for chaining
|
|
1298
|
+
*/
|
|
1299
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
1300
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1301
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1302
|
+
return this;
|
|
1303
|
+
}
|
|
1304
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1305
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1306
|
+
const helpDescription = description ?? "display help for command";
|
|
1307
|
+
const helpCommand = this.createCommand(helpName);
|
|
1308
|
+
helpCommand.helpOption(false);
|
|
1309
|
+
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
1310
|
+
if (helpDescription) helpCommand.description(helpDescription);
|
|
1311
|
+
this._addImplicitHelpCommand = true;
|
|
1312
|
+
this._helpCommand = helpCommand;
|
|
1313
|
+
return this;
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Add prepared custom help command.
|
|
1317
|
+
*
|
|
1318
|
+
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
1319
|
+
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
1320
|
+
* @return {Command} `this` command for chaining
|
|
1321
|
+
*/
|
|
1322
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1323
|
+
if (typeof helpCommand !== "object") {
|
|
1324
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1325
|
+
return this;
|
|
1326
|
+
}
|
|
1327
|
+
this._addImplicitHelpCommand = true;
|
|
1328
|
+
this._helpCommand = helpCommand;
|
|
1329
|
+
return this;
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Lazy create help command.
|
|
1333
|
+
*
|
|
1334
|
+
* @return {(Command|null)}
|
|
1335
|
+
* @package
|
|
1336
|
+
*/
|
|
1337
|
+
_getHelpCommand() {
|
|
1338
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
1339
|
+
if (hasImplicitHelpCommand) {
|
|
1340
|
+
if (this._helpCommand === void 0) {
|
|
1341
|
+
this.helpCommand(void 0, void 0);
|
|
1342
|
+
}
|
|
1343
|
+
return this._helpCommand;
|
|
1344
|
+
}
|
|
1345
|
+
return null;
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Add hook for life cycle event.
|
|
1349
|
+
*
|
|
1350
|
+
* @param {string} event
|
|
1351
|
+
* @param {Function} listener
|
|
1352
|
+
* @return {Command} `this` command for chaining
|
|
1353
|
+
*/
|
|
1354
|
+
hook(event, listener) {
|
|
1355
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1356
|
+
if (!allowedValues.includes(event)) {
|
|
1357
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1358
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1359
|
+
}
|
|
1360
|
+
if (this._lifeCycleHooks[event]) {
|
|
1361
|
+
this._lifeCycleHooks[event].push(listener);
|
|
1362
|
+
} else {
|
|
1363
|
+
this._lifeCycleHooks[event] = [listener];
|
|
1364
|
+
}
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Register callback to use as replacement for calling process.exit.
|
|
1369
|
+
*
|
|
1370
|
+
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
1371
|
+
* @return {Command} `this` command for chaining
|
|
1372
|
+
*/
|
|
1373
|
+
exitOverride(fn) {
|
|
1374
|
+
if (fn) {
|
|
1375
|
+
this._exitCallback = fn;
|
|
1376
|
+
} else {
|
|
1377
|
+
this._exitCallback = (err) => {
|
|
1378
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1379
|
+
throw err;
|
|
1380
|
+
} else {
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
return this;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Call process.exit, and _exitCallback if defined.
|
|
1388
|
+
*
|
|
1389
|
+
* @param {number} exitCode exit code for using with process.exit
|
|
1390
|
+
* @param {string} code an id string representing the error
|
|
1391
|
+
* @param {string} message human-readable description of the error
|
|
1392
|
+
* @return never
|
|
1393
|
+
* @private
|
|
1394
|
+
*/
|
|
1395
|
+
_exit(exitCode, code, message) {
|
|
1396
|
+
if (this._exitCallback) {
|
|
1397
|
+
this._exitCallback(new CommanderError2(exitCode, code, message));
|
|
1398
|
+
}
|
|
1399
|
+
process2.exit(exitCode);
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Register callback `fn` for the command.
|
|
1403
|
+
*
|
|
1404
|
+
* @example
|
|
1405
|
+
* program
|
|
1406
|
+
* .command('serve')
|
|
1407
|
+
* .description('start service')
|
|
1408
|
+
* .action(function() {
|
|
1409
|
+
* // do work here
|
|
1410
|
+
* });
|
|
1411
|
+
*
|
|
1412
|
+
* @param {Function} fn
|
|
1413
|
+
* @return {Command} `this` command for chaining
|
|
1414
|
+
*/
|
|
1415
|
+
action(fn) {
|
|
1416
|
+
const listener = (args) => {
|
|
1417
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1418
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1419
|
+
if (this._storeOptionsAsProperties) {
|
|
1420
|
+
actionArgs[expectedArgsCount] = this;
|
|
1421
|
+
} else {
|
|
1422
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
1423
|
+
}
|
|
1424
|
+
actionArgs.push(this);
|
|
1425
|
+
return fn.apply(this, actionArgs);
|
|
1426
|
+
};
|
|
1427
|
+
this._actionHandler = listener;
|
|
1428
|
+
return this;
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Factory routine to create a new unattached option.
|
|
1432
|
+
*
|
|
1433
|
+
* See .option() for creating an attached option, which uses this routine to
|
|
1434
|
+
* create the option. You can override createOption to return a custom option.
|
|
1435
|
+
*
|
|
1436
|
+
* @param {string} flags
|
|
1437
|
+
* @param {string} [description]
|
|
1438
|
+
* @return {Option} new option
|
|
1439
|
+
*/
|
|
1440
|
+
createOption(flags, description) {
|
|
1441
|
+
return new Option2(flags, description);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
1445
|
+
*
|
|
1446
|
+
* @param {(Option | Argument)} target
|
|
1447
|
+
* @param {string} value
|
|
1448
|
+
* @param {*} previous
|
|
1449
|
+
* @param {string} invalidArgumentMessage
|
|
1450
|
+
* @private
|
|
1451
|
+
*/
|
|
1452
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1453
|
+
try {
|
|
1454
|
+
return target.parseArg(value, previous);
|
|
1455
|
+
} catch (err) {
|
|
1456
|
+
if (err.code === "commander.invalidArgument") {
|
|
1457
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1458
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1459
|
+
}
|
|
1460
|
+
throw err;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Check for option flag conflicts.
|
|
1465
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
1466
|
+
*
|
|
1467
|
+
* @param {Option} option
|
|
1468
|
+
* @private
|
|
1469
|
+
*/
|
|
1470
|
+
_registerOption(option) {
|
|
1471
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1472
|
+
if (matchingOption) {
|
|
1473
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1474
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1475
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1476
|
+
}
|
|
1477
|
+
this.options.push(option);
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Check for command name and alias conflicts with existing commands.
|
|
1481
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
1482
|
+
*
|
|
1483
|
+
* @param {Command} command
|
|
1484
|
+
* @private
|
|
1485
|
+
*/
|
|
1486
|
+
_registerCommand(command) {
|
|
1487
|
+
const knownBy = (cmd) => {
|
|
1488
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1489
|
+
};
|
|
1490
|
+
const alreadyUsed = knownBy(command).find(
|
|
1491
|
+
(name) => this._findCommand(name)
|
|
1492
|
+
);
|
|
1493
|
+
if (alreadyUsed) {
|
|
1494
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1495
|
+
const newCmd = knownBy(command).join("|");
|
|
1496
|
+
throw new Error(
|
|
1497
|
+
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
this.commands.push(command);
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Add an option.
|
|
1504
|
+
*
|
|
1505
|
+
* @param {Option} option
|
|
1506
|
+
* @return {Command} `this` command for chaining
|
|
1507
|
+
*/
|
|
1508
|
+
addOption(option) {
|
|
1509
|
+
this._registerOption(option);
|
|
1510
|
+
const oname = option.name();
|
|
1511
|
+
const name = option.attributeName();
|
|
1512
|
+
if (option.negate) {
|
|
1513
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1514
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
1515
|
+
this.setOptionValueWithSource(
|
|
1516
|
+
name,
|
|
1517
|
+
option.defaultValue === void 0 ? true : option.defaultValue,
|
|
1518
|
+
"default"
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
} else if (option.defaultValue !== void 0) {
|
|
1522
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1523
|
+
}
|
|
1524
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1525
|
+
if (val == null && option.presetArg !== void 0) {
|
|
1526
|
+
val = option.presetArg;
|
|
1527
|
+
}
|
|
1528
|
+
const oldValue = this.getOptionValue(name);
|
|
1529
|
+
if (val !== null && option.parseArg) {
|
|
1530
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1531
|
+
} else if (val !== null && option.variadic) {
|
|
1532
|
+
val = option._concatValue(val, oldValue);
|
|
1533
|
+
}
|
|
1534
|
+
if (val == null) {
|
|
1535
|
+
if (option.negate) {
|
|
1536
|
+
val = false;
|
|
1537
|
+
} else if (option.isBoolean() || option.optional) {
|
|
1538
|
+
val = true;
|
|
1539
|
+
} else {
|
|
1540
|
+
val = "";
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1544
|
+
};
|
|
1545
|
+
this.on("option:" + oname, (val) => {
|
|
1546
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1547
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1548
|
+
});
|
|
1549
|
+
if (option.envVar) {
|
|
1550
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
1551
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1552
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
return this;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Internal implementation shared by .option() and .requiredOption()
|
|
1559
|
+
*
|
|
1560
|
+
* @return {Command} `this` command for chaining
|
|
1561
|
+
* @private
|
|
1562
|
+
*/
|
|
1563
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1564
|
+
if (typeof flags === "object" && flags instanceof Option2) {
|
|
1565
|
+
throw new Error(
|
|
1566
|
+
"To add an Option object use addOption() instead of option() or requiredOption()"
|
|
1567
|
+
);
|
|
1568
|
+
}
|
|
1569
|
+
const option = this.createOption(flags, description);
|
|
1570
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1571
|
+
if (typeof fn === "function") {
|
|
1572
|
+
option.default(defaultValue).argParser(fn);
|
|
1573
|
+
} else if (fn instanceof RegExp) {
|
|
1574
|
+
const regex = fn;
|
|
1575
|
+
fn = (val, def) => {
|
|
1576
|
+
const m2 = regex.exec(val);
|
|
1577
|
+
return m2 ? m2[0] : def;
|
|
1578
|
+
};
|
|
1579
|
+
option.default(defaultValue).argParser(fn);
|
|
1580
|
+
} else {
|
|
1581
|
+
option.default(fn);
|
|
1582
|
+
}
|
|
1583
|
+
return this.addOption(option);
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
1587
|
+
*
|
|
1588
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
1589
|
+
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
1590
|
+
*
|
|
1591
|
+
* See the README for more details, and see also addOption() and requiredOption().
|
|
1592
|
+
*
|
|
1593
|
+
* @example
|
|
1594
|
+
* program
|
|
1595
|
+
* .option('-p, --pepper', 'add pepper')
|
|
1596
|
+
* .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
1597
|
+
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
1598
|
+
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
1599
|
+
*
|
|
1600
|
+
* @param {string} flags
|
|
1601
|
+
* @param {string} [description]
|
|
1602
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
1603
|
+
* @param {*} [defaultValue]
|
|
1604
|
+
* @return {Command} `this` command for chaining
|
|
1605
|
+
*/
|
|
1606
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1607
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Add a required option which must have a value after parsing. This usually means
|
|
1611
|
+
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
1612
|
+
*
|
|
1613
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
1614
|
+
*
|
|
1615
|
+
* @param {string} flags
|
|
1616
|
+
* @param {string} [description]
|
|
1617
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
1618
|
+
* @param {*} [defaultValue]
|
|
1619
|
+
* @return {Command} `this` command for chaining
|
|
1620
|
+
*/
|
|
1621
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1622
|
+
return this._optionEx(
|
|
1623
|
+
{ mandatory: true },
|
|
1624
|
+
flags,
|
|
1625
|
+
description,
|
|
1626
|
+
parseArg,
|
|
1627
|
+
defaultValue
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Alter parsing of short flags with optional values.
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* // for `.option('-f,--flag [value]'):
|
|
1635
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
1636
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
1637
|
+
*
|
|
1638
|
+
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
1639
|
+
* @return {Command} `this` command for chaining
|
|
1640
|
+
*/
|
|
1641
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1642
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1643
|
+
return this;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Allow unknown options on the command line.
|
|
1647
|
+
*
|
|
1648
|
+
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
1649
|
+
* @return {Command} `this` command for chaining
|
|
1650
|
+
*/
|
|
1651
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1652
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1653
|
+
return this;
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
1657
|
+
*
|
|
1658
|
+
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
1659
|
+
* @return {Command} `this` command for chaining
|
|
1660
|
+
*/
|
|
1661
|
+
allowExcessArguments(allowExcess = true) {
|
|
1662
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1663
|
+
return this;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
1667
|
+
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
1668
|
+
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
1669
|
+
*
|
|
1670
|
+
* @param {boolean} [positional]
|
|
1671
|
+
* @return {Command} `this` command for chaining
|
|
1672
|
+
*/
|
|
1673
|
+
enablePositionalOptions(positional = true) {
|
|
1674
|
+
this._enablePositionalOptions = !!positional;
|
|
1675
|
+
return this;
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
1679
|
+
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
1680
|
+
* positional options to have been enabled on the program (parent commands).
|
|
1681
|
+
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
1682
|
+
*
|
|
1683
|
+
* @param {boolean} [passThrough] for unknown options.
|
|
1684
|
+
* @return {Command} `this` command for chaining
|
|
1685
|
+
*/
|
|
1686
|
+
passThroughOptions(passThrough = true) {
|
|
1687
|
+
this._passThroughOptions = !!passThrough;
|
|
1688
|
+
this._checkForBrokenPassThrough();
|
|
1689
|
+
return this;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* @private
|
|
1693
|
+
*/
|
|
1694
|
+
_checkForBrokenPassThrough() {
|
|
1695
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1696
|
+
throw new Error(
|
|
1697
|
+
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Whether to store option values as properties on command object,
|
|
1703
|
+
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
1704
|
+
*
|
|
1705
|
+
* @param {boolean} [storeAsProperties=true]
|
|
1706
|
+
* @return {Command} `this` command for chaining
|
|
1707
|
+
*/
|
|
1708
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1709
|
+
if (this.options.length) {
|
|
1710
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1711
|
+
}
|
|
1712
|
+
if (Object.keys(this._optionValues).length) {
|
|
1713
|
+
throw new Error(
|
|
1714
|
+
"call .storeOptionsAsProperties() before setting option values"
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1718
|
+
return this;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Retrieve option value.
|
|
1722
|
+
*
|
|
1723
|
+
* @param {string} key
|
|
1724
|
+
* @return {object} value
|
|
1725
|
+
*/
|
|
1726
|
+
getOptionValue(key) {
|
|
1727
|
+
if (this._storeOptionsAsProperties) {
|
|
1728
|
+
return this[key];
|
|
1729
|
+
}
|
|
1730
|
+
return this._optionValues[key];
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* Store option value.
|
|
1734
|
+
*
|
|
1735
|
+
* @param {string} key
|
|
1736
|
+
* @param {object} value
|
|
1737
|
+
* @return {Command} `this` command for chaining
|
|
1738
|
+
*/
|
|
1739
|
+
setOptionValue(key, value) {
|
|
1740
|
+
return this.setOptionValueWithSource(key, value, void 0);
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Store option value and where the value came from.
|
|
1744
|
+
*
|
|
1745
|
+
* @param {string} key
|
|
1746
|
+
* @param {object} value
|
|
1747
|
+
* @param {string} source - expected values are default/config/env/cli/implied
|
|
1748
|
+
* @return {Command} `this` command for chaining
|
|
1749
|
+
*/
|
|
1750
|
+
setOptionValueWithSource(key, value, source) {
|
|
1751
|
+
if (this._storeOptionsAsProperties) {
|
|
1752
|
+
this[key] = value;
|
|
1753
|
+
} else {
|
|
1754
|
+
this._optionValues[key] = value;
|
|
1755
|
+
}
|
|
1756
|
+
this._optionValueSources[key] = source;
|
|
1757
|
+
return this;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Get source of option value.
|
|
1761
|
+
* Expected values are default | config | env | cli | implied
|
|
1762
|
+
*
|
|
1763
|
+
* @param {string} key
|
|
1764
|
+
* @return {string}
|
|
1765
|
+
*/
|
|
1766
|
+
getOptionValueSource(key) {
|
|
1767
|
+
return this._optionValueSources[key];
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
1771
|
+
* Expected values are default | config | env | cli | implied
|
|
1772
|
+
*
|
|
1773
|
+
* @param {string} key
|
|
1774
|
+
* @return {string}
|
|
1775
|
+
*/
|
|
1776
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1777
|
+
let source;
|
|
1778
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1779
|
+
if (cmd.getOptionValueSource(key) !== void 0) {
|
|
1780
|
+
source = cmd.getOptionValueSource(key);
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
return source;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Get user arguments from implied or explicit arguments.
|
|
1787
|
+
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
1788
|
+
*
|
|
1789
|
+
* @private
|
|
1790
|
+
*/
|
|
1791
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1792
|
+
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
1793
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1794
|
+
}
|
|
1795
|
+
parseOptions = parseOptions || {};
|
|
1796
|
+
if (argv === void 0 && parseOptions.from === void 0) {
|
|
1797
|
+
if (process2.versions?.electron) {
|
|
1798
|
+
parseOptions.from = "electron";
|
|
1799
|
+
}
|
|
1800
|
+
const execArgv = process2.execArgv ?? [];
|
|
1801
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1802
|
+
parseOptions.from = "eval";
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (argv === void 0) {
|
|
1806
|
+
argv = process2.argv;
|
|
1807
|
+
}
|
|
1808
|
+
this.rawArgs = argv.slice();
|
|
1809
|
+
let userArgs;
|
|
1810
|
+
switch (parseOptions.from) {
|
|
1811
|
+
case void 0:
|
|
1812
|
+
case "node":
|
|
1813
|
+
this._scriptPath = argv[1];
|
|
1814
|
+
userArgs = argv.slice(2);
|
|
1815
|
+
break;
|
|
1816
|
+
case "electron":
|
|
1817
|
+
if (process2.defaultApp) {
|
|
1818
|
+
this._scriptPath = argv[1];
|
|
1819
|
+
userArgs = argv.slice(2);
|
|
1820
|
+
} else {
|
|
1821
|
+
userArgs = argv.slice(1);
|
|
1822
|
+
}
|
|
1823
|
+
break;
|
|
1824
|
+
case "user":
|
|
1825
|
+
userArgs = argv.slice(0);
|
|
1826
|
+
break;
|
|
1827
|
+
case "eval":
|
|
1828
|
+
userArgs = argv.slice(1);
|
|
1829
|
+
break;
|
|
1830
|
+
default:
|
|
1831
|
+
throw new Error(
|
|
1832
|
+
`unexpected parse option { from: '${parseOptions.from}' }`
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
if (!this._name && this._scriptPath)
|
|
1836
|
+
this.nameFromFilename(this._scriptPath);
|
|
1837
|
+
this._name = this._name || "program";
|
|
1838
|
+
return userArgs;
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
1842
|
+
*
|
|
1843
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
1844
|
+
*
|
|
1845
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
1846
|
+
*
|
|
1847
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
1848
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
1849
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
1850
|
+
* - `'user'`: just user arguments
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
1854
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
1855
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1856
|
+
*
|
|
1857
|
+
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
1858
|
+
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
1859
|
+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
1860
|
+
* @return {Command} `this` command for chaining
|
|
1861
|
+
*/
|
|
1862
|
+
parse(argv, parseOptions) {
|
|
1863
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1864
|
+
this._parseCommand([], userArgs);
|
|
1865
|
+
return this;
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
1869
|
+
*
|
|
1870
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
1871
|
+
*
|
|
1872
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
1873
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
1874
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
1875
|
+
* - `'user'`: just user arguments
|
|
1876
|
+
*
|
|
1877
|
+
* @example
|
|
1878
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
1879
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
1880
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1881
|
+
*
|
|
1882
|
+
* @param {string[]} [argv]
|
|
1883
|
+
* @param {object} [parseOptions]
|
|
1884
|
+
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
1885
|
+
* @return {Promise}
|
|
1886
|
+
*/
|
|
1887
|
+
async parseAsync(argv, parseOptions) {
|
|
1888
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1889
|
+
await this._parseCommand([], userArgs);
|
|
1890
|
+
return this;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Execute a sub-command executable.
|
|
1894
|
+
*
|
|
1895
|
+
* @private
|
|
1896
|
+
*/
|
|
1897
|
+
_executeSubCommand(subcommand, args) {
|
|
1898
|
+
args = args.slice();
|
|
1899
|
+
let launchWithNode = false;
|
|
1900
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1901
|
+
function findFile(baseDir, baseName) {
|
|
1902
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1903
|
+
if (fs.existsSync(localBin)) return localBin;
|
|
1904
|
+
if (sourceExt.includes(path.extname(baseName))) return void 0;
|
|
1905
|
+
const foundExt = sourceExt.find(
|
|
1906
|
+
(ext) => fs.existsSync(`${localBin}${ext}`)
|
|
1907
|
+
);
|
|
1908
|
+
if (foundExt) return `${localBin}${foundExt}`;
|
|
1909
|
+
return void 0;
|
|
1910
|
+
}
|
|
1911
|
+
this._checkForMissingMandatoryOptions();
|
|
1912
|
+
this._checkForConflictingOptions();
|
|
1913
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1914
|
+
let executableDir = this._executableDir || "";
|
|
1915
|
+
if (this._scriptPath) {
|
|
1916
|
+
let resolvedScriptPath;
|
|
1917
|
+
try {
|
|
1918
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1919
|
+
} catch (err) {
|
|
1920
|
+
resolvedScriptPath = this._scriptPath;
|
|
1921
|
+
}
|
|
1922
|
+
executableDir = path.resolve(
|
|
1923
|
+
path.dirname(resolvedScriptPath),
|
|
1924
|
+
executableDir
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
if (executableDir) {
|
|
1928
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1929
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1930
|
+
const legacyName = path.basename(
|
|
1931
|
+
this._scriptPath,
|
|
1932
|
+
path.extname(this._scriptPath)
|
|
1933
|
+
);
|
|
1934
|
+
if (legacyName !== this._name) {
|
|
1935
|
+
localFile = findFile(
|
|
1936
|
+
executableDir,
|
|
1937
|
+
`${legacyName}-${subcommand._name}`
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
executableFile = localFile || executableFile;
|
|
1942
|
+
}
|
|
1943
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1944
|
+
let proc;
|
|
1945
|
+
if (process2.platform !== "win32") {
|
|
1946
|
+
if (launchWithNode) {
|
|
1947
|
+
args.unshift(executableFile);
|
|
1948
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1949
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1950
|
+
} else {
|
|
1951
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1952
|
+
}
|
|
1953
|
+
} else {
|
|
1954
|
+
args.unshift(executableFile);
|
|
1955
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1956
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1957
|
+
}
|
|
1958
|
+
if (!proc.killed) {
|
|
1959
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1960
|
+
signals.forEach((signal) => {
|
|
1961
|
+
process2.on(signal, () => {
|
|
1962
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1963
|
+
proc.kill(signal);
|
|
1964
|
+
}
|
|
1965
|
+
});
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
const exitCallback = this._exitCallback;
|
|
1969
|
+
proc.on("close", (code) => {
|
|
1970
|
+
code = code ?? 1;
|
|
1971
|
+
if (!exitCallback) {
|
|
1972
|
+
process2.exit(code);
|
|
1973
|
+
} else {
|
|
1974
|
+
exitCallback(
|
|
1975
|
+
new CommanderError2(
|
|
1976
|
+
code,
|
|
1977
|
+
"commander.executeSubCommandAsync",
|
|
1978
|
+
"(close)"
|
|
1979
|
+
)
|
|
1980
|
+
);
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
proc.on("error", (err) => {
|
|
1984
|
+
if (err.code === "ENOENT") {
|
|
1985
|
+
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";
|
|
1986
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1987
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1988
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1989
|
+
- ${executableDirMessage}`;
|
|
1990
|
+
throw new Error(executableMissing);
|
|
1991
|
+
} else if (err.code === "EACCES") {
|
|
1992
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1993
|
+
}
|
|
1994
|
+
if (!exitCallback) {
|
|
1995
|
+
process2.exit(1);
|
|
1996
|
+
} else {
|
|
1997
|
+
const wrappedError = new CommanderError2(
|
|
1998
|
+
1,
|
|
1999
|
+
"commander.executeSubCommandAsync",
|
|
2000
|
+
"(error)"
|
|
2001
|
+
);
|
|
2002
|
+
wrappedError.nestedError = err;
|
|
2003
|
+
exitCallback(wrappedError);
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
this.runningCommand = proc;
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* @private
|
|
2010
|
+
*/
|
|
2011
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2012
|
+
const subCommand = this._findCommand(commandName);
|
|
2013
|
+
if (!subCommand) this.help({ error: true });
|
|
2014
|
+
let promiseChain;
|
|
2015
|
+
promiseChain = this._chainOrCallSubCommandHook(
|
|
2016
|
+
promiseChain,
|
|
2017
|
+
subCommand,
|
|
2018
|
+
"preSubcommand"
|
|
2019
|
+
);
|
|
2020
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2021
|
+
if (subCommand._executableHandler) {
|
|
2022
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
2023
|
+
} else {
|
|
2024
|
+
return subCommand._parseCommand(operands, unknown);
|
|
2025
|
+
}
|
|
2026
|
+
});
|
|
2027
|
+
return promiseChain;
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* Invoke help directly if possible, or dispatch if necessary.
|
|
2031
|
+
* e.g. help foo
|
|
2032
|
+
*
|
|
2033
|
+
* @private
|
|
2034
|
+
*/
|
|
2035
|
+
_dispatchHelpCommand(subcommandName) {
|
|
2036
|
+
if (!subcommandName) {
|
|
2037
|
+
this.help();
|
|
2038
|
+
}
|
|
2039
|
+
const subCommand = this._findCommand(subcommandName);
|
|
2040
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
2041
|
+
subCommand.help();
|
|
2042
|
+
}
|
|
2043
|
+
return this._dispatchSubcommand(
|
|
2044
|
+
subcommandName,
|
|
2045
|
+
[],
|
|
2046
|
+
[this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Check this.args against expected this.registeredArguments.
|
|
2051
|
+
*
|
|
2052
|
+
* @private
|
|
2053
|
+
*/
|
|
2054
|
+
_checkNumberOfArguments() {
|
|
2055
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
2056
|
+
if (arg.required && this.args[i] == null) {
|
|
2057
|
+
this.missingArgument(arg.name());
|
|
2058
|
+
}
|
|
2059
|
+
});
|
|
2060
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
2061
|
+
return;
|
|
2062
|
+
}
|
|
2063
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
2064
|
+
this._excessArguments(this.args);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
2069
|
+
*
|
|
2070
|
+
* @private
|
|
2071
|
+
*/
|
|
2072
|
+
_processArguments() {
|
|
2073
|
+
const myParseArg = (argument, value, previous) => {
|
|
2074
|
+
let parsedValue = value;
|
|
2075
|
+
if (value !== null && argument.parseArg) {
|
|
2076
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2077
|
+
parsedValue = this._callParseArg(
|
|
2078
|
+
argument,
|
|
2079
|
+
value,
|
|
2080
|
+
previous,
|
|
2081
|
+
invalidValueMessage
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
return parsedValue;
|
|
2085
|
+
};
|
|
2086
|
+
this._checkNumberOfArguments();
|
|
2087
|
+
const processedArgs = [];
|
|
2088
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2089
|
+
let value = declaredArg.defaultValue;
|
|
2090
|
+
if (declaredArg.variadic) {
|
|
2091
|
+
if (index < this.args.length) {
|
|
2092
|
+
value = this.args.slice(index);
|
|
2093
|
+
if (declaredArg.parseArg) {
|
|
2094
|
+
value = value.reduce((processed, v2) => {
|
|
2095
|
+
return myParseArg(declaredArg, v2, processed);
|
|
2096
|
+
}, declaredArg.defaultValue);
|
|
2097
|
+
}
|
|
2098
|
+
} else if (value === void 0) {
|
|
2099
|
+
value = [];
|
|
2100
|
+
}
|
|
2101
|
+
} else if (index < this.args.length) {
|
|
2102
|
+
value = this.args[index];
|
|
2103
|
+
if (declaredArg.parseArg) {
|
|
2104
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
processedArgs[index] = value;
|
|
2108
|
+
});
|
|
2109
|
+
this.processedArgs = processedArgs;
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Once we have a promise we chain, but call synchronously until then.
|
|
2113
|
+
*
|
|
2114
|
+
* @param {(Promise|undefined)} promise
|
|
2115
|
+
* @param {Function} fn
|
|
2116
|
+
* @return {(Promise|undefined)}
|
|
2117
|
+
* @private
|
|
2118
|
+
*/
|
|
2119
|
+
_chainOrCall(promise, fn) {
|
|
2120
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
2121
|
+
return promise.then(() => fn());
|
|
2122
|
+
}
|
|
2123
|
+
return fn();
|
|
2124
|
+
}
|
|
2125
|
+
/**
|
|
2126
|
+
*
|
|
2127
|
+
* @param {(Promise|undefined)} promise
|
|
2128
|
+
* @param {string} event
|
|
2129
|
+
* @return {(Promise|undefined)}
|
|
2130
|
+
* @private
|
|
2131
|
+
*/
|
|
2132
|
+
_chainOrCallHooks(promise, event) {
|
|
2133
|
+
let result = promise;
|
|
2134
|
+
const hooks = [];
|
|
2135
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
2136
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
2137
|
+
hooks.push({ hookedCommand, callback });
|
|
2138
|
+
});
|
|
2139
|
+
});
|
|
2140
|
+
if (event === "postAction") {
|
|
2141
|
+
hooks.reverse();
|
|
2142
|
+
}
|
|
2143
|
+
hooks.forEach((hookDetail) => {
|
|
2144
|
+
result = this._chainOrCall(result, () => {
|
|
2145
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2146
|
+
});
|
|
2147
|
+
});
|
|
2148
|
+
return result;
|
|
2149
|
+
}
|
|
2150
|
+
/**
|
|
2151
|
+
*
|
|
2152
|
+
* @param {(Promise|undefined)} promise
|
|
2153
|
+
* @param {Command} subCommand
|
|
2154
|
+
* @param {string} event
|
|
2155
|
+
* @return {(Promise|undefined)}
|
|
2156
|
+
* @private
|
|
2157
|
+
*/
|
|
2158
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
2159
|
+
let result = promise;
|
|
2160
|
+
if (this._lifeCycleHooks[event] !== void 0) {
|
|
2161
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
2162
|
+
result = this._chainOrCall(result, () => {
|
|
2163
|
+
return hook(this, subCommand);
|
|
2164
|
+
});
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
return result;
|
|
2168
|
+
}
|
|
2169
|
+
/**
|
|
2170
|
+
* Process arguments in context of this command.
|
|
2171
|
+
* Returns action result, in case it is a promise.
|
|
2172
|
+
*
|
|
2173
|
+
* @private
|
|
2174
|
+
*/
|
|
2175
|
+
_parseCommand(operands, unknown) {
|
|
2176
|
+
const parsed = this.parseOptions(unknown);
|
|
2177
|
+
this._parseOptionsEnv();
|
|
2178
|
+
this._parseOptionsImplied();
|
|
2179
|
+
operands = operands.concat(parsed.operands);
|
|
2180
|
+
unknown = parsed.unknown;
|
|
2181
|
+
this.args = operands.concat(unknown);
|
|
2182
|
+
if (operands && this._findCommand(operands[0])) {
|
|
2183
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
2184
|
+
}
|
|
2185
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
2186
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
2187
|
+
}
|
|
2188
|
+
if (this._defaultCommandName) {
|
|
2189
|
+
this._outputHelpIfRequested(unknown);
|
|
2190
|
+
return this._dispatchSubcommand(
|
|
2191
|
+
this._defaultCommandName,
|
|
2192
|
+
operands,
|
|
2193
|
+
unknown
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
2197
|
+
this.help({ error: true });
|
|
2198
|
+
}
|
|
2199
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
2200
|
+
this._checkForMissingMandatoryOptions();
|
|
2201
|
+
this._checkForConflictingOptions();
|
|
2202
|
+
const checkForUnknownOptions = () => {
|
|
2203
|
+
if (parsed.unknown.length > 0) {
|
|
2204
|
+
this.unknownOption(parsed.unknown[0]);
|
|
2205
|
+
}
|
|
2206
|
+
};
|
|
2207
|
+
const commandEvent = `command:${this.name()}`;
|
|
2208
|
+
if (this._actionHandler) {
|
|
2209
|
+
checkForUnknownOptions();
|
|
2210
|
+
this._processArguments();
|
|
2211
|
+
let promiseChain;
|
|
2212
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
2213
|
+
promiseChain = this._chainOrCall(
|
|
2214
|
+
promiseChain,
|
|
2215
|
+
() => this._actionHandler(this.processedArgs)
|
|
2216
|
+
);
|
|
2217
|
+
if (this.parent) {
|
|
2218
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2219
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
2223
|
+
return promiseChain;
|
|
2224
|
+
}
|
|
2225
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
2226
|
+
checkForUnknownOptions();
|
|
2227
|
+
this._processArguments();
|
|
2228
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2229
|
+
} else if (operands.length) {
|
|
2230
|
+
if (this._findCommand("*")) {
|
|
2231
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
2232
|
+
}
|
|
2233
|
+
if (this.listenerCount("command:*")) {
|
|
2234
|
+
this.emit("command:*", operands, unknown);
|
|
2235
|
+
} else if (this.commands.length) {
|
|
2236
|
+
this.unknownCommand();
|
|
2237
|
+
} else {
|
|
2238
|
+
checkForUnknownOptions();
|
|
2239
|
+
this._processArguments();
|
|
2240
|
+
}
|
|
2241
|
+
} else if (this.commands.length) {
|
|
2242
|
+
checkForUnknownOptions();
|
|
2243
|
+
this.help({ error: true });
|
|
2244
|
+
} else {
|
|
2245
|
+
checkForUnknownOptions();
|
|
2246
|
+
this._processArguments();
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Find matching command.
|
|
2251
|
+
*
|
|
2252
|
+
* @private
|
|
2253
|
+
* @return {Command | undefined}
|
|
2254
|
+
*/
|
|
2255
|
+
_findCommand(name) {
|
|
2256
|
+
if (!name) return void 0;
|
|
2257
|
+
return this.commands.find(
|
|
2258
|
+
(cmd) => cmd._name === name || cmd._aliases.includes(name)
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Return an option matching `arg` if any.
|
|
2263
|
+
*
|
|
2264
|
+
* @param {string} arg
|
|
2265
|
+
* @return {Option}
|
|
2266
|
+
* @package
|
|
2267
|
+
*/
|
|
2268
|
+
_findOption(arg) {
|
|
2269
|
+
return this.options.find((option) => option.is(arg));
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Display an error message if a mandatory option does not have a value.
|
|
2273
|
+
* Called after checking for help flags in leaf subcommand.
|
|
2274
|
+
*
|
|
2275
|
+
* @private
|
|
2276
|
+
*/
|
|
2277
|
+
_checkForMissingMandatoryOptions() {
|
|
2278
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2279
|
+
cmd.options.forEach((anOption) => {
|
|
2280
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
|
|
2281
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Display an error message if conflicting options are used together in this.
|
|
2288
|
+
*
|
|
2289
|
+
* @private
|
|
2290
|
+
*/
|
|
2291
|
+
_checkForConflictingLocalOptions() {
|
|
2292
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
2293
|
+
const optionKey = option.attributeName();
|
|
2294
|
+
if (this.getOptionValue(optionKey) === void 0) {
|
|
2295
|
+
return false;
|
|
2296
|
+
}
|
|
2297
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
2298
|
+
});
|
|
2299
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
2300
|
+
(option) => option.conflictsWith.length > 0
|
|
2301
|
+
);
|
|
2302
|
+
optionsWithConflicting.forEach((option) => {
|
|
2303
|
+
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
2304
|
+
(defined) => option.conflictsWith.includes(defined.attributeName())
|
|
2305
|
+
);
|
|
2306
|
+
if (conflictingAndDefined) {
|
|
2307
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Display an error message if conflicting options are used together.
|
|
2313
|
+
* Called after checking for help flags in leaf subcommand.
|
|
2314
|
+
*
|
|
2315
|
+
* @private
|
|
2316
|
+
*/
|
|
2317
|
+
_checkForConflictingOptions() {
|
|
2318
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2319
|
+
cmd._checkForConflictingLocalOptions();
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Parse options from `argv` removing known options,
|
|
2324
|
+
* and return argv split into operands and unknown arguments.
|
|
2325
|
+
*
|
|
2326
|
+
* Examples:
|
|
2327
|
+
*
|
|
2328
|
+
* argv => operands, unknown
|
|
2329
|
+
* --known kkk op => [op], []
|
|
2330
|
+
* op --known kkk => [op], []
|
|
2331
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
2332
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
2333
|
+
*
|
|
2334
|
+
* @param {string[]} argv
|
|
2335
|
+
* @return {{operands: string[], unknown: string[]}}
|
|
2336
|
+
*/
|
|
2337
|
+
parseOptions(argv) {
|
|
2338
|
+
const operands = [];
|
|
2339
|
+
const unknown = [];
|
|
2340
|
+
let dest = operands;
|
|
2341
|
+
const args = argv.slice();
|
|
2342
|
+
function maybeOption(arg) {
|
|
2343
|
+
return arg.length > 1 && arg[0] === "-";
|
|
2344
|
+
}
|
|
2345
|
+
let activeVariadicOption = null;
|
|
2346
|
+
while (args.length) {
|
|
2347
|
+
const arg = args.shift();
|
|
2348
|
+
if (arg === "--") {
|
|
2349
|
+
if (dest === unknown) dest.push(arg);
|
|
2350
|
+
dest.push(...args);
|
|
2351
|
+
break;
|
|
2352
|
+
}
|
|
2353
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
2354
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2355
|
+
continue;
|
|
2356
|
+
}
|
|
2357
|
+
activeVariadicOption = null;
|
|
2358
|
+
if (maybeOption(arg)) {
|
|
2359
|
+
const option = this._findOption(arg);
|
|
2360
|
+
if (option) {
|
|
2361
|
+
if (option.required) {
|
|
2362
|
+
const value = args.shift();
|
|
2363
|
+
if (value === void 0) this.optionMissingArgument(option);
|
|
2364
|
+
this.emit(`option:${option.name()}`, value);
|
|
2365
|
+
} else if (option.optional) {
|
|
2366
|
+
let value = null;
|
|
2367
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
2368
|
+
value = args.shift();
|
|
2369
|
+
}
|
|
2370
|
+
this.emit(`option:${option.name()}`, value);
|
|
2371
|
+
} else {
|
|
2372
|
+
this.emit(`option:${option.name()}`);
|
|
2373
|
+
}
|
|
2374
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
2375
|
+
continue;
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
2379
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
2380
|
+
if (option) {
|
|
2381
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
2382
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
2383
|
+
} else {
|
|
2384
|
+
this.emit(`option:${option.name()}`);
|
|
2385
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
2386
|
+
}
|
|
2387
|
+
continue;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
2391
|
+
const index = arg.indexOf("=");
|
|
2392
|
+
const option = this._findOption(arg.slice(0, index));
|
|
2393
|
+
if (option && (option.required || option.optional)) {
|
|
2394
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
2395
|
+
continue;
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
if (maybeOption(arg)) {
|
|
2399
|
+
dest = unknown;
|
|
2400
|
+
}
|
|
2401
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2402
|
+
if (this._findCommand(arg)) {
|
|
2403
|
+
operands.push(arg);
|
|
2404
|
+
if (args.length > 0) unknown.push(...args);
|
|
2405
|
+
break;
|
|
2406
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
2407
|
+
operands.push(arg);
|
|
2408
|
+
if (args.length > 0) operands.push(...args);
|
|
2409
|
+
break;
|
|
2410
|
+
} else if (this._defaultCommandName) {
|
|
2411
|
+
unknown.push(arg);
|
|
2412
|
+
if (args.length > 0) unknown.push(...args);
|
|
2413
|
+
break;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
if (this._passThroughOptions) {
|
|
2417
|
+
dest.push(arg);
|
|
2418
|
+
if (args.length > 0) dest.push(...args);
|
|
2419
|
+
break;
|
|
2420
|
+
}
|
|
2421
|
+
dest.push(arg);
|
|
2422
|
+
}
|
|
2423
|
+
return { operands, unknown };
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Return an object containing local option values as key-value pairs.
|
|
2427
|
+
*
|
|
2428
|
+
* @return {object}
|
|
2429
|
+
*/
|
|
2430
|
+
opts() {
|
|
2431
|
+
if (this._storeOptionsAsProperties) {
|
|
2432
|
+
const result = {};
|
|
2433
|
+
const len = this.options.length;
|
|
2434
|
+
for (let i = 0; i < len; i++) {
|
|
2435
|
+
const key = this.options[i].attributeName();
|
|
2436
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
2437
|
+
}
|
|
2438
|
+
return result;
|
|
2439
|
+
}
|
|
2440
|
+
return this._optionValues;
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Return an object containing merged local and global option values as key-value pairs.
|
|
2444
|
+
*
|
|
2445
|
+
* @return {object}
|
|
2446
|
+
*/
|
|
2447
|
+
optsWithGlobals() {
|
|
2448
|
+
return this._getCommandAndAncestors().reduce(
|
|
2449
|
+
(combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
|
|
2450
|
+
{}
|
|
2451
|
+
);
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Display error message and exit (or call exitOverride).
|
|
2455
|
+
*
|
|
2456
|
+
* @param {string} message
|
|
2457
|
+
* @param {object} [errorOptions]
|
|
2458
|
+
* @param {string} [errorOptions.code] - an id string representing the error
|
|
2459
|
+
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
2460
|
+
*/
|
|
2461
|
+
error(message, errorOptions) {
|
|
2462
|
+
this._outputConfiguration.outputError(
|
|
2463
|
+
`${message}
|
|
2464
|
+
`,
|
|
2465
|
+
this._outputConfiguration.writeErr
|
|
2466
|
+
);
|
|
2467
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
2468
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
2469
|
+
`);
|
|
2470
|
+
} else if (this._showHelpAfterError) {
|
|
2471
|
+
this._outputConfiguration.writeErr("\n");
|
|
2472
|
+
this.outputHelp({ error: true });
|
|
2473
|
+
}
|
|
2474
|
+
const config = errorOptions || {};
|
|
2475
|
+
const exitCode = config.exitCode || 1;
|
|
2476
|
+
const code = config.code || "commander.error";
|
|
2477
|
+
this._exit(exitCode, code, message);
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Apply any option related environment variables, if option does
|
|
2481
|
+
* not have a value from cli or client code.
|
|
2482
|
+
*
|
|
2483
|
+
* @private
|
|
2484
|
+
*/
|
|
2485
|
+
_parseOptionsEnv() {
|
|
2486
|
+
this.options.forEach((option) => {
|
|
2487
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
2488
|
+
const optionKey = option.attributeName();
|
|
2489
|
+
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
2490
|
+
this.getOptionValueSource(optionKey)
|
|
2491
|
+
)) {
|
|
2492
|
+
if (option.required || option.optional) {
|
|
2493
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
2494
|
+
} else {
|
|
2495
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
/**
|
|
2502
|
+
* Apply any implied option values, if option is undefined or default value.
|
|
2503
|
+
*
|
|
2504
|
+
* @private
|
|
2505
|
+
*/
|
|
2506
|
+
_parseOptionsImplied() {
|
|
2507
|
+
const dualHelper = new DualOptions(this.options);
|
|
2508
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
2509
|
+
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
2510
|
+
};
|
|
2511
|
+
this.options.filter(
|
|
2512
|
+
(option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
|
|
2513
|
+
this.getOptionValue(option.attributeName()),
|
|
2514
|
+
option
|
|
2515
|
+
)
|
|
2516
|
+
).forEach((option) => {
|
|
2517
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
2518
|
+
this.setOptionValueWithSource(
|
|
2519
|
+
impliedKey,
|
|
2520
|
+
option.implied[impliedKey],
|
|
2521
|
+
"implied"
|
|
2522
|
+
);
|
|
2523
|
+
});
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* Argument `name` is missing.
|
|
2528
|
+
*
|
|
2529
|
+
* @param {string} name
|
|
2530
|
+
* @private
|
|
2531
|
+
*/
|
|
2532
|
+
missingArgument(name) {
|
|
2533
|
+
const message = `error: missing required argument '${name}'`;
|
|
2534
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* `Option` is missing an argument.
|
|
2538
|
+
*
|
|
2539
|
+
* @param {Option} option
|
|
2540
|
+
* @private
|
|
2541
|
+
*/
|
|
2542
|
+
optionMissingArgument(option) {
|
|
2543
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
2544
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* `Option` does not have a value, and is a mandatory option.
|
|
2548
|
+
*
|
|
2549
|
+
* @param {Option} option
|
|
2550
|
+
* @private
|
|
2551
|
+
*/
|
|
2552
|
+
missingMandatoryOptionValue(option) {
|
|
2553
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
2554
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
2555
|
+
}
|
|
2556
|
+
/**
|
|
2557
|
+
* `Option` conflicts with another option.
|
|
2558
|
+
*
|
|
2559
|
+
* @param {Option} option
|
|
2560
|
+
* @param {Option} conflictingOption
|
|
2561
|
+
* @private
|
|
2562
|
+
*/
|
|
2563
|
+
_conflictingOption(option, conflictingOption) {
|
|
2564
|
+
const findBestOptionFromValue = (option2) => {
|
|
2565
|
+
const optionKey = option2.attributeName();
|
|
2566
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
2567
|
+
const negativeOption = this.options.find(
|
|
2568
|
+
(target) => target.negate && optionKey === target.attributeName()
|
|
2569
|
+
);
|
|
2570
|
+
const positiveOption = this.options.find(
|
|
2571
|
+
(target) => !target.negate && optionKey === target.attributeName()
|
|
2572
|
+
);
|
|
2573
|
+
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
|
|
2574
|
+
return negativeOption;
|
|
2575
|
+
}
|
|
2576
|
+
return positiveOption || option2;
|
|
2577
|
+
};
|
|
2578
|
+
const getErrorMessage = (option2) => {
|
|
2579
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
2580
|
+
const optionKey = bestOption.attributeName();
|
|
2581
|
+
const source = this.getOptionValueSource(optionKey);
|
|
2582
|
+
if (source === "env") {
|
|
2583
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
2584
|
+
}
|
|
2585
|
+
return `option '${bestOption.flags}'`;
|
|
2586
|
+
};
|
|
2587
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2588
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
2589
|
+
}
|
|
2590
|
+
/**
|
|
2591
|
+
* Unknown option `flag`.
|
|
2592
|
+
*
|
|
2593
|
+
* @param {string} flag
|
|
2594
|
+
* @private
|
|
2595
|
+
*/
|
|
2596
|
+
unknownOption(flag) {
|
|
2597
|
+
if (this._allowUnknownOption) return;
|
|
2598
|
+
let suggestion = "";
|
|
2599
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
2600
|
+
let candidateFlags = [];
|
|
2601
|
+
let command = this;
|
|
2602
|
+
do {
|
|
2603
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
2604
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
2605
|
+
command = command.parent;
|
|
2606
|
+
} while (command && !command._enablePositionalOptions);
|
|
2607
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
2608
|
+
}
|
|
2609
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
2610
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* Excess arguments, more than expected.
|
|
2614
|
+
*
|
|
2615
|
+
* @param {string[]} receivedArgs
|
|
2616
|
+
* @private
|
|
2617
|
+
*/
|
|
2618
|
+
_excessArguments(receivedArgs) {
|
|
2619
|
+
if (this._allowExcessArguments) return;
|
|
2620
|
+
const expected = this.registeredArguments.length;
|
|
2621
|
+
const s = expected === 1 ? "" : "s";
|
|
2622
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
2623
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2624
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
2625
|
+
}
|
|
2626
|
+
/**
|
|
2627
|
+
* Unknown command.
|
|
2628
|
+
*
|
|
2629
|
+
* @private
|
|
2630
|
+
*/
|
|
2631
|
+
unknownCommand() {
|
|
2632
|
+
const unknownName = this.args[0];
|
|
2633
|
+
let suggestion = "";
|
|
2634
|
+
if (this._showSuggestionAfterError) {
|
|
2635
|
+
const candidateNames = [];
|
|
2636
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
2637
|
+
candidateNames.push(command.name());
|
|
2638
|
+
if (command.alias()) candidateNames.push(command.alias());
|
|
2639
|
+
});
|
|
2640
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2641
|
+
}
|
|
2642
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
2643
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* Get or set the program version.
|
|
2647
|
+
*
|
|
2648
|
+
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
2649
|
+
*
|
|
2650
|
+
* You can optionally supply the flags and description to override the defaults.
|
|
2651
|
+
*
|
|
2652
|
+
* @param {string} [str]
|
|
2653
|
+
* @param {string} [flags]
|
|
2654
|
+
* @param {string} [description]
|
|
2655
|
+
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
2656
|
+
*/
|
|
2657
|
+
version(str, flags, description) {
|
|
2658
|
+
if (str === void 0) return this._version;
|
|
2659
|
+
this._version = str;
|
|
2660
|
+
flags = flags || "-V, --version";
|
|
2661
|
+
description = description || "output the version number";
|
|
2662
|
+
const versionOption = this.createOption(flags, description);
|
|
2663
|
+
this._versionOptionName = versionOption.attributeName();
|
|
2664
|
+
this._registerOption(versionOption);
|
|
2665
|
+
this.on("option:" + versionOption.name(), () => {
|
|
2666
|
+
this._outputConfiguration.writeOut(`${str}
|
|
2667
|
+
`);
|
|
2668
|
+
this._exit(0, "commander.version", str);
|
|
2669
|
+
});
|
|
2670
|
+
return this;
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2673
|
+
* Set the description.
|
|
2674
|
+
*
|
|
2675
|
+
* @param {string} [str]
|
|
2676
|
+
* @param {object} [argsDescription]
|
|
2677
|
+
* @return {(string|Command)}
|
|
2678
|
+
*/
|
|
2679
|
+
description(str, argsDescription) {
|
|
2680
|
+
if (str === void 0 && argsDescription === void 0)
|
|
2681
|
+
return this._description;
|
|
2682
|
+
this._description = str;
|
|
2683
|
+
if (argsDescription) {
|
|
2684
|
+
this._argsDescription = argsDescription;
|
|
2685
|
+
}
|
|
2686
|
+
return this;
|
|
2687
|
+
}
|
|
2688
|
+
/**
|
|
2689
|
+
* Set the summary. Used when listed as subcommand of parent.
|
|
2690
|
+
*
|
|
2691
|
+
* @param {string} [str]
|
|
2692
|
+
* @return {(string|Command)}
|
|
2693
|
+
*/
|
|
2694
|
+
summary(str) {
|
|
2695
|
+
if (str === void 0) return this._summary;
|
|
2696
|
+
this._summary = str;
|
|
2697
|
+
return this;
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* Set an alias for the command.
|
|
2701
|
+
*
|
|
2702
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
2703
|
+
*
|
|
2704
|
+
* @param {string} [alias]
|
|
2705
|
+
* @return {(string|Command)}
|
|
2706
|
+
*/
|
|
2707
|
+
alias(alias) {
|
|
2708
|
+
if (alias === void 0) return this._aliases[0];
|
|
2709
|
+
let command = this;
|
|
2710
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
2711
|
+
command = this.commands[this.commands.length - 1];
|
|
2712
|
+
}
|
|
2713
|
+
if (alias === command._name)
|
|
2714
|
+
throw new Error("Command alias can't be the same as its name");
|
|
2715
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
2716
|
+
if (matchingCommand) {
|
|
2717
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
2718
|
+
throw new Error(
|
|
2719
|
+
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
|
|
2720
|
+
);
|
|
2721
|
+
}
|
|
2722
|
+
command._aliases.push(alias);
|
|
2723
|
+
return this;
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* Set aliases for the command.
|
|
2727
|
+
*
|
|
2728
|
+
* Only the first alias is shown in the auto-generated help.
|
|
2729
|
+
*
|
|
2730
|
+
* @param {string[]} [aliases]
|
|
2731
|
+
* @return {(string[]|Command)}
|
|
2732
|
+
*/
|
|
2733
|
+
aliases(aliases) {
|
|
2734
|
+
if (aliases === void 0) return this._aliases;
|
|
2735
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
2736
|
+
return this;
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Set / get the command usage `str`.
|
|
2740
|
+
*
|
|
2741
|
+
* @param {string} [str]
|
|
2742
|
+
* @return {(string|Command)}
|
|
2743
|
+
*/
|
|
2744
|
+
usage(str) {
|
|
2745
|
+
if (str === void 0) {
|
|
2746
|
+
if (this._usage) return this._usage;
|
|
2747
|
+
const args = this.registeredArguments.map((arg) => {
|
|
2748
|
+
return humanReadableArgName(arg);
|
|
2749
|
+
});
|
|
2750
|
+
return [].concat(
|
|
2751
|
+
this.options.length || this._helpOption !== null ? "[options]" : [],
|
|
2752
|
+
this.commands.length ? "[command]" : [],
|
|
2753
|
+
this.registeredArguments.length ? args : []
|
|
2754
|
+
).join(" ");
|
|
2755
|
+
}
|
|
2756
|
+
this._usage = str;
|
|
2757
|
+
return this;
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2760
|
+
* Get or set the name of the command.
|
|
2761
|
+
*
|
|
2762
|
+
* @param {string} [str]
|
|
2763
|
+
* @return {(string|Command)}
|
|
2764
|
+
*/
|
|
2765
|
+
name(str) {
|
|
2766
|
+
if (str === void 0) return this._name;
|
|
2767
|
+
this._name = str;
|
|
2768
|
+
return this;
|
|
2769
|
+
}
|
|
2770
|
+
/**
|
|
2771
|
+
* Set the name of the command from script filename, such as process.argv[1],
|
|
2772
|
+
* or require.main.filename, or __filename.
|
|
2773
|
+
*
|
|
2774
|
+
* (Used internally and public although not documented in README.)
|
|
2775
|
+
*
|
|
2776
|
+
* @example
|
|
2777
|
+
* program.nameFromFilename(require.main.filename);
|
|
2778
|
+
*
|
|
2779
|
+
* @param {string} filename
|
|
2780
|
+
* @return {Command}
|
|
2781
|
+
*/
|
|
2782
|
+
nameFromFilename(filename) {
|
|
2783
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
2784
|
+
return this;
|
|
2785
|
+
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Get or set the directory for searching for executable subcommands of this command.
|
|
2788
|
+
*
|
|
2789
|
+
* @example
|
|
2790
|
+
* program.executableDir(__dirname);
|
|
2791
|
+
* // or
|
|
2792
|
+
* program.executableDir('subcommands');
|
|
2793
|
+
*
|
|
2794
|
+
* @param {string} [path]
|
|
2795
|
+
* @return {(string|null|Command)}
|
|
2796
|
+
*/
|
|
2797
|
+
executableDir(path2) {
|
|
2798
|
+
if (path2 === void 0) return this._executableDir;
|
|
2799
|
+
this._executableDir = path2;
|
|
2800
|
+
return this;
|
|
2801
|
+
}
|
|
2802
|
+
/**
|
|
2803
|
+
* Return program help documentation.
|
|
2804
|
+
*
|
|
2805
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
2806
|
+
* @return {string}
|
|
2807
|
+
*/
|
|
2808
|
+
helpInformation(contextOptions) {
|
|
2809
|
+
const helper = this.createHelp();
|
|
2810
|
+
if (helper.helpWidth === void 0) {
|
|
2811
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
2812
|
+
}
|
|
2813
|
+
return helper.formatHelp(this, helper);
|
|
2814
|
+
}
|
|
2815
|
+
/**
|
|
2816
|
+
* @private
|
|
2817
|
+
*/
|
|
2818
|
+
_getHelpContext(contextOptions) {
|
|
2819
|
+
contextOptions = contextOptions || {};
|
|
2820
|
+
const context = { error: !!contextOptions.error };
|
|
2821
|
+
let write;
|
|
2822
|
+
if (context.error) {
|
|
2823
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
2824
|
+
} else {
|
|
2825
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
2826
|
+
}
|
|
2827
|
+
context.write = contextOptions.write || write;
|
|
2828
|
+
context.command = this;
|
|
2829
|
+
return context;
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Output help information for this command.
|
|
2833
|
+
*
|
|
2834
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
2835
|
+
*
|
|
2836
|
+
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
2837
|
+
*/
|
|
2838
|
+
outputHelp(contextOptions) {
|
|
2839
|
+
let deprecatedCallback;
|
|
2840
|
+
if (typeof contextOptions === "function") {
|
|
2841
|
+
deprecatedCallback = contextOptions;
|
|
2842
|
+
contextOptions = void 0;
|
|
2843
|
+
}
|
|
2844
|
+
const context = this._getHelpContext(contextOptions);
|
|
2845
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
2846
|
+
this.emit("beforeHelp", context);
|
|
2847
|
+
let helpInformation = this.helpInformation(context);
|
|
2848
|
+
if (deprecatedCallback) {
|
|
2849
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
2850
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2851
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
context.write(helpInformation);
|
|
2855
|
+
if (this._getHelpOption()?.long) {
|
|
2856
|
+
this.emit(this._getHelpOption().long);
|
|
2857
|
+
}
|
|
2858
|
+
this.emit("afterHelp", context);
|
|
2859
|
+
this._getCommandAndAncestors().forEach(
|
|
2860
|
+
(command) => command.emit("afterAllHelp", context)
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* You can pass in flags and a description to customise the built-in help option.
|
|
2865
|
+
* Pass in false to disable the built-in help option.
|
|
2866
|
+
*
|
|
2867
|
+
* @example
|
|
2868
|
+
* program.helpOption('-?, --help' 'show help'); // customise
|
|
2869
|
+
* program.helpOption(false); // disable
|
|
2870
|
+
*
|
|
2871
|
+
* @param {(string | boolean)} flags
|
|
2872
|
+
* @param {string} [description]
|
|
2873
|
+
* @return {Command} `this` command for chaining
|
|
2874
|
+
*/
|
|
2875
|
+
helpOption(flags, description) {
|
|
2876
|
+
if (typeof flags === "boolean") {
|
|
2877
|
+
if (flags) {
|
|
2878
|
+
this._helpOption = this._helpOption ?? void 0;
|
|
2879
|
+
} else {
|
|
2880
|
+
this._helpOption = null;
|
|
2881
|
+
}
|
|
2882
|
+
return this;
|
|
2883
|
+
}
|
|
2884
|
+
flags = flags ?? "-h, --help";
|
|
2885
|
+
description = description ?? "display help for command";
|
|
2886
|
+
this._helpOption = this.createOption(flags, description);
|
|
2887
|
+
return this;
|
|
2888
|
+
}
|
|
2889
|
+
/**
|
|
2890
|
+
* Lazy create help option.
|
|
2891
|
+
* Returns null if has been disabled with .helpOption(false).
|
|
2892
|
+
*
|
|
2893
|
+
* @returns {(Option | null)} the help option
|
|
2894
|
+
* @package
|
|
2895
|
+
*/
|
|
2896
|
+
_getHelpOption() {
|
|
2897
|
+
if (this._helpOption === void 0) {
|
|
2898
|
+
this.helpOption(void 0, void 0);
|
|
2899
|
+
}
|
|
2900
|
+
return this._helpOption;
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Supply your own option to use for the built-in help option.
|
|
2904
|
+
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
2905
|
+
*
|
|
2906
|
+
* @param {Option} option
|
|
2907
|
+
* @return {Command} `this` command for chaining
|
|
2908
|
+
*/
|
|
2909
|
+
addHelpOption(option) {
|
|
2910
|
+
this._helpOption = option;
|
|
2911
|
+
return this;
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Output help information and exit.
|
|
2915
|
+
*
|
|
2916
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
2917
|
+
*
|
|
2918
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
2919
|
+
*/
|
|
2920
|
+
help(contextOptions) {
|
|
2921
|
+
this.outputHelp(contextOptions);
|
|
2922
|
+
let exitCode = process2.exitCode || 0;
|
|
2923
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
2924
|
+
exitCode = 1;
|
|
2925
|
+
}
|
|
2926
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2927
|
+
}
|
|
2928
|
+
/**
|
|
2929
|
+
* Add additional text to be displayed with the built-in help.
|
|
2930
|
+
*
|
|
2931
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
2932
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
2933
|
+
*
|
|
2934
|
+
* @param {string} position - before or after built-in help
|
|
2935
|
+
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
2936
|
+
* @return {Command} `this` command for chaining
|
|
2937
|
+
*/
|
|
2938
|
+
addHelpText(position, text) {
|
|
2939
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
2940
|
+
if (!allowedValues.includes(position)) {
|
|
2941
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
2942
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2943
|
+
}
|
|
2944
|
+
const helpEvent = `${position}Help`;
|
|
2945
|
+
this.on(helpEvent, (context) => {
|
|
2946
|
+
let helpStr;
|
|
2947
|
+
if (typeof text === "function") {
|
|
2948
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
2949
|
+
} else {
|
|
2950
|
+
helpStr = text;
|
|
2951
|
+
}
|
|
2952
|
+
if (helpStr) {
|
|
2953
|
+
context.write(`${helpStr}
|
|
2954
|
+
`);
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2957
|
+
return this;
|
|
2958
|
+
}
|
|
2959
|
+
/**
|
|
2960
|
+
* Output help information if help flags specified
|
|
2961
|
+
*
|
|
2962
|
+
* @param {Array} args - array of options to search for help flags
|
|
2963
|
+
* @private
|
|
2964
|
+
*/
|
|
2965
|
+
_outputHelpIfRequested(args) {
|
|
2966
|
+
const helpOption = this._getHelpOption();
|
|
2967
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
2968
|
+
if (helpRequested) {
|
|
2969
|
+
this.outputHelp();
|
|
2970
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
};
|
|
2974
|
+
function incrementNodeInspectorPort(args) {
|
|
2975
|
+
return args.map((arg) => {
|
|
2976
|
+
if (!arg.startsWith("--inspect")) {
|
|
2977
|
+
return arg;
|
|
2978
|
+
}
|
|
2979
|
+
let debugOption;
|
|
2980
|
+
let debugHost = "127.0.0.1";
|
|
2981
|
+
let debugPort = "9229";
|
|
2982
|
+
let match;
|
|
2983
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
2984
|
+
debugOption = match[1];
|
|
2985
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
2986
|
+
debugOption = match[1];
|
|
2987
|
+
if (/^\d+$/.test(match[3])) {
|
|
2988
|
+
debugPort = match[3];
|
|
2989
|
+
} else {
|
|
2990
|
+
debugHost = match[3];
|
|
2991
|
+
}
|
|
2992
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
2993
|
+
debugOption = match[1];
|
|
2994
|
+
debugHost = match[3];
|
|
2995
|
+
debugPort = match[4];
|
|
2996
|
+
}
|
|
2997
|
+
if (debugOption && debugPort !== "0") {
|
|
2998
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
2999
|
+
}
|
|
3000
|
+
return arg;
|
|
3001
|
+
});
|
|
3002
|
+
}
|
|
3003
|
+
exports.Command = Command2;
|
|
3004
|
+
}
|
|
3005
|
+
});
|
|
3006
|
+
|
|
3007
|
+
// ../../node_modules/commander/index.js
|
|
3008
|
+
var require_commander = __commonJS({
|
|
3009
|
+
"../../node_modules/commander/index.js"(exports) {
|
|
3010
|
+
var { Argument: Argument2 } = require_argument();
|
|
3011
|
+
var { Command: Command2 } = require_command();
|
|
3012
|
+
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
3013
|
+
var { Help: Help2 } = require_help();
|
|
3014
|
+
var { Option: Option2 } = require_option();
|
|
3015
|
+
exports.program = new Command2();
|
|
3016
|
+
exports.createCommand = (name) => new Command2(name);
|
|
3017
|
+
exports.createOption = (flags, description) => new Option2(flags, description);
|
|
3018
|
+
exports.createArgument = (name, description) => new Argument2(name, description);
|
|
3019
|
+
exports.Command = Command2;
|
|
3020
|
+
exports.Option = Option2;
|
|
3021
|
+
exports.Argument = Argument2;
|
|
3022
|
+
exports.Help = Help2;
|
|
3023
|
+
exports.CommanderError = CommanderError2;
|
|
3024
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
3025
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
3026
|
+
}
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
// ../../node_modules/sisteransi/src/index.js
|
|
3030
|
+
var require_src = __commonJS({
|
|
3031
|
+
"../../node_modules/sisteransi/src/index.js"(exports, module) {
|
|
3032
|
+
"use strict";
|
|
3033
|
+
var ESC = "\x1B";
|
|
3034
|
+
var CSI = `${ESC}[`;
|
|
3035
|
+
var beep = "\x07";
|
|
3036
|
+
var cursor = {
|
|
3037
|
+
to(x3, y3) {
|
|
3038
|
+
if (!y3) return `${CSI}${x3 + 1}G`;
|
|
3039
|
+
return `${CSI}${y3 + 1};${x3 + 1}H`;
|
|
3040
|
+
},
|
|
3041
|
+
move(x3, y3) {
|
|
3042
|
+
let ret = "";
|
|
3043
|
+
if (x3 < 0) ret += `${CSI}${-x3}D`;
|
|
3044
|
+
else if (x3 > 0) ret += `${CSI}${x3}C`;
|
|
3045
|
+
if (y3 < 0) ret += `${CSI}${-y3}A`;
|
|
3046
|
+
else if (y3 > 0) ret += `${CSI}${y3}B`;
|
|
3047
|
+
return ret;
|
|
3048
|
+
},
|
|
3049
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
3050
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
3051
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
3052
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
3053
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
3054
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
3055
|
+
left: `${CSI}G`,
|
|
3056
|
+
hide: `${CSI}?25l`,
|
|
3057
|
+
show: `${CSI}?25h`,
|
|
3058
|
+
save: `${ESC}7`,
|
|
3059
|
+
restore: `${ESC}8`
|
|
3060
|
+
};
|
|
3061
|
+
var scroll = {
|
|
3062
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
3063
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
3064
|
+
};
|
|
3065
|
+
var erase = {
|
|
3066
|
+
screen: `${CSI}2J`,
|
|
3067
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
3068
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
3069
|
+
line: `${CSI}2K`,
|
|
3070
|
+
lineEnd: `${CSI}K`,
|
|
3071
|
+
lineStart: `${CSI}1K`,
|
|
3072
|
+
lines(count) {
|
|
3073
|
+
let clear = "";
|
|
3074
|
+
for (let i = 0; i < count; i++)
|
|
3075
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
3076
|
+
if (count)
|
|
3077
|
+
clear += cursor.left;
|
|
3078
|
+
return clear;
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
3082
|
+
}
|
|
3083
|
+
});
|
|
3084
|
+
|
|
3085
|
+
// ../../node_modules/picocolors/picocolors.js
|
|
3086
|
+
var require_picocolors = __commonJS({
|
|
3087
|
+
"../../node_modules/picocolors/picocolors.js"(exports, module) {
|
|
3088
|
+
var p = process || {};
|
|
3089
|
+
var argv = p.argv || [];
|
|
3090
|
+
var env = p.env || {};
|
|
3091
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
3092
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
3093
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
3094
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
3095
|
+
};
|
|
3096
|
+
var replaceClose = (string, close, replace, index) => {
|
|
3097
|
+
let result = "", cursor = 0;
|
|
3098
|
+
do {
|
|
3099
|
+
result += string.substring(cursor, index) + replace;
|
|
3100
|
+
cursor = index + close.length;
|
|
3101
|
+
index = string.indexOf(close, cursor);
|
|
3102
|
+
} while (~index);
|
|
3103
|
+
return result + string.substring(cursor);
|
|
3104
|
+
};
|
|
3105
|
+
var createColors = (enabled = isColorSupported) => {
|
|
3106
|
+
let f2 = enabled ? formatter : () => String;
|
|
3107
|
+
return {
|
|
3108
|
+
isColorSupported: enabled,
|
|
3109
|
+
reset: f2("\x1B[0m", "\x1B[0m"),
|
|
3110
|
+
bold: f2("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
3111
|
+
dim: f2("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
3112
|
+
italic: f2("\x1B[3m", "\x1B[23m"),
|
|
3113
|
+
underline: f2("\x1B[4m", "\x1B[24m"),
|
|
3114
|
+
inverse: f2("\x1B[7m", "\x1B[27m"),
|
|
3115
|
+
hidden: f2("\x1B[8m", "\x1B[28m"),
|
|
3116
|
+
strikethrough: f2("\x1B[9m", "\x1B[29m"),
|
|
3117
|
+
black: f2("\x1B[30m", "\x1B[39m"),
|
|
3118
|
+
red: f2("\x1B[31m", "\x1B[39m"),
|
|
3119
|
+
green: f2("\x1B[32m", "\x1B[39m"),
|
|
3120
|
+
yellow: f2("\x1B[33m", "\x1B[39m"),
|
|
3121
|
+
blue: f2("\x1B[34m", "\x1B[39m"),
|
|
3122
|
+
magenta: f2("\x1B[35m", "\x1B[39m"),
|
|
3123
|
+
cyan: f2("\x1B[36m", "\x1B[39m"),
|
|
3124
|
+
white: f2("\x1B[37m", "\x1B[39m"),
|
|
3125
|
+
gray: f2("\x1B[90m", "\x1B[39m"),
|
|
3126
|
+
bgBlack: f2("\x1B[40m", "\x1B[49m"),
|
|
3127
|
+
bgRed: f2("\x1B[41m", "\x1B[49m"),
|
|
3128
|
+
bgGreen: f2("\x1B[42m", "\x1B[49m"),
|
|
3129
|
+
bgYellow: f2("\x1B[43m", "\x1B[49m"),
|
|
3130
|
+
bgBlue: f2("\x1B[44m", "\x1B[49m"),
|
|
3131
|
+
bgMagenta: f2("\x1B[45m", "\x1B[49m"),
|
|
3132
|
+
bgCyan: f2("\x1B[46m", "\x1B[49m"),
|
|
3133
|
+
bgWhite: f2("\x1B[47m", "\x1B[49m"),
|
|
3134
|
+
blackBright: f2("\x1B[90m", "\x1B[39m"),
|
|
3135
|
+
redBright: f2("\x1B[91m", "\x1B[39m"),
|
|
3136
|
+
greenBright: f2("\x1B[92m", "\x1B[39m"),
|
|
3137
|
+
yellowBright: f2("\x1B[93m", "\x1B[39m"),
|
|
3138
|
+
blueBright: f2("\x1B[94m", "\x1B[39m"),
|
|
3139
|
+
magentaBright: f2("\x1B[95m", "\x1B[39m"),
|
|
3140
|
+
cyanBright: f2("\x1B[96m", "\x1B[39m"),
|
|
3141
|
+
whiteBright: f2("\x1B[97m", "\x1B[39m"),
|
|
3142
|
+
bgBlackBright: f2("\x1B[100m", "\x1B[49m"),
|
|
3143
|
+
bgRedBright: f2("\x1B[101m", "\x1B[49m"),
|
|
3144
|
+
bgGreenBright: f2("\x1B[102m", "\x1B[49m"),
|
|
3145
|
+
bgYellowBright: f2("\x1B[103m", "\x1B[49m"),
|
|
3146
|
+
bgBlueBright: f2("\x1B[104m", "\x1B[49m"),
|
|
3147
|
+
bgMagentaBright: f2("\x1B[105m", "\x1B[49m"),
|
|
3148
|
+
bgCyanBright: f2("\x1B[106m", "\x1B[49m"),
|
|
3149
|
+
bgWhiteBright: f2("\x1B[107m", "\x1B[49m")
|
|
3150
|
+
};
|
|
3151
|
+
};
|
|
3152
|
+
module.exports = createColors();
|
|
3153
|
+
module.exports.createColors = createColors;
|
|
3154
|
+
}
|
|
3155
|
+
});
|
|
3156
|
+
|
|
3157
|
+
// ../../node_modules/commander/esm.mjs
|
|
3158
|
+
var import_index = __toESM(require_commander(), 1);
|
|
3159
|
+
var {
|
|
3160
|
+
program,
|
|
3161
|
+
createCommand,
|
|
3162
|
+
createArgument,
|
|
3163
|
+
createOption,
|
|
3164
|
+
CommanderError,
|
|
3165
|
+
InvalidArgumentError,
|
|
3166
|
+
InvalidOptionArgumentError,
|
|
3167
|
+
// deprecated old name
|
|
3168
|
+
Command,
|
|
3169
|
+
Argument,
|
|
3170
|
+
Option,
|
|
3171
|
+
Help
|
|
3172
|
+
} = import_index.default;
|
|
3173
|
+
|
|
3174
|
+
// ../../node_modules/@clack/core/dist/index.mjs
|
|
3175
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
3176
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
3177
|
+
import { stdin as $, stdout as k } from "node:process";
|
|
3178
|
+
import * as f from "node:readline";
|
|
3179
|
+
import _ from "node:readline";
|
|
3180
|
+
import { WriteStream as U } from "node:tty";
|
|
3181
|
+
function q({ onlyFirst: e2 = false } = {}) {
|
|
3182
|
+
const F = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
3183
|
+
return new RegExp(F, e2 ? void 0 : "g");
|
|
3184
|
+
}
|
|
3185
|
+
var J = q();
|
|
3186
|
+
function S(e2) {
|
|
3187
|
+
if (typeof e2 != "string") throw new TypeError(`Expected a \`string\`, got \`${typeof e2}\``);
|
|
3188
|
+
return e2.replace(J, "");
|
|
3189
|
+
}
|
|
3190
|
+
function T(e2) {
|
|
3191
|
+
return e2 && e2.__esModule && Object.prototype.hasOwnProperty.call(e2, "default") ? e2.default : e2;
|
|
3192
|
+
}
|
|
3193
|
+
var j = { exports: {} };
|
|
3194
|
+
(function(e2) {
|
|
3195
|
+
var u = {};
|
|
3196
|
+
e2.exports = u, u.eastAsianWidth = function(t) {
|
|
3197
|
+
var s = t.charCodeAt(0), C2 = t.length == 2 ? t.charCodeAt(1) : 0, D = s;
|
|
3198
|
+
return 55296 <= s && s <= 56319 && 56320 <= C2 && C2 <= 57343 && (s &= 1023, C2 &= 1023, D = s << 10 | C2, D += 65536), D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N";
|
|
3199
|
+
}, u.characterLength = function(t) {
|
|
3200
|
+
var s = this.eastAsianWidth(t);
|
|
3201
|
+
return s == "F" || s == "W" || s == "A" ? 2 : 1;
|
|
3202
|
+
};
|
|
3203
|
+
function F(t) {
|
|
3204
|
+
return t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
|
|
3205
|
+
}
|
|
3206
|
+
u.length = function(t) {
|
|
3207
|
+
for (var s = F(t), C2 = 0, D = 0; D < s.length; D++) C2 = C2 + this.characterLength(s[D]);
|
|
3208
|
+
return C2;
|
|
3209
|
+
}, u.slice = function(t, s, C2) {
|
|
3210
|
+
textLen = u.length(t), s = s || 0, C2 = C2 || 1, s < 0 && (s = textLen + s), C2 < 0 && (C2 = textLen + C2);
|
|
3211
|
+
for (var D = "", i = 0, n = F(t), E2 = 0; E2 < n.length; E2++) {
|
|
3212
|
+
var h2 = n[E2], o2 = u.length(h2);
|
|
3213
|
+
if (i >= s - (o2 == 2 ? 1 : 0)) if (i + o2 <= C2) D += h2;
|
|
3214
|
+
else break;
|
|
3215
|
+
i += o2;
|
|
3216
|
+
}
|
|
3217
|
+
return D;
|
|
3218
|
+
};
|
|
3219
|
+
})(j);
|
|
3220
|
+
var Q = j.exports;
|
|
3221
|
+
var X = T(Q);
|
|
3222
|
+
var DD = function() {
|
|
3223
|
+
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
|
|
3224
|
+
};
|
|
3225
|
+
var uD = T(DD);
|
|
3226
|
+
function A(e2, u = {}) {
|
|
3227
|
+
if (typeof e2 != "string" || e2.length === 0 || (u = { ambiguousIsNarrow: true, ...u }, e2 = S(e2), e2.length === 0)) return 0;
|
|
3228
|
+
e2 = e2.replace(uD(), " ");
|
|
3229
|
+
const F = u.ambiguousIsNarrow ? 1 : 2;
|
|
3230
|
+
let t = 0;
|
|
3231
|
+
for (const s of e2) {
|
|
3232
|
+
const C2 = s.codePointAt(0);
|
|
3233
|
+
if (C2 <= 31 || C2 >= 127 && C2 <= 159 || C2 >= 768 && C2 <= 879) continue;
|
|
3234
|
+
switch (X.eastAsianWidth(s)) {
|
|
3235
|
+
case "F":
|
|
3236
|
+
case "W":
|
|
3237
|
+
t += 2;
|
|
3238
|
+
break;
|
|
3239
|
+
case "A":
|
|
3240
|
+
t += F;
|
|
3241
|
+
break;
|
|
3242
|
+
default:
|
|
3243
|
+
t += 1;
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
return t;
|
|
3247
|
+
}
|
|
3248
|
+
var d = 10;
|
|
3249
|
+
var M = (e2 = 0) => (u) => `\x1B[${u + e2}m`;
|
|
3250
|
+
var P = (e2 = 0) => (u) => `\x1B[${38 + e2};5;${u}m`;
|
|
3251
|
+
var W = (e2 = 0) => (u, F, t) => `\x1B[${38 + e2};2;${u};${F};${t}m`;
|
|
3252
|
+
var r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } };
|
|
3253
|
+
Object.keys(r.modifier);
|
|
3254
|
+
var FD = Object.keys(r.color);
|
|
3255
|
+
var eD = Object.keys(r.bgColor);
|
|
3256
|
+
[...FD, ...eD];
|
|
3257
|
+
function tD() {
|
|
3258
|
+
const e2 = /* @__PURE__ */ new Map();
|
|
3259
|
+
for (const [u, F] of Object.entries(r)) {
|
|
3260
|
+
for (const [t, s] of Object.entries(F)) r[t] = { open: `\x1B[${s[0]}m`, close: `\x1B[${s[1]}m` }, F[t] = r[t], e2.set(s[0], s[1]);
|
|
3261
|
+
Object.defineProperty(r, u, { value: F, enumerable: false });
|
|
3262
|
+
}
|
|
3263
|
+
return Object.defineProperty(r, "codes", { value: e2, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = M(), r.color.ansi256 = P(), r.color.ansi16m = W(), r.bgColor.ansi = M(d), r.bgColor.ansi256 = P(d), r.bgColor.ansi16m = W(d), Object.defineProperties(r, { rgbToAnsi256: { value: (u, F, t) => u === F && F === t ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(F / 255 * 5) + Math.round(t / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => {
|
|
3264
|
+
const F = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));
|
|
3265
|
+
if (!F) return [0, 0, 0];
|
|
3266
|
+
let [t] = F;
|
|
3267
|
+
t.length === 3 && (t = [...t].map((C2) => C2 + C2).join(""));
|
|
3268
|
+
const s = Number.parseInt(t, 16);
|
|
3269
|
+
return [s >> 16 & 255, s >> 8 & 255, s & 255];
|
|
3270
|
+
}, enumerable: false }, hexToAnsi256: { value: (u) => r.rgbToAnsi256(...r.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => {
|
|
3271
|
+
if (u < 8) return 30 + u;
|
|
3272
|
+
if (u < 16) return 90 + (u - 8);
|
|
3273
|
+
let F, t, s;
|
|
3274
|
+
if (u >= 232) F = ((u - 232) * 10 + 8) / 255, t = F, s = F;
|
|
3275
|
+
else {
|
|
3276
|
+
u -= 16;
|
|
3277
|
+
const i = u % 36;
|
|
3278
|
+
F = Math.floor(u / 36) / 5, t = Math.floor(i / 6) / 5, s = i % 6 / 5;
|
|
3279
|
+
}
|
|
3280
|
+
const C2 = Math.max(F, t, s) * 2;
|
|
3281
|
+
if (C2 === 0) return 30;
|
|
3282
|
+
let D = 30 + (Math.round(s) << 2 | Math.round(t) << 1 | Math.round(F));
|
|
3283
|
+
return C2 === 2 && (D += 60), D;
|
|
3284
|
+
}, enumerable: false }, rgbToAnsi: { value: (u, F, t) => r.ansi256ToAnsi(r.rgbToAnsi256(u, F, t)), enumerable: false }, hexToAnsi: { value: (u) => r.ansi256ToAnsi(r.hexToAnsi256(u)), enumerable: false } }), r;
|
|
3285
|
+
}
|
|
3286
|
+
var sD = tD();
|
|
3287
|
+
var g = /* @__PURE__ */ new Set(["\x1B", "\x9B"]);
|
|
3288
|
+
var CD = 39;
|
|
3289
|
+
var b = "\x07";
|
|
3290
|
+
var O = "[";
|
|
3291
|
+
var iD = "]";
|
|
3292
|
+
var I = "m";
|
|
3293
|
+
var w = `${iD}8;;`;
|
|
3294
|
+
var N = (e2) => `${g.values().next().value}${O}${e2}${I}`;
|
|
3295
|
+
var L = (e2) => `${g.values().next().value}${w}${e2}${b}`;
|
|
3296
|
+
var rD = (e2) => e2.split(" ").map((u) => A(u));
|
|
3297
|
+
var y = (e2, u, F) => {
|
|
3298
|
+
const t = [...u];
|
|
3299
|
+
let s = false, C2 = false, D = A(S(e2[e2.length - 1]));
|
|
3300
|
+
for (const [i, n] of t.entries()) {
|
|
3301
|
+
const E2 = A(n);
|
|
3302
|
+
if (D + E2 <= F ? e2[e2.length - 1] += n : (e2.push(n), D = 0), g.has(n) && (s = true, C2 = t.slice(i + 1).join("").startsWith(w)), s) {
|
|
3303
|
+
C2 ? n === b && (s = false, C2 = false) : n === I && (s = false);
|
|
3304
|
+
continue;
|
|
3305
|
+
}
|
|
3306
|
+
D += E2, D === F && i < t.length - 1 && (e2.push(""), D = 0);
|
|
3307
|
+
}
|
|
3308
|
+
!D && e2[e2.length - 1].length > 0 && e2.length > 1 && (e2[e2.length - 2] += e2.pop());
|
|
3309
|
+
};
|
|
3310
|
+
var ED = (e2) => {
|
|
3311
|
+
const u = e2.split(" ");
|
|
3312
|
+
let F = u.length;
|
|
3313
|
+
for (; F > 0 && !(A(u[F - 1]) > 0); ) F--;
|
|
3314
|
+
return F === u.length ? e2 : u.slice(0, F).join(" ") + u.slice(F).join("");
|
|
3315
|
+
};
|
|
3316
|
+
var oD = (e2, u, F = {}) => {
|
|
3317
|
+
if (F.trim !== false && e2.trim() === "") return "";
|
|
3318
|
+
let t = "", s, C2;
|
|
3319
|
+
const D = rD(e2);
|
|
3320
|
+
let i = [""];
|
|
3321
|
+
for (const [E2, h2] of e2.split(" ").entries()) {
|
|
3322
|
+
F.trim !== false && (i[i.length - 1] = i[i.length - 1].trimStart());
|
|
3323
|
+
let o2 = A(i[i.length - 1]);
|
|
3324
|
+
if (E2 !== 0 && (o2 >= u && (F.wordWrap === false || F.trim === false) && (i.push(""), o2 = 0), (o2 > 0 || F.trim === false) && (i[i.length - 1] += " ", o2++)), F.hard && D[E2] > u) {
|
|
3325
|
+
const B2 = u - o2, p = 1 + Math.floor((D[E2] - B2 - 1) / u);
|
|
3326
|
+
Math.floor((D[E2] - 1) / u) < p && i.push(""), y(i, h2, u);
|
|
3327
|
+
continue;
|
|
3328
|
+
}
|
|
3329
|
+
if (o2 + D[E2] > u && o2 > 0 && D[E2] > 0) {
|
|
3330
|
+
if (F.wordWrap === false && o2 < u) {
|
|
3331
|
+
y(i, h2, u);
|
|
3332
|
+
continue;
|
|
3333
|
+
}
|
|
3334
|
+
i.push("");
|
|
3335
|
+
}
|
|
3336
|
+
if (o2 + D[E2] > u && F.wordWrap === false) {
|
|
3337
|
+
y(i, h2, u);
|
|
3338
|
+
continue;
|
|
3339
|
+
}
|
|
3340
|
+
i[i.length - 1] += h2;
|
|
3341
|
+
}
|
|
3342
|
+
F.trim !== false && (i = i.map((E2) => ED(E2)));
|
|
3343
|
+
const n = [...i.join(`
|
|
3344
|
+
`)];
|
|
3345
|
+
for (const [E2, h2] of n.entries()) {
|
|
3346
|
+
if (t += h2, g.has(h2)) {
|
|
3347
|
+
const { groups: B2 } = new RegExp(`(?:\\${O}(?<code>\\d+)m|\\${w}(?<uri>.*)${b})`).exec(n.slice(E2).join("")) || { groups: {} };
|
|
3348
|
+
if (B2.code !== void 0) {
|
|
3349
|
+
const p = Number.parseFloat(B2.code);
|
|
3350
|
+
s = p === CD ? void 0 : p;
|
|
3351
|
+
} else B2.uri !== void 0 && (C2 = B2.uri.length === 0 ? void 0 : B2.uri);
|
|
3352
|
+
}
|
|
3353
|
+
const o2 = sD.codes.get(Number(s));
|
|
3354
|
+
n[E2 + 1] === `
|
|
3355
|
+
` ? (C2 && (t += L("")), s && o2 && (t += N(o2))) : h2 === `
|
|
3356
|
+
` && (s && o2 && (t += N(s)), C2 && (t += L(C2)));
|
|
3357
|
+
}
|
|
3358
|
+
return t;
|
|
3359
|
+
};
|
|
3360
|
+
function R(e2, u, F) {
|
|
3361
|
+
return String(e2).normalize().replace(/\r\n/g, `
|
|
3362
|
+
`).split(`
|
|
3363
|
+
`).map((t) => oD(t, u, F)).join(`
|
|
3364
|
+
`);
|
|
3365
|
+
}
|
|
3366
|
+
var nD = Object.defineProperty;
|
|
3367
|
+
var aD = (e2, u, F) => u in e2 ? nD(e2, u, { enumerable: true, configurable: true, writable: true, value: F }) : e2[u] = F;
|
|
3368
|
+
var a = (e2, u, F) => (aD(e2, typeof u != "symbol" ? u + "" : u, F), F);
|
|
3369
|
+
function hD(e2, u) {
|
|
3370
|
+
if (e2 === u) return;
|
|
3371
|
+
const F = e2.split(`
|
|
3372
|
+
`), t = u.split(`
|
|
3373
|
+
`), s = [];
|
|
3374
|
+
for (let C2 = 0; C2 < Math.max(F.length, t.length); C2++) F[C2] !== t[C2] && s.push(C2);
|
|
3375
|
+
return s;
|
|
3376
|
+
}
|
|
3377
|
+
var V = Symbol("clack:cancel");
|
|
3378
|
+
function lD(e2) {
|
|
3379
|
+
return e2 === V;
|
|
3380
|
+
}
|
|
3381
|
+
function v(e2, u) {
|
|
3382
|
+
e2.isTTY && e2.setRawMode(u);
|
|
3383
|
+
}
|
|
3384
|
+
var z = /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"]]);
|
|
3385
|
+
var xD = /* @__PURE__ */ new Set(["up", "down", "left", "right", "space", "enter"]);
|
|
3386
|
+
var x = class {
|
|
3387
|
+
constructor({ render: u, input: F = $, output: t = k, ...s }, C2 = true) {
|
|
3388
|
+
a(this, "input"), a(this, "output"), a(this, "rl"), a(this, "opts"), a(this, "_track", false), a(this, "_render"), a(this, "_cursor", 0), a(this, "state", "initial"), a(this, "value"), a(this, "error", ""), a(this, "subscribers", /* @__PURE__ */ new Map()), a(this, "_prevFrame", ""), this.opts = s, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = u.bind(this), this._track = C2, this.input = F, this.output = t;
|
|
3389
|
+
}
|
|
3390
|
+
prompt() {
|
|
3391
|
+
const u = new U(0);
|
|
3392
|
+
return u._write = (F, t, s) => {
|
|
3393
|
+
this._track && (this.value = this.rl.line.replace(/\t/g, ""), this._cursor = this.rl.cursor, this.emit("value", this.value)), s();
|
|
3394
|
+
}, this.input.pipe(u), this.rl = _.createInterface({ input: this.input, output: u, tabSize: 2, prompt: "", escapeCodeTimeout: 50 }), _.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== void 0 && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), v(this.input, true), this.output.on("resize", this.render), this.render(), new Promise((F, t) => {
|
|
3395
|
+
this.once("submit", () => {
|
|
3396
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), v(this.input, false), F(this.value);
|
|
3397
|
+
}), this.once("cancel", () => {
|
|
3398
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), v(this.input, false), F(V);
|
|
3399
|
+
});
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
on(u, F) {
|
|
3403
|
+
const t = this.subscribers.get(u) ?? [];
|
|
3404
|
+
t.push({ cb: F }), this.subscribers.set(u, t);
|
|
3405
|
+
}
|
|
3406
|
+
once(u, F) {
|
|
3407
|
+
const t = this.subscribers.get(u) ?? [];
|
|
3408
|
+
t.push({ cb: F, once: true }), this.subscribers.set(u, t);
|
|
3409
|
+
}
|
|
3410
|
+
emit(u, ...F) {
|
|
3411
|
+
const t = this.subscribers.get(u) ?? [], s = [];
|
|
3412
|
+
for (const C2 of t) C2.cb(...F), C2.once && s.push(() => t.splice(t.indexOf(C2), 1));
|
|
3413
|
+
for (const C2 of s) C2();
|
|
3414
|
+
}
|
|
3415
|
+
unsubscribe() {
|
|
3416
|
+
this.subscribers.clear();
|
|
3417
|
+
}
|
|
3418
|
+
onKeypress(u, F) {
|
|
3419
|
+
if (this.state === "error" && (this.state = "active"), F?.name && !this._track && z.has(F.name) && this.emit("cursor", z.get(F.name)), F?.name && xD.has(F.name) && this.emit("cursor", F.name), u && (u.toLowerCase() === "y" || u.toLowerCase() === "n") && this.emit("confirm", u.toLowerCase() === "y"), u === " " && this.opts.placeholder && (this.value || (this.rl.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u && this.emit("key", u.toLowerCase()), F?.name === "return") {
|
|
3420
|
+
if (this.opts.validate) {
|
|
3421
|
+
const t = this.opts.validate(this.value);
|
|
3422
|
+
t && (this.error = t, this.state = "error", this.rl.write(this.value));
|
|
3423
|
+
}
|
|
3424
|
+
this.state !== "error" && (this.state = "submit");
|
|
3425
|
+
}
|
|
3426
|
+
u === "" && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
3427
|
+
}
|
|
3428
|
+
close() {
|
|
3429
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
3430
|
+
`), v(this.input, false), this.rl.close(), this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
3431
|
+
}
|
|
3432
|
+
restoreCursor() {
|
|
3433
|
+
const u = R(this._prevFrame, process.stdout.columns, { hard: true }).split(`
|
|
3434
|
+
`).length - 1;
|
|
3435
|
+
this.output.write(import_sisteransi.cursor.move(-999, u * -1));
|
|
3436
|
+
}
|
|
3437
|
+
render() {
|
|
3438
|
+
const u = R(this._render(this) ?? "", process.stdout.columns, { hard: true });
|
|
3439
|
+
if (u !== this._prevFrame) {
|
|
3440
|
+
if (this.state === "initial") this.output.write(import_sisteransi.cursor.hide);
|
|
3441
|
+
else {
|
|
3442
|
+
const F = hD(this._prevFrame, u);
|
|
3443
|
+
if (this.restoreCursor(), F && F?.length === 1) {
|
|
3444
|
+
const t = F[0];
|
|
3445
|
+
this.output.write(import_sisteransi.cursor.move(0, t)), this.output.write(import_sisteransi.erase.lines(1));
|
|
3446
|
+
const s = u.split(`
|
|
3447
|
+
`);
|
|
3448
|
+
this.output.write(s[t]), this._prevFrame = u, this.output.write(import_sisteransi.cursor.move(0, s.length - t - 1));
|
|
3449
|
+
return;
|
|
3450
|
+
} else if (F && F?.length > 1) {
|
|
3451
|
+
const t = F[0];
|
|
3452
|
+
this.output.write(import_sisteransi.cursor.move(0, t)), this.output.write(import_sisteransi.erase.down());
|
|
3453
|
+
const s = u.split(`
|
|
3454
|
+
`).slice(t);
|
|
3455
|
+
this.output.write(s.join(`
|
|
3456
|
+
`)), this._prevFrame = u;
|
|
3457
|
+
return;
|
|
3458
|
+
}
|
|
3459
|
+
this.output.write(import_sisteransi.erase.down());
|
|
3460
|
+
}
|
|
3461
|
+
this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u;
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
var BD = class extends x {
|
|
3466
|
+
get cursor() {
|
|
3467
|
+
return this.value ? 0 : 1;
|
|
3468
|
+
}
|
|
3469
|
+
get _value() {
|
|
3470
|
+
return this.cursor === 0;
|
|
3471
|
+
}
|
|
3472
|
+
constructor(u) {
|
|
3473
|
+
super(u, false), this.value = !!u.initialValue, this.on("value", () => {
|
|
3474
|
+
this.value = this._value;
|
|
3475
|
+
}), this.on("confirm", (F) => {
|
|
3476
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = F, this.state = "submit", this.close();
|
|
3477
|
+
}), this.on("cursor", () => {
|
|
3478
|
+
this.value = !this.value;
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
};
|
|
3482
|
+
var TD = Object.defineProperty;
|
|
3483
|
+
var jD = (e2, u, F) => u in e2 ? TD(e2, u, { enumerable: true, configurable: true, writable: true, value: F }) : e2[u] = F;
|
|
3484
|
+
var MD = (e2, u, F) => (jD(e2, typeof u != "symbol" ? u + "" : u, F), F);
|
|
3485
|
+
var PD = class extends x {
|
|
3486
|
+
constructor(u) {
|
|
3487
|
+
super(u), MD(this, "valueWithCursor", ""), this.on("finalize", () => {
|
|
3488
|
+
this.value || (this.value = u.defaultValue), this.valueWithCursor = this.value;
|
|
3489
|
+
}), this.on("value", () => {
|
|
3490
|
+
if (this.cursor >= this.value.length) this.valueWithCursor = `${this.value}${import_picocolors.default.inverse(import_picocolors.default.hidden("_"))}`;
|
|
3491
|
+
else {
|
|
3492
|
+
const F = this.value.slice(0, this.cursor), t = this.value.slice(this.cursor);
|
|
3493
|
+
this.valueWithCursor = `${F}${import_picocolors.default.inverse(t[0])}${t.slice(1)}`;
|
|
3494
|
+
}
|
|
3495
|
+
});
|
|
3496
|
+
}
|
|
3497
|
+
get cursor() {
|
|
3498
|
+
return this._cursor;
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
var WD = globalThis.process.platform.startsWith("win");
|
|
3502
|
+
function OD({ input: e2 = $, output: u = k, overwrite: F = true, hideCursor: t = true } = {}) {
|
|
3503
|
+
const s = f.createInterface({ input: e2, output: u, prompt: "", tabSize: 1 });
|
|
3504
|
+
f.emitKeypressEvents(e2, s), e2.isTTY && e2.setRawMode(true);
|
|
3505
|
+
const C2 = (D, { name: i }) => {
|
|
3506
|
+
if (String(D) === "") {
|
|
3507
|
+
t && u.write(import_sisteransi.cursor.show), process.exit(0);
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
if (!F) return;
|
|
3511
|
+
let n = i === "return" ? 0 : -1, E2 = i === "return" ? -1 : 0;
|
|
3512
|
+
f.moveCursor(u, n, E2, () => {
|
|
3513
|
+
f.clearLine(u, 1, () => {
|
|
3514
|
+
e2.once("keypress", C2);
|
|
3515
|
+
});
|
|
3516
|
+
});
|
|
3517
|
+
};
|
|
3518
|
+
return t && u.write(import_sisteransi.cursor.hide), e2.once("keypress", C2), () => {
|
|
3519
|
+
e2.off("keypress", C2), t && u.write(import_sisteransi.cursor.show), e2.isTTY && !WD && e2.setRawMode(false), s.terminal = false, s.close();
|
|
3520
|
+
};
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
// ../../node_modules/@clack/prompts/dist/index.mjs
|
|
3524
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
3525
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
3526
|
+
import h from "node:process";
|
|
3527
|
+
function q2() {
|
|
3528
|
+
return h.platform !== "win32" ? h.env.TERM !== "linux" : Boolean(h.env.CI) || Boolean(h.env.WT_SESSION) || Boolean(h.env.TERMINUS_SUBLIME) || h.env.ConEmuTask === "{cmd::Cmder}" || h.env.TERM_PROGRAM === "Terminus-Sublime" || h.env.TERM_PROGRAM === "vscode" || h.env.TERM === "xterm-256color" || h.env.TERM === "alacritty" || h.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
3529
|
+
}
|
|
3530
|
+
var _2 = q2();
|
|
3531
|
+
var o = (r2, n) => _2 ? r2 : n;
|
|
3532
|
+
var H = o("\u25C6", "*");
|
|
3533
|
+
var I2 = o("\u25A0", "x");
|
|
3534
|
+
var x2 = o("\u25B2", "x");
|
|
3535
|
+
var S2 = o("\u25C7", "o");
|
|
3536
|
+
var K = o("\u250C", "T");
|
|
3537
|
+
var a2 = o("\u2502", "|");
|
|
3538
|
+
var d2 = o("\u2514", "\u2014");
|
|
3539
|
+
var b2 = o("\u25CF", ">");
|
|
3540
|
+
var E = o("\u25CB", " ");
|
|
3541
|
+
var C = o("\u25FB", "[\u2022]");
|
|
3542
|
+
var w2 = o("\u25FC", "[+]");
|
|
3543
|
+
var M2 = o("\u25FB", "[ ]");
|
|
3544
|
+
var U2 = o("\u25AA", "\u2022");
|
|
3545
|
+
var B = o("\u2500", "-");
|
|
3546
|
+
var Z = o("\u256E", "+");
|
|
3547
|
+
var z2 = o("\u251C", "+");
|
|
3548
|
+
var X2 = o("\u256F", "+");
|
|
3549
|
+
var J2 = o("\u25CF", "\u2022");
|
|
3550
|
+
var Y = o("\u25C6", "*");
|
|
3551
|
+
var Q2 = o("\u25B2", "!");
|
|
3552
|
+
var ee = o("\u25A0", "x");
|
|
3553
|
+
var y2 = (r2) => {
|
|
3554
|
+
switch (r2) {
|
|
3555
|
+
case "initial":
|
|
3556
|
+
case "active":
|
|
3557
|
+
return import_picocolors2.default.cyan(H);
|
|
3558
|
+
case "cancel":
|
|
3559
|
+
return import_picocolors2.default.red(I2);
|
|
3560
|
+
case "error":
|
|
3561
|
+
return import_picocolors2.default.yellow(x2);
|
|
3562
|
+
case "submit":
|
|
3563
|
+
return import_picocolors2.default.green(S2);
|
|
3564
|
+
}
|
|
3565
|
+
};
|
|
3566
|
+
var te = (r2) => new PD({ validate: r2.validate, placeholder: r2.placeholder, defaultValue: r2.defaultValue, initialValue: r2.initialValue, render() {
|
|
3567
|
+
const n = `${import_picocolors2.default.gray(a2)}
|
|
3568
|
+
${y2(this.state)} ${r2.message}
|
|
3569
|
+
`, i = r2.placeholder ? import_picocolors2.default.inverse(r2.placeholder[0]) + import_picocolors2.default.dim(r2.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), t = this.value ? this.valueWithCursor : i;
|
|
3570
|
+
switch (this.state) {
|
|
3571
|
+
case "error":
|
|
3572
|
+
return `${n.trim()}
|
|
3573
|
+
${import_picocolors2.default.yellow(a2)} ${t}
|
|
3574
|
+
${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(this.error)}
|
|
3575
|
+
`;
|
|
3576
|
+
case "submit":
|
|
3577
|
+
return `${n}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.dim(this.value || r2.placeholder)}`;
|
|
3578
|
+
case "cancel":
|
|
3579
|
+
return `${n}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(this.value ?? ""))}${this.value?.trim() ? `
|
|
3580
|
+
` + import_picocolors2.default.gray(a2) : ""}`;
|
|
3581
|
+
default:
|
|
3582
|
+
return `${n}${import_picocolors2.default.cyan(a2)} ${t}
|
|
3583
|
+
${import_picocolors2.default.cyan(d2)}
|
|
3584
|
+
`;
|
|
3585
|
+
}
|
|
3586
|
+
} }).prompt();
|
|
3587
|
+
var se = (r2) => {
|
|
3588
|
+
const n = r2.active ?? "Yes", i = r2.inactive ?? "No";
|
|
3589
|
+
return new BD({ active: n, inactive: i, initialValue: r2.initialValue ?? true, render() {
|
|
3590
|
+
const t = `${import_picocolors2.default.gray(a2)}
|
|
3591
|
+
${y2(this.state)} ${r2.message}
|
|
3592
|
+
`, s = this.value ? n : i;
|
|
3593
|
+
switch (this.state) {
|
|
3594
|
+
case "submit":
|
|
3595
|
+
return `${t}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.dim(s)}`;
|
|
3596
|
+
case "cancel":
|
|
3597
|
+
return `${t}${import_picocolors2.default.gray(a2)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}
|
|
3598
|
+
${import_picocolors2.default.gray(a2)}`;
|
|
3599
|
+
default:
|
|
3600
|
+
return `${t}${import_picocolors2.default.cyan(a2)} ${this.value ? `${import_picocolors2.default.green(b2)} ${n}` : `${import_picocolors2.default.dim(E)} ${import_picocolors2.default.dim(n)}`} ${import_picocolors2.default.dim("/")} ${this.value ? `${import_picocolors2.default.dim(E)} ${import_picocolors2.default.dim(i)}` : `${import_picocolors2.default.green(b2)} ${i}`}
|
|
3601
|
+
${import_picocolors2.default.cyan(d2)}
|
|
3602
|
+
`;
|
|
3603
|
+
}
|
|
3604
|
+
} }).prompt();
|
|
3605
|
+
};
|
|
3606
|
+
var de = () => {
|
|
3607
|
+
const r2 = _2 ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], n = _2 ? 80 : 120;
|
|
3608
|
+
let i, t, s = false, c3 = "";
|
|
3609
|
+
const l2 = (v2 = "") => {
|
|
3610
|
+
s = true, i = OD(), c3 = v2.replace(/\.+$/, ""), process.stdout.write(`${import_picocolors2.default.gray(a2)}
|
|
3611
|
+
`);
|
|
3612
|
+
let g2 = 0, p = 0;
|
|
3613
|
+
t = setInterval(() => {
|
|
3614
|
+
const O2 = import_picocolors2.default.magenta(r2[g2]), P2 = ".".repeat(Math.floor(p)).slice(0, 3);
|
|
3615
|
+
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${O2} ${c3}${P2}`), g2 = g2 + 1 < r2.length ? g2 + 1 : 0, p = p < r2.length ? p + 0.125 : 0;
|
|
3616
|
+
}, n);
|
|
3617
|
+
}, u = (v2 = "", g2 = 0) => {
|
|
3618
|
+
c3 = v2 ?? c3, s = false, clearInterval(t);
|
|
3619
|
+
const p = g2 === 0 ? import_picocolors2.default.green(S2) : g2 === 1 ? import_picocolors2.default.red(I2) : import_picocolors2.default.red(x2);
|
|
3620
|
+
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${p} ${c3}
|
|
3621
|
+
`), i();
|
|
3622
|
+
}, m2 = (v2 = "") => {
|
|
3623
|
+
c3 = v2 ?? c3;
|
|
3624
|
+
}, $2 = (v2) => {
|
|
3625
|
+
const g2 = v2 > 1 ? "Something went wrong" : "Canceled";
|
|
3626
|
+
s && u(g2, v2);
|
|
3627
|
+
};
|
|
3628
|
+
return process.on("uncaughtExceptionMonitor", () => $2(2)), process.on("unhandledRejection", () => $2(2)), process.on("SIGINT", () => $2(1)), process.on("SIGTERM", () => $2(1)), process.on("exit", $2), { start: l2, stop: u, message: m2 };
|
|
3629
|
+
};
|
|
3630
|
+
|
|
3631
|
+
// ../../packages/sdk/dist/errors.js
|
|
3632
|
+
var NotAuthenticatedError = class extends Error {
|
|
3633
|
+
constructor(message = "Not signed in to Ork. Run `ork login` first.") {
|
|
3634
|
+
super(message);
|
|
3635
|
+
this.name = "NotAuthenticatedError";
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
var OrkApiError = class extends Error {
|
|
3639
|
+
status;
|
|
3640
|
+
body;
|
|
3641
|
+
constructor(status, message, body) {
|
|
3642
|
+
super(message);
|
|
3643
|
+
this.status = status;
|
|
3644
|
+
this.body = body;
|
|
3645
|
+
this.name = "OrkApiError";
|
|
3646
|
+
}
|
|
3647
|
+
};
|
|
3648
|
+
|
|
3649
|
+
// ../../packages/sdk/dist/token-store.js
|
|
3650
|
+
import { homedir } from "node:os";
|
|
3651
|
+
import { join } from "node:path";
|
|
3652
|
+
import { mkdirSync, readFileSync, writeFileSync, rmSync, existsSync } from "node:fs";
|
|
3653
|
+
function isExpired(stored) {
|
|
3654
|
+
if (!stored?.token)
|
|
3655
|
+
return true;
|
|
3656
|
+
if (!stored.expiresAt)
|
|
3657
|
+
return false;
|
|
3658
|
+
const ms = new Date(stored.expiresAt).getTime();
|
|
3659
|
+
return Number.isFinite(ms) && ms <= Date.now();
|
|
3660
|
+
}
|
|
3661
|
+
function fileTokenStore(filePath) {
|
|
3662
|
+
const path = filePath ?? defaultConfigPath();
|
|
3663
|
+
return {
|
|
3664
|
+
get() {
|
|
3665
|
+
try {
|
|
3666
|
+
if (!existsSync(path))
|
|
3667
|
+
return null;
|
|
3668
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
3669
|
+
} catch {
|
|
3670
|
+
return null;
|
|
3671
|
+
}
|
|
3672
|
+
},
|
|
3673
|
+
set(value) {
|
|
3674
|
+
mkdirSync(dirOf(path), { recursive: true });
|
|
3675
|
+
writeFileSync(path, JSON.stringify(value, null, 2), { mode: 384 });
|
|
3676
|
+
},
|
|
3677
|
+
clear() {
|
|
3678
|
+
try {
|
|
3679
|
+
rmSync(path, { force: true });
|
|
3680
|
+
} catch {
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
};
|
|
3684
|
+
}
|
|
3685
|
+
function defaultConfigPath() {
|
|
3686
|
+
if (process.env["ORK_CONFIG_DIR"]) {
|
|
3687
|
+
return join(process.env["ORK_CONFIG_DIR"], "config.json");
|
|
3688
|
+
}
|
|
3689
|
+
const base = process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config");
|
|
3690
|
+
return join(base, "ork", "config.json");
|
|
3691
|
+
}
|
|
3692
|
+
function dirOf(path) {
|
|
3693
|
+
return path.slice(0, Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")));
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
// ../../packages/sdk/dist/http.js
|
|
3697
|
+
var Http = class {
|
|
3698
|
+
baseUrl;
|
|
3699
|
+
tokenStore;
|
|
3700
|
+
apiKey;
|
|
3701
|
+
fetchImpl;
|
|
3702
|
+
constructor(config) {
|
|
3703
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
3704
|
+
this.tokenStore = config.tokenStore;
|
|
3705
|
+
this.apiKey = config.apiKey;
|
|
3706
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
3707
|
+
if (!this.fetchImpl) {
|
|
3708
|
+
throw new Error("No fetch available. Use Node >= 18 or pass `fetch` in the SDK config.");
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
async token() {
|
|
3712
|
+
const stored = await this.tokenStore.get();
|
|
3713
|
+
if (isExpired(stored))
|
|
3714
|
+
return null;
|
|
3715
|
+
return stored.token;
|
|
3716
|
+
}
|
|
3717
|
+
async request(path, opts = {}) {
|
|
3718
|
+
const headers = {
|
|
3719
|
+
"Content-Type": "application/json"
|
|
3720
|
+
};
|
|
3721
|
+
if (!opts.anonymous) {
|
|
3722
|
+
if (this.apiKey) {
|
|
3723
|
+
headers["x-api-key"] = this.apiKey;
|
|
3724
|
+
} else {
|
|
3725
|
+
const token = await this.token();
|
|
3726
|
+
if (!token)
|
|
3727
|
+
throw new NotAuthenticatedError();
|
|
3728
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
const url = this.baseUrl + path + buildQuery(opts.query);
|
|
3732
|
+
const res = await this.fetchImpl(url, {
|
|
3733
|
+
method: opts.method ?? "GET",
|
|
3734
|
+
headers,
|
|
3735
|
+
body: opts.body === void 0 ? void 0 : JSON.stringify(opts.body),
|
|
3736
|
+
signal: opts.signal
|
|
3737
|
+
});
|
|
3738
|
+
await this.maybeRefreshToken(res);
|
|
3739
|
+
if (!res.ok) {
|
|
3740
|
+
throw await toApiError(res);
|
|
3741
|
+
}
|
|
3742
|
+
if (res.status === 204)
|
|
3743
|
+
return void 0;
|
|
3744
|
+
const text = await res.text();
|
|
3745
|
+
return text ? JSON.parse(text) : void 0;
|
|
3746
|
+
}
|
|
3747
|
+
/** Persist a server-rotated bearer token, preserving the cached identity. */
|
|
3748
|
+
async maybeRefreshToken(res) {
|
|
3749
|
+
const fresh = res.headers.get("set-auth-token");
|
|
3750
|
+
if (!fresh)
|
|
3751
|
+
return;
|
|
3752
|
+
const existing = await this.tokenStore.get();
|
|
3753
|
+
try {
|
|
3754
|
+
await this.tokenStore.set({ ...existing, token: fresh });
|
|
3755
|
+
} catch {
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
};
|
|
3759
|
+
function buildQuery(query) {
|
|
3760
|
+
if (!query)
|
|
3761
|
+
return "";
|
|
3762
|
+
const params = new URLSearchParams();
|
|
3763
|
+
for (const [key, value] of Object.entries(query)) {
|
|
3764
|
+
if (value !== void 0 && value !== null)
|
|
3765
|
+
params.set(key, String(value));
|
|
3766
|
+
}
|
|
3767
|
+
const qs = params.toString();
|
|
3768
|
+
return qs ? `?${qs}` : "";
|
|
3769
|
+
}
|
|
3770
|
+
async function toApiError(res) {
|
|
3771
|
+
let body;
|
|
3772
|
+
let message = `Ork API responded ${res.status}`;
|
|
3773
|
+
try {
|
|
3774
|
+
const text = await res.text();
|
|
3775
|
+
if (text) {
|
|
3776
|
+
body = JSON.parse(text);
|
|
3777
|
+
const raw = body?.message ?? body?.error;
|
|
3778
|
+
if (typeof raw === "string") {
|
|
3779
|
+
message = raw;
|
|
3780
|
+
} else if (raw !== void 0 || body !== void 0) {
|
|
3781
|
+
message = JSON.stringify(raw ?? body);
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
} catch {
|
|
3785
|
+
}
|
|
3786
|
+
return new OrkApiError(res.status, message, body);
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
// ../../packages/sdk/dist/resources/auth.js
|
|
3790
|
+
function createAuthResource(http, tokenStore) {
|
|
3791
|
+
return {
|
|
3792
|
+
/** Email a magic link. `webVerifyUrl` makes the emailed link land on the web app. */
|
|
3793
|
+
async requestMagicLink(email, webVerifyUrl) {
|
|
3794
|
+
await http.request("/api/auth/sign-in/magic-link", {
|
|
3795
|
+
method: "POST",
|
|
3796
|
+
anonymous: true,
|
|
3797
|
+
body: {
|
|
3798
|
+
email,
|
|
3799
|
+
name: email.split("@")[0],
|
|
3800
|
+
...webVerifyUrl ? { callbackURL: webVerifyUrl } : {}
|
|
3801
|
+
}
|
|
3802
|
+
});
|
|
3803
|
+
},
|
|
3804
|
+
/**
|
|
3805
|
+
* Verify the emailed token, fetch the real session, and persist it.
|
|
3806
|
+
* Accepts either the raw token or the full magic-link URL (we extract `token`).
|
|
3807
|
+
*/
|
|
3808
|
+
async verifyMagicLink(tokenOrUrl, email) {
|
|
3809
|
+
const token = extractToken(tokenOrUrl);
|
|
3810
|
+
const verify = await http.request("/api/auth/magic-link/verify", {
|
|
3811
|
+
method: "GET",
|
|
3812
|
+
anonymous: true,
|
|
3813
|
+
query: { token, ...email ? { email } : {} }
|
|
3814
|
+
});
|
|
3815
|
+
const bearer = verify.token;
|
|
3816
|
+
if (!bearer)
|
|
3817
|
+
throw new Error("Magic link verification returned no token.");
|
|
3818
|
+
await tokenStore.set({ token: bearer });
|
|
3819
|
+
const session = await fetchSession(http);
|
|
3820
|
+
await tokenStore.set({
|
|
3821
|
+
token: bearer,
|
|
3822
|
+
expiresAt: session?.expiresAt,
|
|
3823
|
+
user: session?.user
|
|
3824
|
+
});
|
|
3825
|
+
if (!session) {
|
|
3826
|
+
return { user: { id: "", email: email ?? "" }, expiresAt: "" };
|
|
3827
|
+
}
|
|
3828
|
+
return session;
|
|
3829
|
+
},
|
|
3830
|
+
/** Current session, or null if not signed in / expired. */
|
|
3831
|
+
async getSession() {
|
|
3832
|
+
const token = await http.token();
|
|
3833
|
+
if (!token)
|
|
3834
|
+
return null;
|
|
3835
|
+
return fetchSession(http);
|
|
3836
|
+
},
|
|
3837
|
+
async isAuthenticated() {
|
|
3838
|
+
return !isExpired(await tokenStore.get());
|
|
3839
|
+
},
|
|
3840
|
+
/** Revoke server-side and wipe local storage. */
|
|
3841
|
+
async logout() {
|
|
3842
|
+
try {
|
|
3843
|
+
await http.request("/api/auth/sign-out", { method: "POST" });
|
|
3844
|
+
} catch {
|
|
3845
|
+
}
|
|
3846
|
+
await tokenStore.clear();
|
|
3847
|
+
}
|
|
3848
|
+
};
|
|
3849
|
+
}
|
|
3850
|
+
async function fetchSession(http) {
|
|
3851
|
+
const res = await http.request("/api/auth/get-session");
|
|
3852
|
+
if (!res?.session || !res.user)
|
|
3853
|
+
return null;
|
|
3854
|
+
return {
|
|
3855
|
+
user: res.user,
|
|
3856
|
+
expiresAt: res.session.expiresAt
|
|
3857
|
+
};
|
|
3858
|
+
}
|
|
3859
|
+
function extractToken(tokenOrUrl) {
|
|
3860
|
+
const trimmed = tokenOrUrl.trim();
|
|
3861
|
+
if (trimmed.includes("://") || trimmed.includes("token=")) {
|
|
3862
|
+
try {
|
|
3863
|
+
const url = new URL(trimmed);
|
|
3864
|
+
const t = url.searchParams.get("token");
|
|
3865
|
+
if (t)
|
|
3866
|
+
return t;
|
|
3867
|
+
} catch {
|
|
3868
|
+
const match = trimmed.match(/token=([^&\s]+)/);
|
|
3869
|
+
if (match)
|
|
3870
|
+
return decodeURIComponent(match[1]);
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
return trimmed;
|
|
3874
|
+
}
|
|
3875
|
+
|
|
3876
|
+
// ../../packages/sdk/dist/resources/notes.js
|
|
3877
|
+
function createNotesResource(http) {
|
|
3878
|
+
return {
|
|
3879
|
+
create(payload) {
|
|
3880
|
+
return http.request("/api/notes/create", { method: "POST", body: payload });
|
|
3881
|
+
},
|
|
3882
|
+
get(id) {
|
|
3883
|
+
return http.request(`/api/notes/${id}`);
|
|
3884
|
+
},
|
|
3885
|
+
update(id, payload) {
|
|
3886
|
+
return http.request(`/api/notes/${id}`, { method: "PUT", body: payload });
|
|
3887
|
+
},
|
|
3888
|
+
delete(id) {
|
|
3889
|
+
return http.request(`/api/notes/${id}`, { method: "DELETE" });
|
|
3890
|
+
},
|
|
3891
|
+
list(query) {
|
|
3892
|
+
return http.request("/api/notes/all", {
|
|
3893
|
+
query
|
|
3894
|
+
});
|
|
3895
|
+
},
|
|
3896
|
+
search(q3) {
|
|
3897
|
+
return http.request("/api/notes/search", { query: { q: q3 } });
|
|
3898
|
+
},
|
|
3899
|
+
// ── Pinning ──────────────────────────────────────────────────────────
|
|
3900
|
+
pinned() {
|
|
3901
|
+
return http.request("/api/notes/pinned");
|
|
3902
|
+
},
|
|
3903
|
+
pin(id) {
|
|
3904
|
+
return http.request(`/api/notes/pin/${id}`, { method: "POST" });
|
|
3905
|
+
},
|
|
3906
|
+
unpin(id) {
|
|
3907
|
+
return http.request(`/api/notes/unpin/${id}`, { method: "POST" });
|
|
3908
|
+
},
|
|
3909
|
+
// ── Publishing ───────────────────────────────────────────────────────
|
|
3910
|
+
publish(id, payload) {
|
|
3911
|
+
return http.request(`/api/notes/${id}/publish`, {
|
|
3912
|
+
method: "POST",
|
|
3913
|
+
body: payload ?? {}
|
|
3914
|
+
});
|
|
3915
|
+
},
|
|
3916
|
+
unpublish(id) {
|
|
3917
|
+
return http.request(`/api/notes/${id}/unpublish`, { method: "POST" });
|
|
3918
|
+
},
|
|
3919
|
+
getPublic(slug) {
|
|
3920
|
+
return http.request(`/api/notes/public/${slug}`);
|
|
3921
|
+
},
|
|
3922
|
+
// ── Archiving ────────────────────────────────────────────────────────
|
|
3923
|
+
archive(id) {
|
|
3924
|
+
return http.request(`/api/notes/archive/${id}`, { method: "POST" });
|
|
3925
|
+
},
|
|
3926
|
+
unarchive(id) {
|
|
3927
|
+
return http.request(`/api/notes/unarchive/${id}`, { method: "POST" });
|
|
3928
|
+
},
|
|
3929
|
+
// ── Tags on a note ───────────────────────────────────────────────────
|
|
3930
|
+
listTags(id) {
|
|
3931
|
+
return http.request(`/api/notes/${id}/tags`);
|
|
3932
|
+
},
|
|
3933
|
+
/** Add tags (additive). */
|
|
3934
|
+
addTags(id, tagIds) {
|
|
3935
|
+
return http.request(`/api/notes/${id}/tags`, {
|
|
3936
|
+
method: "POST",
|
|
3937
|
+
body: { tagIds }
|
|
3938
|
+
});
|
|
3939
|
+
},
|
|
3940
|
+
/** Replace the full tag set on a note. */
|
|
3941
|
+
setTags(id, tagIds) {
|
|
3942
|
+
return http.request(`/api/notes/${id}/tags`, {
|
|
3943
|
+
method: "PUT",
|
|
3944
|
+
body: { tagIds }
|
|
3945
|
+
});
|
|
3946
|
+
},
|
|
3947
|
+
removeTag(id, tagId) {
|
|
3948
|
+
return http.request(`/api/notes/${id}/tags/${tagId}`, {
|
|
3949
|
+
method: "DELETE"
|
|
3950
|
+
});
|
|
3951
|
+
}
|
|
3952
|
+
};
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
// ../../packages/sdk/dist/resources/collections.js
|
|
3956
|
+
function createCollectionsResource(http) {
|
|
3957
|
+
return {
|
|
3958
|
+
list(query) {
|
|
3959
|
+
return http.request("/api/collections", {
|
|
3960
|
+
query
|
|
3961
|
+
});
|
|
3962
|
+
},
|
|
3963
|
+
create(payload) {
|
|
3964
|
+
return http.request("/api/collections", { method: "POST", body: payload });
|
|
3965
|
+
},
|
|
3966
|
+
get(id) {
|
|
3967
|
+
return http.request(`/api/collections/${id}`);
|
|
3968
|
+
},
|
|
3969
|
+
update(id, payload) {
|
|
3970
|
+
return http.request(`/api/collections/${id}`, {
|
|
3971
|
+
method: "PUT",
|
|
3972
|
+
body: payload
|
|
3973
|
+
});
|
|
3974
|
+
},
|
|
3975
|
+
delete(id) {
|
|
3976
|
+
return http.request(`/api/collections/${id}`, { method: "DELETE" });
|
|
3977
|
+
},
|
|
3978
|
+
// ── Publishing ───────────────────────────────────────────────────────
|
|
3979
|
+
// A collection needs a slug to be published (unlike notes, it isn't
|
|
3980
|
+
// auto-generated). Pass one in `payload.slug` if it doesn't have one yet.
|
|
3981
|
+
// The endpoint validates a JSON body, so we always send at least {}.
|
|
3982
|
+
publish(id, payload = {}) {
|
|
3983
|
+
return http.request(`/api/collections/${id}/publish`, {
|
|
3984
|
+
method: "POST",
|
|
3985
|
+
body: payload
|
|
3986
|
+
});
|
|
3987
|
+
},
|
|
3988
|
+
unpublish(id) {
|
|
3989
|
+
return http.request(`/api/collections/${id}/unpublish`, {
|
|
3990
|
+
method: "POST"
|
|
3991
|
+
});
|
|
3992
|
+
},
|
|
3993
|
+
getPublic(slug) {
|
|
3994
|
+
return http.request(`/api/collections/public/${slug}`);
|
|
3995
|
+
},
|
|
3996
|
+
// ── Membership ───────────────────────────────────────────────────────
|
|
3997
|
+
addNotes(id, payload) {
|
|
3998
|
+
return http.request(`/api/collections/${id}/notes`, {
|
|
3999
|
+
method: "POST",
|
|
4000
|
+
body: payload
|
|
4001
|
+
});
|
|
4002
|
+
},
|
|
4003
|
+
setNotes(id, payload) {
|
|
4004
|
+
return http.request(`/api/collections/${id}/notes`, {
|
|
4005
|
+
method: "PUT",
|
|
4006
|
+
body: payload
|
|
4007
|
+
});
|
|
4008
|
+
},
|
|
4009
|
+
reorderNotes(id, noteIds) {
|
|
4010
|
+
return http.request(`/api/collections/${id}/notes/order`, {
|
|
4011
|
+
method: "PUT",
|
|
4012
|
+
body: { noteIds }
|
|
4013
|
+
});
|
|
4014
|
+
},
|
|
4015
|
+
removeNote(id, noteId) {
|
|
4016
|
+
return http.request(`/api/collections/${id}/notes/${noteId}`, {
|
|
4017
|
+
method: "DELETE"
|
|
4018
|
+
});
|
|
4019
|
+
}
|
|
4020
|
+
};
|
|
4021
|
+
}
|
|
4022
|
+
|
|
4023
|
+
// ../../packages/sdk/dist/resources/tags.js
|
|
4024
|
+
function createTagsResource(http) {
|
|
4025
|
+
return {
|
|
4026
|
+
list(query) {
|
|
4027
|
+
return http.request("/api/user/tags", {
|
|
4028
|
+
query
|
|
4029
|
+
});
|
|
4030
|
+
},
|
|
4031
|
+
create(payload) {
|
|
4032
|
+
return http.request("/api/user/tags", { method: "POST", body: payload });
|
|
4033
|
+
},
|
|
4034
|
+
get(id) {
|
|
4035
|
+
return http.request(`/api/user/tags/${id}`);
|
|
4036
|
+
},
|
|
4037
|
+
update(id, payload) {
|
|
4038
|
+
return http.request(`/api/user/tags/${id}`, {
|
|
4039
|
+
method: "PUT",
|
|
4040
|
+
body: payload
|
|
4041
|
+
});
|
|
4042
|
+
},
|
|
4043
|
+
delete(id) {
|
|
4044
|
+
return http.request(`/api/user/tags/${id}`, { method: "DELETE" });
|
|
4045
|
+
}
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
4048
|
+
|
|
4049
|
+
// ../../packages/sdk/dist/resources/api-keys.js
|
|
4050
|
+
function createApiKeysResource(http) {
|
|
4051
|
+
return {
|
|
4052
|
+
create(input = {}) {
|
|
4053
|
+
return http.request("/api/auth/api-key/create", {
|
|
4054
|
+
method: "POST",
|
|
4055
|
+
body: input
|
|
4056
|
+
});
|
|
4057
|
+
},
|
|
4058
|
+
list() {
|
|
4059
|
+
return http.request("/api/auth/api-key/list");
|
|
4060
|
+
},
|
|
4061
|
+
delete(keyId) {
|
|
4062
|
+
return http.request("/api/auth/api-key/delete", {
|
|
4063
|
+
method: "POST",
|
|
4064
|
+
body: { keyId }
|
|
4065
|
+
});
|
|
4066
|
+
}
|
|
4067
|
+
};
|
|
4068
|
+
}
|
|
4069
|
+
|
|
4070
|
+
// ../../packages/sdk/dist/markdown.js
|
|
4071
|
+
var TASK_LIST_OPEN = '<ul data-type="taskList">';
|
|
4072
|
+
function markdownToBlocks(markdown) {
|
|
4073
|
+
const lines = normalizeHtmlBlocks(markdown.replace(/\r\n/g, "\n")).split("\n");
|
|
4074
|
+
const blocks = [];
|
|
4075
|
+
let i = 0;
|
|
4076
|
+
while (i < lines.length) {
|
|
4077
|
+
const line = lines[i];
|
|
4078
|
+
if (line.trim() === "") {
|
|
4079
|
+
i++;
|
|
4080
|
+
continue;
|
|
4081
|
+
}
|
|
4082
|
+
const fence = line.match(/^```(\w*)\s*$/);
|
|
4083
|
+
if (fence) {
|
|
4084
|
+
const language = fence[1] || "plaintext";
|
|
4085
|
+
const code = [];
|
|
4086
|
+
i++;
|
|
4087
|
+
while (i < lines.length && !/^```\s*$/.test(lines[i])) {
|
|
4088
|
+
code.push(lines[i]);
|
|
4089
|
+
i++;
|
|
4090
|
+
}
|
|
4091
|
+
i++;
|
|
4092
|
+
blocks.push({
|
|
4093
|
+
blockType: "code",
|
|
4094
|
+
content: JSON.stringify({ language, code: code.join("\n") })
|
|
4095
|
+
});
|
|
4096
|
+
continue;
|
|
4097
|
+
}
|
|
4098
|
+
const heading = line.match(/^(#{1,4})\s+(.*)$/);
|
|
4099
|
+
if (heading) {
|
|
4100
|
+
const level = heading[1].length;
|
|
4101
|
+
blocks.push({
|
|
4102
|
+
blockType: `h${level}`,
|
|
4103
|
+
content: `<h${level}>${inlineToHtml(heading[2].trim())}</h${level}>`
|
|
4104
|
+
});
|
|
4105
|
+
i++;
|
|
4106
|
+
continue;
|
|
4107
|
+
}
|
|
4108
|
+
if (/^\s*[-*]\s+\[[ xX]\]\s+/.test(line)) {
|
|
4109
|
+
const items = [];
|
|
4110
|
+
while (i < lines.length && /^\s*[-*]\s+\[[ xX]\]\s+/.test(lines[i])) {
|
|
4111
|
+
const m2 = lines[i].match(/^\s*[-*]\s+\[([ xX])\]\s+(.*)$/);
|
|
4112
|
+
items.push({ checked: m2[1].toLowerCase() === "x", text: m2[2] });
|
|
4113
|
+
i++;
|
|
4114
|
+
}
|
|
4115
|
+
blocks.push({ blockType: "tasks", content: tasksToHtml(items) });
|
|
4116
|
+
continue;
|
|
4117
|
+
}
|
|
4118
|
+
if (/^\s*[-*]\s+/.test(line)) {
|
|
4119
|
+
const items = [];
|
|
4120
|
+
while (i < lines.length && /^\s*[-*]\s+/.test(lines[i]) && !/^\s*[-*]\s+\[[ xX]\]/.test(lines[i])) {
|
|
4121
|
+
items.push(lines[i].replace(/^\s*[-*]\s+/, ""));
|
|
4122
|
+
i++;
|
|
4123
|
+
}
|
|
4124
|
+
blocks.push({ blockType: "ul", content: listToHtml("ul", items) });
|
|
4125
|
+
continue;
|
|
4126
|
+
}
|
|
4127
|
+
if (/^\s*\d+\.\s+/.test(line)) {
|
|
4128
|
+
const items = [];
|
|
4129
|
+
while (i < lines.length && /^\s*\d+\.\s+/.test(lines[i])) {
|
|
4130
|
+
items.push(lines[i].replace(/^\s*\d+\.\s+/, ""));
|
|
4131
|
+
i++;
|
|
4132
|
+
}
|
|
4133
|
+
blocks.push({ blockType: "ol", content: listToHtml("ol", items) });
|
|
4134
|
+
continue;
|
|
4135
|
+
}
|
|
4136
|
+
const para = [];
|
|
4137
|
+
while (i < lines.length && lines[i].trim() !== "" && !isStructural(lines[i])) {
|
|
4138
|
+
para.push(lines[i].trim());
|
|
4139
|
+
i++;
|
|
4140
|
+
}
|
|
4141
|
+
blocks.push({
|
|
4142
|
+
blockType: "p",
|
|
4143
|
+
content: `<p>${inlineToHtml(para.join(" "))}</p>`
|
|
4144
|
+
});
|
|
4145
|
+
}
|
|
4146
|
+
if (blocks.length === 0) {
|
|
4147
|
+
blocks.push({ blockType: "p", content: "<p></p>" });
|
|
4148
|
+
}
|
|
4149
|
+
return blocks.map((b3, idx) => ({ ...b3, position: idx }));
|
|
4150
|
+
}
|
|
4151
|
+
function isStructural(line) {
|
|
4152
|
+
return /^#{1,4}\s/.test(line) || /^```/.test(line) || /^\s*[-*]\s+/.test(line) || /^\s*\d+\.\s+/.test(line);
|
|
4153
|
+
}
|
|
4154
|
+
function normalizeHtmlBlocks(text) {
|
|
4155
|
+
if (!/<(h[1-6]|p|ul|ol|li|br)\b[^>]*>/i.test(text))
|
|
4156
|
+
return text;
|
|
4157
|
+
return text.replace(/<h([1-6])[^>]*>([\s\S]*?)<\/h\1>/gi, (_m, n, inner) => `
|
|
4158
|
+
|
|
4159
|
+
${"#".repeat(Math.min(4, Number(n)))} ${htmlToInline(inner).trim()}
|
|
4160
|
+
|
|
4161
|
+
`).replace(/<li[^>]*>([\s\S]*?)<\/li>/gi, (_m, inner) => `
|
|
4162
|
+
- ${htmlToInline(inner).trim()}`).replace(/<\/?(?:ul|ol)[^>]*>/gi, "\n\n").replace(/<p[^>]*>([\s\S]*?)<\/p>/gi, (_m, inner) => `
|
|
4163
|
+
|
|
4164
|
+
${htmlToInline(inner).trim()}
|
|
4165
|
+
|
|
4166
|
+
`).replace(/<br\s*\/?>/gi, "\n");
|
|
4167
|
+
}
|
|
4168
|
+
function blocksToMarkdown(blocks) {
|
|
4169
|
+
const ordered = [...blocks].sort((a3, b3) => (a3.position ?? 0) - (b3.position ?? 0));
|
|
4170
|
+
return ordered.map((b3) => blockToMarkdown(b3)).filter(Boolean).join("\n\n");
|
|
4171
|
+
}
|
|
4172
|
+
function blockToMarkdown(block) {
|
|
4173
|
+
const content = block.content ?? "";
|
|
4174
|
+
switch (block.blockType) {
|
|
4175
|
+
case "h1":
|
|
4176
|
+
case "h2":
|
|
4177
|
+
case "h3":
|
|
4178
|
+
case "h4": {
|
|
4179
|
+
const level = Number(block.blockType.slice(1));
|
|
4180
|
+
return `${"#".repeat(level)} ${htmlToInline(stripTag(content))}`;
|
|
4181
|
+
}
|
|
4182
|
+
case "p":
|
|
4183
|
+
return htmlToInline(stripTag(content));
|
|
4184
|
+
case "ul":
|
|
4185
|
+
return htmlListItems(content).map((t) => `- ${t}`).join("\n");
|
|
4186
|
+
case "ol":
|
|
4187
|
+
return htmlListItems(content).map((t, idx) => `${idx + 1}. ${t}`).join("\n");
|
|
4188
|
+
case "tasks":
|
|
4189
|
+
return htmlTaskItems(content).map((it) => `- [${it.checked ? "x" : " "}] ${it.text}`).join("\n");
|
|
4190
|
+
case "code": {
|
|
4191
|
+
const { language, code } = parseJson(content);
|
|
4192
|
+
return "```" + (language || "") + "\n" + (code ?? "") + "\n```";
|
|
4193
|
+
}
|
|
4194
|
+
case "url": {
|
|
4195
|
+
const meta = parseJson(content);
|
|
4196
|
+
if (!meta.url)
|
|
4197
|
+
return "";
|
|
4198
|
+
return meta.title ? `[${meta.title}](${meta.url})` : meta.url;
|
|
4199
|
+
}
|
|
4200
|
+
case "image": {
|
|
4201
|
+
const meta = parseJson(content);
|
|
4202
|
+
return meta.url ? `` : "";
|
|
4203
|
+
}
|
|
4204
|
+
case "attachment":
|
|
4205
|
+
case "audio": {
|
|
4206
|
+
const meta = parseJson(content);
|
|
4207
|
+
return meta.url ? `[${meta.filename ?? "attachment"}](${meta.url})` : "";
|
|
4208
|
+
}
|
|
4209
|
+
default:
|
|
4210
|
+
return htmlToInline(stripTag(content));
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
function listToHtml(tag, items) {
|
|
4214
|
+
const lis = items.map((t) => `<li><p>${inlineToHtml(t.trim())}</p></li>`).join("");
|
|
4215
|
+
return `<${tag}>${lis}</${tag}>`;
|
|
4216
|
+
}
|
|
4217
|
+
function tasksToHtml(items) {
|
|
4218
|
+
const lis = items.map((it) => `<li data-type="taskItem" data-checked="${it.checked}"><label><input type="checkbox"${it.checked ? " checked" : ""}><span></span></label><div><p>${inlineToHtml(it.text.trim())}</p></div></li>`).join("");
|
|
4219
|
+
return `${TASK_LIST_OPEN}${lis}</ul>`;
|
|
4220
|
+
}
|
|
4221
|
+
function inlineToHtml(text) {
|
|
4222
|
+
let out = escapeHtml(text);
|
|
4223
|
+
out = out.replace(/`([^`]+)`/g, (_m, c3) => `<code>${c3}</code>`);
|
|
4224
|
+
out = out.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
|
4225
|
+
out = out.replace(/(^|[^*])\*([^*]+)\*/g, "$1<em>$2</em>");
|
|
4226
|
+
out = out.replace(/_([^_]+)_/g, "<em>$1</em>");
|
|
4227
|
+
out = out.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, label, href) => `<a href="${href}">${label}</a>`);
|
|
4228
|
+
return out;
|
|
4229
|
+
}
|
|
4230
|
+
function htmlToInline(html) {
|
|
4231
|
+
let out = html;
|
|
4232
|
+
out = out.replace(/<strong>(.*?)<\/strong>/gi, "**$1**");
|
|
4233
|
+
out = out.replace(/<b>(.*?)<\/b>/gi, "**$1**");
|
|
4234
|
+
out = out.replace(/<em>(.*?)<\/em>/gi, "*$1*");
|
|
4235
|
+
out = out.replace(/<i>(.*?)<\/i>/gi, "*$1*");
|
|
4236
|
+
out = out.replace(/<code>(.*?)<\/code>/gi, "`$1`");
|
|
4237
|
+
out = out.replace(/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, (_m, href, label) => `[${label}](${href})`);
|
|
4238
|
+
out = out.replace(/<br\s*\/?>/gi, " ");
|
|
4239
|
+
out = out.replace(/<[^>]+>/g, "");
|
|
4240
|
+
return unescapeHtml(out).trim();
|
|
4241
|
+
}
|
|
4242
|
+
function stripTag(html) {
|
|
4243
|
+
return html.replace(/^<(p|h[1-4])>/i, "").replace(/<\/(p|h[1-4])>$/i, "");
|
|
4244
|
+
}
|
|
4245
|
+
function htmlListItems(html) {
|
|
4246
|
+
const items = [...html.matchAll(/<li[^>]*>([\s\S]*?)<\/li>/gi)].map((m2) => htmlToInline(m2[1].replace(/<\/?p>/gi, "")));
|
|
4247
|
+
return items.filter((t) => t.length > 0 || items.length === 1);
|
|
4248
|
+
}
|
|
4249
|
+
function htmlTaskItems(html) {
|
|
4250
|
+
return [...html.matchAll(/<li[^>]*data-checked="(true|false)"[^>]*>([\s\S]*?)<\/li>/gi)].map((m2) => ({
|
|
4251
|
+
checked: m2[1] === "true",
|
|
4252
|
+
text: htmlToInline(m2[2].replace(/<label>[\s\S]*?<\/label>/i, "").replace(/<\/?(div|p)>/gi, ""))
|
|
4253
|
+
}));
|
|
4254
|
+
}
|
|
4255
|
+
function escapeHtml(s) {
|
|
4256
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4257
|
+
}
|
|
4258
|
+
function unescapeHtml(s) {
|
|
4259
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'");
|
|
4260
|
+
}
|
|
4261
|
+
function parseJson(s) {
|
|
4262
|
+
try {
|
|
4263
|
+
return JSON.parse(s);
|
|
4264
|
+
} catch {
|
|
4265
|
+
return {};
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
|
|
4269
|
+
// ../../packages/sdk/dist/client.js
|
|
4270
|
+
function createOrkClient(config) {
|
|
4271
|
+
const tokenStore = config.tokenStore ?? fileTokenStore();
|
|
4272
|
+
const http = new Http({
|
|
4273
|
+
baseUrl: config.baseUrl,
|
|
4274
|
+
tokenStore,
|
|
4275
|
+
apiKey: config.apiKey,
|
|
4276
|
+
fetch: config.fetch
|
|
4277
|
+
});
|
|
4278
|
+
const notes = createNotesResource(http);
|
|
4279
|
+
return {
|
|
4280
|
+
http,
|
|
4281
|
+
tokenStore,
|
|
4282
|
+
auth: createAuthResource(http, tokenStore),
|
|
4283
|
+
notes,
|
|
4284
|
+
collections: createCollectionsResource(http),
|
|
4285
|
+
tags: createTagsResource(http),
|
|
4286
|
+
apiKeys: createApiKeysResource(http),
|
|
4287
|
+
/** Markdown convenience layer (the dual-format authoring surface). */
|
|
4288
|
+
markdown: {
|
|
4289
|
+
toBlocks: markdownToBlocks,
|
|
4290
|
+
fromBlocks: blocksToMarkdown,
|
|
4291
|
+
/** Create a note from a markdown body in one call. */
|
|
4292
|
+
createNote(title, markdown, extra) {
|
|
4293
|
+
return notes.create({
|
|
4294
|
+
title,
|
|
4295
|
+
blocks: markdownToBlocks(markdown),
|
|
4296
|
+
...extra
|
|
4297
|
+
});
|
|
4298
|
+
},
|
|
4299
|
+
/** Fetch a note and render its blocks as markdown. */
|
|
4300
|
+
async getNote(id) {
|
|
4301
|
+
const res = await notes.get(id);
|
|
4302
|
+
return {
|
|
4303
|
+
title: res.note.title,
|
|
4304
|
+
markdown: blocksToMarkdown(res.note.blocks)
|
|
4305
|
+
};
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
};
|
|
4309
|
+
}
|
|
4310
|
+
|
|
4311
|
+
// src/config.ts
|
|
4312
|
+
var DEFAULT_API_URL = "https://api.ork.so";
|
|
4313
|
+
var DEFAULT_WEB_URL = "https://ork.so";
|
|
4314
|
+
function apiUrl() {
|
|
4315
|
+
return (process.env["ORK_API_URL"] ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
4316
|
+
}
|
|
4317
|
+
function webUrl() {
|
|
4318
|
+
return (process.env["ORK_WEB_URL"] ?? DEFAULT_WEB_URL).replace(/\/+$/, "");
|
|
4319
|
+
}
|
|
4320
|
+
function client() {
|
|
4321
|
+
return createOrkClient({
|
|
4322
|
+
baseUrl: apiUrl(),
|
|
4323
|
+
tokenStore: fileTokenStore()
|
|
4324
|
+
});
|
|
4325
|
+
}
|
|
4326
|
+
|
|
4327
|
+
// src/ui.ts
|
|
4328
|
+
var useColor = process.stdout.isTTY && !process.env["NO_COLOR"];
|
|
4329
|
+
var wrap = (code) => (s) => useColor ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
4330
|
+
var c2 = {
|
|
4331
|
+
dim: wrap("2"),
|
|
4332
|
+
bold: wrap("1"),
|
|
4333
|
+
red: wrap("31"),
|
|
4334
|
+
green: wrap("32"),
|
|
4335
|
+
yellow: wrap("33"),
|
|
4336
|
+
blue: wrap("34"),
|
|
4337
|
+
cyan: wrap("36")
|
|
4338
|
+
};
|
|
4339
|
+
function ok(message) {
|
|
4340
|
+
console.log(`${c2.green("\u2713")} ${message}`);
|
|
4341
|
+
}
|
|
4342
|
+
function info(message) {
|
|
4343
|
+
console.log(message);
|
|
4344
|
+
}
|
|
4345
|
+
function fail(err) {
|
|
4346
|
+
if (err instanceof NotAuthenticatedError) {
|
|
4347
|
+
console.error(`${c2.red("\u2717")} Not signed in. Run ${c2.bold("ork login")} first.`);
|
|
4348
|
+
} else if (err instanceof OrkApiError) {
|
|
4349
|
+
console.error(`${c2.red("\u2717")} ${err.message} ${c2.dim(`(HTTP ${err.status})`)}`);
|
|
4350
|
+
} else if (err instanceof Error) {
|
|
4351
|
+
console.error(`${c2.red("\u2717")} ${err.message}`);
|
|
4352
|
+
} else {
|
|
4353
|
+
console.error(`${c2.red("\u2717")} ${String(err)}`);
|
|
4354
|
+
}
|
|
4355
|
+
process.exit(1);
|
|
4356
|
+
}
|
|
4357
|
+
function maybeJson(value, json) {
|
|
4358
|
+
if (!json) return false;
|
|
4359
|
+
console.log(JSON.stringify(value, null, 2));
|
|
4360
|
+
return true;
|
|
4361
|
+
}
|
|
4362
|
+
function table(rows) {
|
|
4363
|
+
if (rows.length === 0) return;
|
|
4364
|
+
const widths = [];
|
|
4365
|
+
for (const row of rows) {
|
|
4366
|
+
row.forEach((cell, i) => {
|
|
4367
|
+
const len = stripAnsi(cell).length;
|
|
4368
|
+
if (len > (widths[i] ?? 0)) widths[i] = len;
|
|
4369
|
+
});
|
|
4370
|
+
}
|
|
4371
|
+
for (const row of rows) {
|
|
4372
|
+
const line = row.map(
|
|
4373
|
+
(cell, i) => i === row.length - 1 ? cell : cell + " ".repeat(widths[i] - stripAnsi(cell).length)
|
|
4374
|
+
).join(" ");
|
|
4375
|
+
console.log(line);
|
|
4376
|
+
}
|
|
4377
|
+
}
|
|
4378
|
+
function relativeTime(iso) {
|
|
4379
|
+
const then = new Date(iso).getTime();
|
|
4380
|
+
if (!Number.isFinite(then)) return "";
|
|
4381
|
+
const secs = Math.round((Date.now() - then) / 1e3);
|
|
4382
|
+
const units = [
|
|
4383
|
+
[60, "s"],
|
|
4384
|
+
[60, "m"],
|
|
4385
|
+
[24, "h"],
|
|
4386
|
+
[7, "d"],
|
|
4387
|
+
[4.345, "w"],
|
|
4388
|
+
[12, "mo"],
|
|
4389
|
+
[Number.POSITIVE_INFINITY, "y"]
|
|
4390
|
+
];
|
|
4391
|
+
let value = secs;
|
|
4392
|
+
let unit = "s";
|
|
4393
|
+
for (const [size, label] of units) {
|
|
4394
|
+
if (Math.abs(value) < size) {
|
|
4395
|
+
unit = label;
|
|
4396
|
+
break;
|
|
4397
|
+
}
|
|
4398
|
+
value = Math.round(value / size);
|
|
4399
|
+
unit = label;
|
|
4400
|
+
}
|
|
4401
|
+
return `${value}${unit} ago`;
|
|
4402
|
+
}
|
|
4403
|
+
function stripAnsi(s) {
|
|
4404
|
+
return s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
4405
|
+
}
|
|
4406
|
+
|
|
4407
|
+
// src/commands/auth.ts
|
|
4408
|
+
function registerAuthCommands(program3) {
|
|
4409
|
+
program3.command("login").description("Sign in via magic link (or paste an existing token)").option("-e, --email <email>", "email to send the magic link to").option("-t, --token <token>", "skip the email flow and store a token directly").action(async (opts) => {
|
|
4410
|
+
const ork = client();
|
|
4411
|
+
try {
|
|
4412
|
+
if (opts.token) {
|
|
4413
|
+
await ork.tokenStore.set({ token: opts.token });
|
|
4414
|
+
const session2 = await ork.auth.getSession();
|
|
4415
|
+
if (!session2) {
|
|
4416
|
+
await ork.tokenStore.clear();
|
|
4417
|
+
throw new Error("That token was rejected by the server.");
|
|
4418
|
+
}
|
|
4419
|
+
await ork.tokenStore.set({
|
|
4420
|
+
token: opts.token,
|
|
4421
|
+
expiresAt: session2.expiresAt,
|
|
4422
|
+
user: session2.user
|
|
4423
|
+
});
|
|
4424
|
+
return ok(`Signed in as ${c2.bold(session2.user.email)}`);
|
|
4425
|
+
}
|
|
4426
|
+
const email = opts.email ?? await te({
|
|
4427
|
+
message: "Email",
|
|
4428
|
+
validate: (v2) => v2.includes("@") ? void 0 : "Enter a valid email"
|
|
4429
|
+
});
|
|
4430
|
+
if (lD(email)) return info("Cancelled.");
|
|
4431
|
+
const spin = de();
|
|
4432
|
+
spin.start("Sending magic link");
|
|
4433
|
+
await ork.auth.requestMagicLink(email, `${webUrl()}/auth/verify/`);
|
|
4434
|
+
spin.stop("Magic link sent");
|
|
4435
|
+
info(
|
|
4436
|
+
c2.dim(
|
|
4437
|
+
"Open the email and copy the link (or just the token from it), then paste it here."
|
|
4438
|
+
)
|
|
4439
|
+
);
|
|
4440
|
+
const pasted = await te({
|
|
4441
|
+
message: "Paste the magic link or token",
|
|
4442
|
+
validate: (v2) => v2.trim() ? void 0 : "Required"
|
|
4443
|
+
});
|
|
4444
|
+
if (lD(pasted)) return info("Cancelled.");
|
|
4445
|
+
const verifySpin = de();
|
|
4446
|
+
verifySpin.start("Verifying");
|
|
4447
|
+
const session = await ork.auth.verifyMagicLink(
|
|
4448
|
+
pasted,
|
|
4449
|
+
email
|
|
4450
|
+
);
|
|
4451
|
+
verifySpin.stop("Verified");
|
|
4452
|
+
ok(`Signed in as ${c2.bold(session.user.email || email)}`);
|
|
4453
|
+
} catch (err) {
|
|
4454
|
+
fail(err);
|
|
4455
|
+
}
|
|
4456
|
+
});
|
|
4457
|
+
program3.command("logout").description("Sign out and remove the stored token").action(async () => {
|
|
4458
|
+
try {
|
|
4459
|
+
await client().auth.logout();
|
|
4460
|
+
ok("Signed out.");
|
|
4461
|
+
} catch (err) {
|
|
4462
|
+
fail(err);
|
|
4463
|
+
}
|
|
4464
|
+
});
|
|
4465
|
+
program3.command("whoami").description("Show the currently signed-in user").option("--json", "output raw JSON").action(async (opts) => {
|
|
4466
|
+
try {
|
|
4467
|
+
const session = await client().auth.getSession();
|
|
4468
|
+
if (!session) {
|
|
4469
|
+
info("Not signed in.");
|
|
4470
|
+
process.exit(1);
|
|
4471
|
+
}
|
|
4472
|
+
if (opts.json) return console.log(JSON.stringify(session, null, 2));
|
|
4473
|
+
info(
|
|
4474
|
+
`${c2.bold(session.user.email)}${session.user.username ? c2.dim(` (@${session.user.username})`) : ""}`
|
|
4475
|
+
);
|
|
4476
|
+
info(c2.dim(`session expires ${new Date(session.expiresAt).toLocaleString()}`));
|
|
4477
|
+
} catch (err) {
|
|
4478
|
+
fail(err);
|
|
4479
|
+
}
|
|
4480
|
+
});
|
|
4481
|
+
}
|
|
4482
|
+
|
|
4483
|
+
// src/editor.ts
|
|
4484
|
+
import { spawn } from "node:child_process";
|
|
4485
|
+
import { mkdtempSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, rmSync as rmSync2 } from "node:fs";
|
|
4486
|
+
import { tmpdir } from "node:os";
|
|
4487
|
+
import { join as join2 } from "node:path";
|
|
4488
|
+
function readStdin() {
|
|
4489
|
+
return new Promise((resolve) => {
|
|
4490
|
+
if (process.stdin.isTTY) return resolve("");
|
|
4491
|
+
let data = "";
|
|
4492
|
+
process.stdin.setEncoding("utf8");
|
|
4493
|
+
process.stdin.on("data", (chunk) => data += chunk);
|
|
4494
|
+
process.stdin.on("end", () => resolve(data));
|
|
4495
|
+
process.stdin.on("error", () => resolve(data));
|
|
4496
|
+
});
|
|
4497
|
+
}
|
|
4498
|
+
function openEditor(initial = "", suffix = ".md") {
|
|
4499
|
+
const editor = process.env["EDITOR"] || process.env["VISUAL"] || "nano";
|
|
4500
|
+
const dir = mkdtempSync(join2(tmpdir(), "ork-"));
|
|
4501
|
+
const file = join2(dir, `note${suffix}`);
|
|
4502
|
+
writeFileSync2(file, initial, "utf8");
|
|
4503
|
+
return new Promise((resolve, reject) => {
|
|
4504
|
+
const child = spawn(editor, [file], { stdio: "inherit" });
|
|
4505
|
+
child.on("error", (err) => {
|
|
4506
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
4507
|
+
reject(err);
|
|
4508
|
+
});
|
|
4509
|
+
child.on("exit", (code) => {
|
|
4510
|
+
if (code !== 0) {
|
|
4511
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
4512
|
+
return reject(new Error(`Editor exited with code ${code}`));
|
|
4513
|
+
}
|
|
4514
|
+
const content = readFileSync2(file, "utf8");
|
|
4515
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
4516
|
+
resolve(content);
|
|
4517
|
+
});
|
|
4518
|
+
});
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
// src/commands/tag-resolve.ts
|
|
4522
|
+
var DEFAULT_TAG_ICON = "\u{1F3F7}\uFE0F";
|
|
4523
|
+
var DEFAULT_TAG_COLOR = "#6366f1";
|
|
4524
|
+
async function resolveTagIds(ork, names) {
|
|
4525
|
+
const existing = await ork.tags.list({ pageSize: 100 });
|
|
4526
|
+
const byName = new Map(existing.tags.map((t) => [t.name.toLowerCase(), t.id]));
|
|
4527
|
+
const ids = [];
|
|
4528
|
+
for (const raw of names) {
|
|
4529
|
+
const name = raw.trim();
|
|
4530
|
+
if (!name) continue;
|
|
4531
|
+
const found = byName.get(name.toLowerCase());
|
|
4532
|
+
if (found) {
|
|
4533
|
+
ids.push(found);
|
|
4534
|
+
continue;
|
|
4535
|
+
}
|
|
4536
|
+
const created = await ork.tags.create({
|
|
4537
|
+
name,
|
|
4538
|
+
icon: DEFAULT_TAG_ICON,
|
|
4539
|
+
color: DEFAULT_TAG_COLOR
|
|
4540
|
+
});
|
|
4541
|
+
const id = created.tag?.id;
|
|
4542
|
+
if (id) {
|
|
4543
|
+
byName.set(name.toLowerCase(), id);
|
|
4544
|
+
ids.push(id);
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
return ids;
|
|
4548
|
+
}
|
|
4549
|
+
|
|
4550
|
+
// src/commands/notes.ts
|
|
4551
|
+
function registerNoteCommands(program3) {
|
|
4552
|
+
program3.command("new").description("Create a note (from -m, a file, stdin, or $EDITOR)").option("-t, --title <title>", "note title").option("-m, --message <markdown>", "note body as markdown").option("-f, --file <path>", "read note body from a markdown file").option("-T, --tag <name...>", "tags to attach (created if missing)").option("--raw", "treat input as a raw JSON block array instead of markdown").option("--json", "output raw JSON").action(async (opts) => {
|
|
4553
|
+
const ork = client();
|
|
4554
|
+
try {
|
|
4555
|
+
let bodyText = opts.message;
|
|
4556
|
+
if (!bodyText && opts.file) {
|
|
4557
|
+
const { readFileSync: readFileSync3 } = await import("node:fs");
|
|
4558
|
+
bodyText = readFileSync3(opts.file, "utf8");
|
|
4559
|
+
}
|
|
4560
|
+
if (!bodyText) bodyText = await readStdin();
|
|
4561
|
+
if (!bodyText && process.stdin.isTTY) bodyText = await openEditor();
|
|
4562
|
+
if (!bodyText?.trim()) return info("Nothing to save \u2014 empty note.");
|
|
4563
|
+
const blocks = opts.raw ? JSON.parse(bodyText) : ork.markdown.toBlocks(bodyText);
|
|
4564
|
+
const res = await ork.notes.create({
|
|
4565
|
+
title: opts.title ?? null,
|
|
4566
|
+
blocks
|
|
4567
|
+
});
|
|
4568
|
+
const note = res.note;
|
|
4569
|
+
if (opts.tag?.length) {
|
|
4570
|
+
const tagIds = await resolveTagIds(ork, opts.tag);
|
|
4571
|
+
if (tagIds.length) await ork.notes.addTags(note.id, tagIds);
|
|
4572
|
+
}
|
|
4573
|
+
if (maybeJson(res, opts.json)) return;
|
|
4574
|
+
ok(`Created note ${c2.bold(note.title || note.id)}`);
|
|
4575
|
+
info(c2.dim(`${webUrl()}/${note.slug ?? note.id}`));
|
|
4576
|
+
} catch (err) {
|
|
4577
|
+
fail(err);
|
|
4578
|
+
}
|
|
4579
|
+
});
|
|
4580
|
+
program3.command("ls").description("List your notes").option("-n, --limit <n>", "how many to show", "20").option("-p, --pinned", "only pinned notes").option("--json", "output raw JSON").action(async (opts) => {
|
|
4581
|
+
try {
|
|
4582
|
+
const ork = client();
|
|
4583
|
+
const res = opts.pinned ? await ork.notes.pinned() : await ork.notes.list({ pageSize: Number(opts.limit) });
|
|
4584
|
+
if (maybeJson(res, opts.json)) return;
|
|
4585
|
+
if (!res.notes.length) return info("No notes yet.");
|
|
4586
|
+
table(
|
|
4587
|
+
res.notes.map((n) => [
|
|
4588
|
+
c2.dim(n.id),
|
|
4589
|
+
c2.bold(n.title || c2.dim("(untitled)")),
|
|
4590
|
+
c2.dim(relativeTime(n.updatedAt ?? ""))
|
|
4591
|
+
])
|
|
4592
|
+
);
|
|
4593
|
+
} catch (err) {
|
|
4594
|
+
fail(err);
|
|
4595
|
+
}
|
|
4596
|
+
});
|
|
4597
|
+
program3.command("search <query>").description("Full-text search your notes").option("--json", "output raw JSON").action(async (query, opts) => {
|
|
4598
|
+
try {
|
|
4599
|
+
const res = await client().notes.search(query);
|
|
4600
|
+
if (maybeJson(res, opts.json)) return;
|
|
4601
|
+
if (!res.results.length) return info(`No matches for "${query}".`);
|
|
4602
|
+
table(
|
|
4603
|
+
res.results.map((r2) => [
|
|
4604
|
+
c2.dim(r2.id),
|
|
4605
|
+
c2.bold(r2.title || c2.dim("(untitled)")),
|
|
4606
|
+
c2.dim(relativeTime(r2.datetime))
|
|
4607
|
+
])
|
|
4608
|
+
);
|
|
4609
|
+
} catch (err) {
|
|
4610
|
+
fail(err);
|
|
4611
|
+
}
|
|
4612
|
+
});
|
|
4613
|
+
program3.command("view <id>").description("Print a note as markdown").option("--json", "output raw JSON").action(async (id, opts) => {
|
|
4614
|
+
try {
|
|
4615
|
+
const ork = client();
|
|
4616
|
+
if (opts.json) {
|
|
4617
|
+
return console.log(JSON.stringify(await ork.notes.get(id), null, 2));
|
|
4618
|
+
}
|
|
4619
|
+
const { title, markdown } = await ork.markdown.getNote(id);
|
|
4620
|
+
if (title) info(c2.bold(`# ${title}
|
|
4621
|
+
`));
|
|
4622
|
+
info(markdown);
|
|
4623
|
+
} catch (err) {
|
|
4624
|
+
fail(err);
|
|
4625
|
+
}
|
|
4626
|
+
});
|
|
4627
|
+
program3.command("edit <id>").description("Edit a note in $EDITOR (replaces its body)").action(async (id) => {
|
|
4628
|
+
try {
|
|
4629
|
+
const ork = client();
|
|
4630
|
+
const current = await ork.notes.get(id);
|
|
4631
|
+
const seeded = ork.markdown.fromBlocks(current.note.blocks);
|
|
4632
|
+
const edited = await openEditor(seeded);
|
|
4633
|
+
if (edited.trim() === seeded.trim()) return info("No changes.");
|
|
4634
|
+
const newBlocks = ork.markdown.toBlocks(edited);
|
|
4635
|
+
const blockChanges = [
|
|
4636
|
+
...current.note.blocks.map((b3) => ({
|
|
4637
|
+
operation: "delete",
|
|
4638
|
+
blockId: b3.id
|
|
4639
|
+
})),
|
|
4640
|
+
...newBlocks.map((b3) => ({
|
|
4641
|
+
operation: "create",
|
|
4642
|
+
blockType: b3.blockType,
|
|
4643
|
+
content: b3.content,
|
|
4644
|
+
position: b3.position
|
|
4645
|
+
}))
|
|
4646
|
+
];
|
|
4647
|
+
await ork.notes.update(id, { title: current.note.title, blockChanges });
|
|
4648
|
+
ok("Note updated.");
|
|
4649
|
+
} catch (err) {
|
|
4650
|
+
fail(err);
|
|
4651
|
+
}
|
|
4652
|
+
});
|
|
4653
|
+
program3.command("rm <id>").description("Delete a note").option("-y, --yes", "skip confirmation").action(async (id, opts) => {
|
|
4654
|
+
try {
|
|
4655
|
+
if (!opts.yes) {
|
|
4656
|
+
const confirmed = await se({ message: `Delete note ${id}?` });
|
|
4657
|
+
if (lD(confirmed) || !confirmed) return info("Cancelled.");
|
|
4658
|
+
}
|
|
4659
|
+
await client().notes.delete(id);
|
|
4660
|
+
ok("Note deleted.");
|
|
4661
|
+
} catch (err) {
|
|
4662
|
+
fail(err);
|
|
4663
|
+
}
|
|
4664
|
+
});
|
|
4665
|
+
program3.command("publish <id>").description("Publish a note and print its public URL").action(async (id) => {
|
|
4666
|
+
try {
|
|
4667
|
+
const res = await client().notes.publish(id);
|
|
4668
|
+
ok("Published.");
|
|
4669
|
+
info(c2.cyan(res.publicUrl));
|
|
4670
|
+
} catch (err) {
|
|
4671
|
+
fail(err);
|
|
4672
|
+
}
|
|
4673
|
+
});
|
|
4674
|
+
program3.command("unpublish <id>").description("Unpublish a note").action(async (id) => {
|
|
4675
|
+
try {
|
|
4676
|
+
await client().notes.unpublish(id);
|
|
4677
|
+
ok("Unpublished.");
|
|
4678
|
+
} catch (err) {
|
|
4679
|
+
fail(err);
|
|
4680
|
+
}
|
|
4681
|
+
});
|
|
4682
|
+
program3.command("pin <id>").description("Pin a note").action(async (id) => {
|
|
4683
|
+
try {
|
|
4684
|
+
await client().notes.pin(id);
|
|
4685
|
+
ok("Pinned.");
|
|
4686
|
+
} catch (err) {
|
|
4687
|
+
fail(err);
|
|
4688
|
+
}
|
|
4689
|
+
});
|
|
4690
|
+
program3.command("unpin <id>").description("Unpin a note").action(async (id) => {
|
|
4691
|
+
try {
|
|
4692
|
+
await client().notes.unpin(id);
|
|
4693
|
+
ok("Unpinned.");
|
|
4694
|
+
} catch (err) {
|
|
4695
|
+
fail(err);
|
|
4696
|
+
}
|
|
4697
|
+
});
|
|
4698
|
+
}
|
|
4699
|
+
|
|
4700
|
+
// src/commands/tags.ts
|
|
4701
|
+
function registerTagCommands(program3) {
|
|
4702
|
+
const tag = program3.command("tag").description("Manage tags");
|
|
4703
|
+
tag.command("ls").description("List your tags").option("--json", "output raw JSON").action(async (opts) => {
|
|
4704
|
+
try {
|
|
4705
|
+
const res = await client().tags.list({ pageSize: 100 });
|
|
4706
|
+
if (maybeJson(res, opts.json)) return;
|
|
4707
|
+
if (!res.tags.length) return info("No tags yet.");
|
|
4708
|
+
table(
|
|
4709
|
+
res.tags.map((t) => [
|
|
4710
|
+
c2.dim(t.id),
|
|
4711
|
+
`${t.icon} ${c2.bold(t.name)}`,
|
|
4712
|
+
t.noteCount != null ? c2.dim(`${t.noteCount} notes`) : ""
|
|
4713
|
+
])
|
|
4714
|
+
);
|
|
4715
|
+
} catch (err) {
|
|
4716
|
+
fail(err);
|
|
4717
|
+
}
|
|
4718
|
+
});
|
|
4719
|
+
tag.command("new <name>").description("Create a tag").option("-i, --icon <icon>", "emoji/icon", "\u{1F3F7}\uFE0F").option("-c, --color <hex>", "hex color", "#6366f1").action(async (name, opts) => {
|
|
4720
|
+
try {
|
|
4721
|
+
const res = await client().tags.create({
|
|
4722
|
+
name,
|
|
4723
|
+
icon: opts.icon,
|
|
4724
|
+
color: opts.color
|
|
4725
|
+
});
|
|
4726
|
+
ok(`Created tag ${res.tag.icon} ${c2.bold(res.tag.name)} ${c2.dim(res.tag.id)}`);
|
|
4727
|
+
} catch (err) {
|
|
4728
|
+
fail(err);
|
|
4729
|
+
}
|
|
4730
|
+
});
|
|
4731
|
+
tag.command("rm <id>").description("Delete a tag").action(async (id) => {
|
|
4732
|
+
try {
|
|
4733
|
+
await client().tags.delete(id);
|
|
4734
|
+
ok("Tag deleted.");
|
|
4735
|
+
} catch (err) {
|
|
4736
|
+
fail(err);
|
|
4737
|
+
}
|
|
4738
|
+
});
|
|
4739
|
+
tag.command("add <noteId> <name...>").description("Attach tags to a note (creating any that don't exist)").action(async (noteId, names) => {
|
|
4740
|
+
try {
|
|
4741
|
+
const ork = client();
|
|
4742
|
+
const ids = await resolveTagIds(ork, names);
|
|
4743
|
+
if (!ids.length) return info("No tags to add.");
|
|
4744
|
+
await ork.notes.addTags(noteId, ids);
|
|
4745
|
+
ok(`Added ${ids.length} tag(s) to ${noteId}.`);
|
|
4746
|
+
} catch (err) {
|
|
4747
|
+
fail(err);
|
|
4748
|
+
}
|
|
4749
|
+
});
|
|
4750
|
+
tag.command("remove <noteId> <tagId>").description("Remove a tag from a note").action(async (noteId, tagId) => {
|
|
4751
|
+
try {
|
|
4752
|
+
await client().notes.removeTag(noteId, tagId);
|
|
4753
|
+
ok("Tag removed.");
|
|
4754
|
+
} catch (err) {
|
|
4755
|
+
fail(err);
|
|
4756
|
+
}
|
|
4757
|
+
});
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
// src/commands/collections.ts
|
|
4761
|
+
function registerCollectionCommands(program3) {
|
|
4762
|
+
const col = program3.command("collection").alias("col").description("Manage collections");
|
|
4763
|
+
col.command("ls").description("List your collections").option("--json", "output raw JSON").action(async (opts) => {
|
|
4764
|
+
try {
|
|
4765
|
+
const res = await client().collections.list({ pageSize: 100 });
|
|
4766
|
+
if (maybeJson(res, opts.json)) return;
|
|
4767
|
+
if (!res.collections.length) return info("No collections yet.");
|
|
4768
|
+
table(
|
|
4769
|
+
res.collections.map((cl) => [
|
|
4770
|
+
c2.dim(cl.id),
|
|
4771
|
+
c2.bold(cl.name),
|
|
4772
|
+
cl.noteCount != null ? c2.dim(`${cl.noteCount} notes`) : "",
|
|
4773
|
+
cl.publishedAt ? c2.green("published") : c2.dim("private")
|
|
4774
|
+
])
|
|
4775
|
+
);
|
|
4776
|
+
} catch (err) {
|
|
4777
|
+
fail(err);
|
|
4778
|
+
}
|
|
4779
|
+
});
|
|
4780
|
+
col.command("new <name>").description("Create a collection").option("-d, --description <text>", "collection description").action(async (name, opts) => {
|
|
4781
|
+
try {
|
|
4782
|
+
const res = await client().collections.create({
|
|
4783
|
+
name,
|
|
4784
|
+
description: opts.description ?? null
|
|
4785
|
+
});
|
|
4786
|
+
ok(`Created collection ${c2.bold(res.collection.name)} ${c2.dim(res.collection.id)}`);
|
|
4787
|
+
} catch (err) {
|
|
4788
|
+
fail(err);
|
|
4789
|
+
}
|
|
4790
|
+
});
|
|
4791
|
+
col.command("rm <id>").description("Delete a collection").action(async (id) => {
|
|
4792
|
+
try {
|
|
4793
|
+
await client().collections.delete(id);
|
|
4794
|
+
ok("Collection deleted.");
|
|
4795
|
+
} catch (err) {
|
|
4796
|
+
fail(err);
|
|
4797
|
+
}
|
|
4798
|
+
});
|
|
4799
|
+
col.command("add <collectionId> <noteId...>").description("Add notes to a collection").action(async (collectionId, noteIds) => {
|
|
4800
|
+
try {
|
|
4801
|
+
await client().collections.addNotes(collectionId, { noteIds });
|
|
4802
|
+
ok(`Added ${noteIds.length} note(s) to ${collectionId}.`);
|
|
4803
|
+
} catch (err) {
|
|
4804
|
+
fail(err);
|
|
4805
|
+
}
|
|
4806
|
+
});
|
|
4807
|
+
col.command("remove <collectionId> <noteId>").description("Remove a note from a collection").action(async (collectionId, noteId) => {
|
|
4808
|
+
try {
|
|
4809
|
+
await client().collections.removeNote(collectionId, noteId);
|
|
4810
|
+
ok("Note removed from collection.");
|
|
4811
|
+
} catch (err) {
|
|
4812
|
+
fail(err);
|
|
4813
|
+
}
|
|
4814
|
+
});
|
|
4815
|
+
col.command("publish <id>").description("Publish a collection (needs a slug if it doesn't have one)").option("-s, --slug <slug>", "public slug (lowercase, hyphens)").action(async (id, opts) => {
|
|
4816
|
+
try {
|
|
4817
|
+
const res = await client().collections.publish(
|
|
4818
|
+
id,
|
|
4819
|
+
opts.slug ? { slug: opts.slug } : {}
|
|
4820
|
+
);
|
|
4821
|
+
ok("Collection published.");
|
|
4822
|
+
if (res.collection?.slug) {
|
|
4823
|
+
info(c2.cyan(`${webUrl()}/collection/${res.collection.slug}`));
|
|
4824
|
+
}
|
|
4825
|
+
} catch (err) {
|
|
4826
|
+
fail(err);
|
|
4827
|
+
}
|
|
4828
|
+
});
|
|
4829
|
+
col.command("unpublish <id>").description("Unpublish a collection").action(async (id) => {
|
|
4830
|
+
try {
|
|
4831
|
+
await client().collections.unpublish(id);
|
|
4832
|
+
ok("Collection unpublished.");
|
|
4833
|
+
} catch (err) {
|
|
4834
|
+
fail(err);
|
|
4835
|
+
}
|
|
4836
|
+
});
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4839
|
+
// src/commands/tokens.ts
|
|
4840
|
+
function registerTokenCommands(program3) {
|
|
4841
|
+
const token = program3.command("token").description("Manage scoped API keys (for agents / MCP / CI)");
|
|
4842
|
+
token.command("create [name]").description("Create an API key (printed once)").option("-e, --expires-in <seconds>", "expiry in seconds (default: never)").option("--json", "output raw JSON").action(async (name, opts) => {
|
|
4843
|
+
try {
|
|
4844
|
+
const created = await client().apiKeys.create({
|
|
4845
|
+
name: name ?? "cli",
|
|
4846
|
+
expiresIn: opts.expiresIn ? Number(opts.expiresIn) : null
|
|
4847
|
+
});
|
|
4848
|
+
if (maybeJson(created, opts.json)) return;
|
|
4849
|
+
ok(`Created API key "${created.name ?? "cli"}"`);
|
|
4850
|
+
info(`
|
|
4851
|
+
${c2.bold(c2.green(created.key))}
|
|
4852
|
+
`);
|
|
4853
|
+
info(c2.dim("Shown once \u2014 store it now. Use it as ORK_API_KEY, e.g.:"));
|
|
4854
|
+
info(c2.dim(` ORK_API_KEY=${created.key} ork-mcp`));
|
|
4855
|
+
} catch (err) {
|
|
4856
|
+
fail(err);
|
|
4857
|
+
}
|
|
4858
|
+
});
|
|
4859
|
+
token.command("ls").description("List your API keys").option("--json", "output raw JSON").action(async (opts) => {
|
|
4860
|
+
try {
|
|
4861
|
+
const keys = await client().apiKeys.list();
|
|
4862
|
+
if (maybeJson(keys, opts.json)) return;
|
|
4863
|
+
if (!keys.length) return info("No API keys.");
|
|
4864
|
+
table(
|
|
4865
|
+
keys.map((k2) => [
|
|
4866
|
+
c2.dim(k2.id),
|
|
4867
|
+
c2.bold(k2.name || "(unnamed)"),
|
|
4868
|
+
k2.enabled ? c2.green("enabled") : c2.red("disabled"),
|
|
4869
|
+
k2.lastRequest ? c2.dim(`used ${relativeTime(k2.lastRequest)}`) : c2.dim("never used")
|
|
4870
|
+
])
|
|
4871
|
+
);
|
|
4872
|
+
} catch (err) {
|
|
4873
|
+
fail(err);
|
|
4874
|
+
}
|
|
4875
|
+
});
|
|
4876
|
+
token.command("revoke <id>").description("Revoke (delete) an API key").action(async (id) => {
|
|
4877
|
+
try {
|
|
4878
|
+
await client().apiKeys.delete(id);
|
|
4879
|
+
ok("API key revoked.");
|
|
4880
|
+
} catch (err) {
|
|
4881
|
+
fail(err);
|
|
4882
|
+
}
|
|
4883
|
+
});
|
|
4884
|
+
}
|
|
4885
|
+
|
|
4886
|
+
// src/index.ts
|
|
4887
|
+
var program2 = new Command();
|
|
4888
|
+
program2.name("ork").description("Ork from the command line \u2014 write, search, and manage notes.").version("1.0.0").showHelpAfterError();
|
|
4889
|
+
registerAuthCommands(program2);
|
|
4890
|
+
registerNoteCommands(program2);
|
|
4891
|
+
registerTagCommands(program2);
|
|
4892
|
+
registerCollectionCommands(program2);
|
|
4893
|
+
registerTokenCommands(program2);
|
|
4894
|
+
program2.parseAsync().catch((err) => {
|
|
4895
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
4896
|
+
process.exit(1);
|
|
4897
|
+
});
|