ya-git-jira 1.3.0 → 1.5.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/bin/git-bump.ts +7 -4
- package/bin/{git-jira-issues.ts → git-jira-issue-list.ts} +10 -7
- package/bin/git-jira-issue-show.ts +40 -0
- package/bin/git-jira-issue.ts +14 -25
- package/bin/git-jira-start.ts +8 -5
- package/bin/git-jira.ts +9 -6
- package/bin/git-lab-group-list.ts +35 -0
- package/bin/git-lab-group.ts +25 -0
- package/bin/git-lab-merge-active.ts +41 -0
- package/bin/git-lab-merge-todo.ts +36 -0
- package/bin/git-lab-merge-train-list.ts +26 -0
- package/bin/git-lab-merge-train.ts +25 -0
- package/bin/git-lab-merge.ts +29 -0
- package/bin/git-lab-namespace-list.ts +27 -0
- package/bin/git-lab-namespace.ts +24 -0
- package/bin/{git-lab-projects.ts → git-lab-project-list.ts} +13 -10
- package/bin/git-lab-project-pipeline-list.ts +46 -0
- package/bin/git-lab-project-pipeline.ts +24 -0
- package/bin/git-lab-project-whereami.ts +43 -0
- package/bin/git-lab-project.ts +28 -0
- package/bin/git-lab-whoami.ts +8 -5
- package/bin/git-lab.ts +18 -8
- package/bin/gitj.ts +7 -5
- package/build.ts +1 -1
- package/bun.lockb +0 -0
- package/dist/bin/git-bump.js +55 -17
- package/dist/bin/{git-jira-issues.js → git-jira-issue-list.js} +71 -28
- package/dist/bin/{git-lab-mergetrain.js → git-jira-issue-show.js} +100 -43
- package/dist/bin/git-jira-issue.js +106 -33
- package/dist/bin/git-jira-start.js +70 -27
- package/dist/bin/git-jira.js +117 -59
- package/dist/bin/git-lab-group-list.js +2793 -0
- package/dist/bin/git-lab-group.js +2805 -0
- package/dist/bin/git-lab-groups.js +1992 -0
- package/dist/bin/git-lab-merge-active.js +2798 -0
- package/dist/bin/git-lab-merge-todo.js +2793 -0
- package/dist/bin/git-lab-merge-train-list.js +2754 -0
- package/dist/bin/git-lab-merge-train.js +2766 -0
- package/dist/bin/git-lab-merge.js +2865 -0
- package/dist/bin/git-lab-namespace-list.js +1967 -0
- package/dist/bin/git-lab-namespace.js +1979 -0
- package/dist/bin/git-lab-namespaces.js +1984 -0
- package/dist/bin/git-lab-project-list.js +2761 -0
- package/dist/bin/git-lab-project-pipeline-list.js +2800 -0
- package/dist/bin/git-lab-project-pipeline.js +2812 -0
- package/dist/bin/git-lab-project-whereami.js +2764 -0
- package/dist/bin/git-lab-project.js +2805 -0
- package/dist/bin/git-lab-projects-list.js +1996 -0
- package/dist/bin/git-lab-projects-whereami.js +1999 -0
- package/dist/bin/git-lab-projects.js +138 -35
- package/dist/bin/git-lab-whoami.js +100 -56
- package/dist/bin/git-lab.js +1123 -58
- package/dist/bin/gitj.js +1260 -172
- package/dist/index.js +881 -35
- package/index.ts +1 -1
- package/lib/gitlab/api.ts +46 -0
- package/lib/gitlab/config.ts +21 -0
- package/lib/gitlab/dlog.ts +2 -0
- package/lib/gitlab/group.ts +12 -0
- package/lib/gitlab/index.ts +8 -0
- package/lib/gitlab/merge-request.ts +31 -0
- package/lib/gitlab/merge-trains.ts +19 -0
- package/lib/gitlab/namespace.ts +12 -0
- package/lib/gitlab/pipeline.ts +32 -0
- package/lib/gitlab/project.ts +78 -0
- package/lib/gitlab/user.ts +13 -0
- package/lib/is_main.ts +21 -2
- package/lib/jira.ts +12 -7
- package/lib/package.ts +35 -0
- package/package.json +21 -4
- package/tests/all-help.test.ts +46 -0
- package/tests/git.test.ts +8 -7
- package/tests/gitj.test.ts +1 -1
- package/lib/gitlab.ts +0 -86
|
@@ -0,0 +1,2793 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
20
|
+
var __require = (id) => {
|
|
21
|
+
return import.meta.require(id);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// bine_modules/commander/lib/suggestS
|
|
25
|
+
var require_error = __commonJS((exports) => {
|
|
26
|
+
class CommanderError extends Error {
|
|
27
|
+
constructor(exitCode, code, message) {
|
|
28
|
+
super(message);
|
|
29
|
+
Error.captureStackTrace(this, this.constructor);
|
|
30
|
+
this.name = this.constructor.name;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.exitCode = exitCode;
|
|
33
|
+
this.nestedError = undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class InvalidArgumentError extends CommanderError {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(1, "commander.invalidArgument", message);
|
|
40
|
+
Error.captureStackTrace(this, this.constructor);
|
|
41
|
+
this.name = this.constructor.name;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.CommanderError = CommanderError;
|
|
45
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// bine_modules/commander/lib/suggestSimi
|
|
49
|
+
var require_argument = __commonJS((exports) => {
|
|
50
|
+
var humanReadableArgName = function(arg) {
|
|
51
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
52
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
53
|
+
};
|
|
54
|
+
var { InvalidArgumentError } = require_error();
|
|
55
|
+
|
|
56
|
+
class Argument {
|
|
57
|
+
constructor(name, description) {
|
|
58
|
+
this.description = description || "";
|
|
59
|
+
this.variadic = false;
|
|
60
|
+
this.parseArg = undefined;
|
|
61
|
+
this.defaultValue = undefined;
|
|
62
|
+
this.defaultValueDescription = undefined;
|
|
63
|
+
this.argChoices = undefined;
|
|
64
|
+
switch (name[0]) {
|
|
65
|
+
case "<":
|
|
66
|
+
this.required = true;
|
|
67
|
+
this._name = name.slice(1, -1);
|
|
68
|
+
break;
|
|
69
|
+
case "[":
|
|
70
|
+
this.required = false;
|
|
71
|
+
this._name = name.slice(1, -1);
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
this.required = true;
|
|
75
|
+
this._name = name;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
79
|
+
this.variadic = true;
|
|
80
|
+
this._name = this._name.slice(0, -3);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
name() {
|
|
84
|
+
return this._name;
|
|
85
|
+
}
|
|
86
|
+
_concatValue(value, previous) {
|
|
87
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
88
|
+
return [value];
|
|
89
|
+
}
|
|
90
|
+
return previous.concat(value);
|
|
91
|
+
}
|
|
92
|
+
default(value, description) {
|
|
93
|
+
this.defaultValue = value;
|
|
94
|
+
this.defaultValueDescription = description;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
argParser(fn) {
|
|
98
|
+
this.parseArg = fn;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
choices(values) {
|
|
102
|
+
this.argChoices = values.slice();
|
|
103
|
+
this.parseArg = (arg, previous) => {
|
|
104
|
+
if (!this.argChoices.includes(arg)) {
|
|
105
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
106
|
+
}
|
|
107
|
+
if (this.variadic) {
|
|
108
|
+
return this._concatValue(arg, previous);
|
|
109
|
+
}
|
|
110
|
+
return arg;
|
|
111
|
+
};
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
argRequired() {
|
|
115
|
+
this.required = true;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
argOptional() {
|
|
119
|
+
this.required = false;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.Argument = Argument;
|
|
124
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// bine_modules/commander/lib/suggest
|
|
128
|
+
var require_help = __commonJS((exports) => {
|
|
129
|
+
var { humanReadableArgName } = require_argument();
|
|
130
|
+
|
|
131
|
+
class Help {
|
|
132
|
+
constructor() {
|
|
133
|
+
this.helpWidth = undefined;
|
|
134
|
+
this.sortSubcommands = false;
|
|
135
|
+
this.sortOptions = false;
|
|
136
|
+
this.showGlobalOptions = false;
|
|
137
|
+
}
|
|
138
|
+
visibleCommands(cmd) {
|
|
139
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
140
|
+
if (cmd._hasImplicitHelpCommand()) {
|
|
141
|
+
const [, helpName, helpArgs] = cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/);
|
|
142
|
+
const helpCommand = cmd.createCommand(helpName).helpOption(false);
|
|
143
|
+
helpCommand.description(cmd._helpCommandDescription);
|
|
144
|
+
if (helpArgs)
|
|
145
|
+
helpCommand.arguments(helpArgs);
|
|
146
|
+
visibleCommands.push(helpCommand);
|
|
147
|
+
}
|
|
148
|
+
if (this.sortSubcommands) {
|
|
149
|
+
visibleCommands.sort((a, b) => {
|
|
150
|
+
return a.name().localeCompare(b.name());
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return visibleCommands;
|
|
154
|
+
}
|
|
155
|
+
compareOptions(a, b) {
|
|
156
|
+
const getSortKey = (option) => {
|
|
157
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
158
|
+
};
|
|
159
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
160
|
+
}
|
|
161
|
+
visibleOptions(cmd) {
|
|
162
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
163
|
+
const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
|
|
164
|
+
const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
|
|
165
|
+
if (showShortHelpFlag || showLongHelpFlag) {
|
|
166
|
+
let helpOption;
|
|
167
|
+
if (!showShortHelpFlag) {
|
|
168
|
+
helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
|
|
169
|
+
} else if (!showLongHelpFlag) {
|
|
170
|
+
helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
|
|
171
|
+
} else {
|
|
172
|
+
helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
|
|
173
|
+
}
|
|
174
|
+
visibleOptions.push(helpOption);
|
|
175
|
+
}
|
|
176
|
+
if (this.sortOptions) {
|
|
177
|
+
visibleOptions.sort(this.compareOptions);
|
|
178
|
+
}
|
|
179
|
+
return visibleOptions;
|
|
180
|
+
}
|
|
181
|
+
visibleGlobalOptions(cmd) {
|
|
182
|
+
if (!this.showGlobalOptions)
|
|
183
|
+
return [];
|
|
184
|
+
const globalOptions = [];
|
|
185
|
+
for (let parentCmd = cmd.parent;parentCmd; parentCmd = parentCmd.parent) {
|
|
186
|
+
const visibleOptions = parentCmd.options.filter((option) => !option.hidden);
|
|
187
|
+
globalOptions.push(...visibleOptions);
|
|
188
|
+
}
|
|
189
|
+
if (this.sortOptions) {
|
|
190
|
+
globalOptions.sort(this.compareOptions);
|
|
191
|
+
}
|
|
192
|
+
return globalOptions;
|
|
193
|
+
}
|
|
194
|
+
visibleArguments(cmd) {
|
|
195
|
+
if (cmd._argsDescription) {
|
|
196
|
+
cmd._args.forEach((argument) => {
|
|
197
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (cmd._args.find((argument) => argument.description)) {
|
|
201
|
+
return cmd._args;
|
|
202
|
+
}
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
subcommandTerm(cmd) {
|
|
206
|
+
const args = cmd._args.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
207
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
208
|
+
}
|
|
209
|
+
optionTerm(option) {
|
|
210
|
+
return option.flags;
|
|
211
|
+
}
|
|
212
|
+
argumentTerm(argument) {
|
|
213
|
+
return argument.name();
|
|
214
|
+
}
|
|
215
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
216
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
217
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
218
|
+
}, 0);
|
|
219
|
+
}
|
|
220
|
+
longestOptionTermLength(cmd, helper) {
|
|
221
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
222
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
223
|
+
}, 0);
|
|
224
|
+
}
|
|
225
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
226
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
227
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
228
|
+
}, 0);
|
|
229
|
+
}
|
|
230
|
+
longestArgumentTermLength(cmd, helper) {
|
|
231
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
232
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
233
|
+
}, 0);
|
|
234
|
+
}
|
|
235
|
+
commandUsage(cmd) {
|
|
236
|
+
let cmdName = cmd._name;
|
|
237
|
+
if (cmd._aliases[0]) {
|
|
238
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
239
|
+
}
|
|
240
|
+
let parentCmdNames = "";
|
|
241
|
+
for (let parentCmd = cmd.parent;parentCmd; parentCmd = parentCmd.parent) {
|
|
242
|
+
parentCmdNames = parentCmd.name() + " " + parentCmdNames;
|
|
243
|
+
}
|
|
244
|
+
return parentCmdNames + cmdName + " " + cmd.usage();
|
|
245
|
+
}
|
|
246
|
+
commandDescription(cmd) {
|
|
247
|
+
return cmd.description();
|
|
248
|
+
}
|
|
249
|
+
subcommandDescription(cmd) {
|
|
250
|
+
return cmd.summary() || cmd.description();
|
|
251
|
+
}
|
|
252
|
+
optionDescription(option) {
|
|
253
|
+
const extraInfo = [];
|
|
254
|
+
if (option.argChoices) {
|
|
255
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
256
|
+
}
|
|
257
|
+
if (option.defaultValue !== undefined) {
|
|
258
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
259
|
+
if (showDefault) {
|
|
260
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
264
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
265
|
+
}
|
|
266
|
+
if (option.envVar !== undefined) {
|
|
267
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
268
|
+
}
|
|
269
|
+
if (extraInfo.length > 0) {
|
|
270
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
271
|
+
}
|
|
272
|
+
return option.description;
|
|
273
|
+
}
|
|
274
|
+
argumentDescription(argument) {
|
|
275
|
+
const extraInfo = [];
|
|
276
|
+
if (argument.argChoices) {
|
|
277
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
278
|
+
}
|
|
279
|
+
if (argument.defaultValue !== undefined) {
|
|
280
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
281
|
+
}
|
|
282
|
+
if (extraInfo.length > 0) {
|
|
283
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
284
|
+
if (argument.description) {
|
|
285
|
+
return `${argument.description} ${extraDescripton}`;
|
|
286
|
+
}
|
|
287
|
+
return extraDescripton;
|
|
288
|
+
}
|
|
289
|
+
return argument.description;
|
|
290
|
+
}
|
|
291
|
+
formatHelp(cmd, helper) {
|
|
292
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
293
|
+
const helpWidth = helper.helpWidth || 80;
|
|
294
|
+
const itemIndentWidth = 2;
|
|
295
|
+
const itemSeparatorWidth = 2;
|
|
296
|
+
function formatItem(term, description) {
|
|
297
|
+
if (description) {
|
|
298
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
299
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
300
|
+
}
|
|
301
|
+
return term;
|
|
302
|
+
}
|
|
303
|
+
function formatList(textArray) {
|
|
304
|
+
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
305
|
+
}
|
|
306
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
307
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
308
|
+
if (commandDescription.length > 0) {
|
|
309
|
+
output = output.concat([helper.wrap(commandDescription, helpWidth, 0), ""]);
|
|
310
|
+
}
|
|
311
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
312
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
313
|
+
});
|
|
314
|
+
if (argumentList.length > 0) {
|
|
315
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
316
|
+
}
|
|
317
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
318
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
319
|
+
});
|
|
320
|
+
if (optionList.length > 0) {
|
|
321
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
322
|
+
}
|
|
323
|
+
if (this.showGlobalOptions) {
|
|
324
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
325
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
326
|
+
});
|
|
327
|
+
if (globalOptionList.length > 0) {
|
|
328
|
+
output = output.concat(["Global Options:", formatList(globalOptionList), ""]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
332
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
333
|
+
});
|
|
334
|
+
if (commandList.length > 0) {
|
|
335
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
336
|
+
}
|
|
337
|
+
return output.join("\n");
|
|
338
|
+
}
|
|
339
|
+
padWidth(cmd, helper) {
|
|
340
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
341
|
+
}
|
|
342
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
343
|
+
const indents = " \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF";
|
|
344
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
345
|
+
if (str.match(manualIndent))
|
|
346
|
+
return str;
|
|
347
|
+
const columnWidth = width - indent;
|
|
348
|
+
if (columnWidth < minColumnWidth)
|
|
349
|
+
return str;
|
|
350
|
+
const leadingStr = str.slice(0, indent);
|
|
351
|
+
const columnText = str.slice(indent).replace("\r\n", "\n");
|
|
352
|
+
const indentString = " ".repeat(indent);
|
|
353
|
+
const zeroWidthSpace = "\u200B";
|
|
354
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
355
|
+
const regex = new RegExp(`\n|.{1,${columnWidth - 1}}([${breaks}]|\$)|[^${breaks}]+?([${breaks}]|\$)`, "g");
|
|
356
|
+
const lines = columnText.match(regex) || [];
|
|
357
|
+
return leadingStr + lines.map((line, i) => {
|
|
358
|
+
if (line === "\n")
|
|
359
|
+
return "";
|
|
360
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
361
|
+
}).join("\n");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.Help = Help;
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// bine_modules/commander/lib/suggestSi
|
|
368
|
+
var require_option = __commonJS((exports) => {
|
|
369
|
+
var camelcase = function(str) {
|
|
370
|
+
return str.split("-").reduce((str2, word) => {
|
|
371
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
var splitOptionFlags = function(flags) {
|
|
375
|
+
let shortFlag;
|
|
376
|
+
let longFlag;
|
|
377
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
378
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
379
|
+
shortFlag = flagParts.shift();
|
|
380
|
+
longFlag = flagParts.shift();
|
|
381
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
382
|
+
shortFlag = longFlag;
|
|
383
|
+
longFlag = undefined;
|
|
384
|
+
}
|
|
385
|
+
return { shortFlag, longFlag };
|
|
386
|
+
};
|
|
387
|
+
var { InvalidArgumentError } = require_error();
|
|
388
|
+
|
|
389
|
+
class Option {
|
|
390
|
+
constructor(flags, description) {
|
|
391
|
+
this.flags = flags;
|
|
392
|
+
this.description = description || "";
|
|
393
|
+
this.required = flags.includes("<");
|
|
394
|
+
this.optional = flags.includes("[");
|
|
395
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
396
|
+
this.mandatory = false;
|
|
397
|
+
const optionFlags = splitOptionFlags(flags);
|
|
398
|
+
this.short = optionFlags.shortFlag;
|
|
399
|
+
this.long = optionFlags.longFlag;
|
|
400
|
+
this.negate = false;
|
|
401
|
+
if (this.long) {
|
|
402
|
+
this.negate = this.long.startsWith("--no-");
|
|
403
|
+
}
|
|
404
|
+
this.defaultValue = undefined;
|
|
405
|
+
this.defaultValueDescription = undefined;
|
|
406
|
+
this.presetArg = undefined;
|
|
407
|
+
this.envVar = undefined;
|
|
408
|
+
this.parseArg = undefined;
|
|
409
|
+
this.hidden = false;
|
|
410
|
+
this.argChoices = undefined;
|
|
411
|
+
this.conflictsWith = [];
|
|
412
|
+
this.implied = undefined;
|
|
413
|
+
}
|
|
414
|
+
default(value, description) {
|
|
415
|
+
this.defaultValue = value;
|
|
416
|
+
this.defaultValueDescription = description;
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
preset(arg) {
|
|
420
|
+
this.presetArg = arg;
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
conflicts(names) {
|
|
424
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
implies(impliedOptionValues) {
|
|
428
|
+
let newImplied = impliedOptionValues;
|
|
429
|
+
if (typeof impliedOptionValues === "string") {
|
|
430
|
+
newImplied = { [impliedOptionValues]: true };
|
|
431
|
+
}
|
|
432
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
env(name) {
|
|
436
|
+
this.envVar = name;
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
argParser(fn) {
|
|
440
|
+
this.parseArg = fn;
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
makeOptionMandatory(mandatory = true) {
|
|
444
|
+
this.mandatory = !!mandatory;
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
hideHelp(hide = true) {
|
|
448
|
+
this.hidden = !!hide;
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
_concatValue(value, previous) {
|
|
452
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
453
|
+
return [value];
|
|
454
|
+
}
|
|
455
|
+
return previous.concat(value);
|
|
456
|
+
}
|
|
457
|
+
choices(values) {
|
|
458
|
+
this.argChoices = values.slice();
|
|
459
|
+
this.parseArg = (arg, previous) => {
|
|
460
|
+
if (!this.argChoices.includes(arg)) {
|
|
461
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
462
|
+
}
|
|
463
|
+
if (this.variadic) {
|
|
464
|
+
return this._concatValue(arg, previous);
|
|
465
|
+
}
|
|
466
|
+
return arg;
|
|
467
|
+
};
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
name() {
|
|
471
|
+
if (this.long) {
|
|
472
|
+
return this.long.replace(/^--/, "");
|
|
473
|
+
}
|
|
474
|
+
return this.short.replace(/^-/, "");
|
|
475
|
+
}
|
|
476
|
+
attributeName() {
|
|
477
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
478
|
+
}
|
|
479
|
+
is(arg) {
|
|
480
|
+
return this.short === arg || this.long === arg;
|
|
481
|
+
}
|
|
482
|
+
isBoolean() {
|
|
483
|
+
return !this.required && !this.optional && !this.negate;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
class DualOptions {
|
|
488
|
+
constructor(options) {
|
|
489
|
+
this.positiveOptions = new Map;
|
|
490
|
+
this.negativeOptions = new Map;
|
|
491
|
+
this.dualOptions = new Set;
|
|
492
|
+
options.forEach((option) => {
|
|
493
|
+
if (option.negate) {
|
|
494
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
495
|
+
} else {
|
|
496
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
this.negativeOptions.forEach((value, key) => {
|
|
500
|
+
if (this.positiveOptions.has(key)) {
|
|
501
|
+
this.dualOptions.add(key);
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
valueFromOption(value, option) {
|
|
506
|
+
const optionKey = option.attributeName();
|
|
507
|
+
if (!this.dualOptions.has(optionKey))
|
|
508
|
+
return true;
|
|
509
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
510
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
511
|
+
return option.negate === (negativeValue === value);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
exports.Option = Option;
|
|
515
|
+
exports.splitOptionFlags = splitOptionFlags;
|
|
516
|
+
exports.DualOptions = DualOptions;
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// bine_modules/commander/lib/suggestSimilar.js
|
|
520
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
521
|
+
var editDistance = function(a, b) {
|
|
522
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
523
|
+
return Math.max(a.length, b.length);
|
|
524
|
+
const d = [];
|
|
525
|
+
for (let i = 0;i <= a.length; i++) {
|
|
526
|
+
d[i] = [i];
|
|
527
|
+
}
|
|
528
|
+
for (let j = 0;j <= b.length; j++) {
|
|
529
|
+
d[0][j] = j;
|
|
530
|
+
}
|
|
531
|
+
for (let j = 1;j <= b.length; j++) {
|
|
532
|
+
for (let i = 1;i <= a.length; i++) {
|
|
533
|
+
let cost = 1;
|
|
534
|
+
if (a[i - 1] === b[j - 1]) {
|
|
535
|
+
cost = 0;
|
|
536
|
+
} else {
|
|
537
|
+
cost = 1;
|
|
538
|
+
}
|
|
539
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
540
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
541
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return d[a.length][b.length];
|
|
546
|
+
};
|
|
547
|
+
var suggestSimilar = function(word, candidates) {
|
|
548
|
+
if (!candidates || candidates.length === 0)
|
|
549
|
+
return "";
|
|
550
|
+
candidates = Array.from(new Set(candidates));
|
|
551
|
+
const searchingOptions = word.startsWith("--");
|
|
552
|
+
if (searchingOptions) {
|
|
553
|
+
word = word.slice(2);
|
|
554
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
555
|
+
}
|
|
556
|
+
let similar = [];
|
|
557
|
+
let bestDistance = maxDistance;
|
|
558
|
+
const minSimilarity = 0.4;
|
|
559
|
+
candidates.forEach((candidate) => {
|
|
560
|
+
if (candidate.length <= 1)
|
|
561
|
+
return;
|
|
562
|
+
const distance = editDistance(word, candidate);
|
|
563
|
+
const length = Math.max(word.length, candidate.length);
|
|
564
|
+
const similarity = (length - distance) / length;
|
|
565
|
+
if (similarity > minSimilarity) {
|
|
566
|
+
if (distance < bestDistance) {
|
|
567
|
+
bestDistance = distance;
|
|
568
|
+
similar = [candidate];
|
|
569
|
+
} else if (distance === bestDistance) {
|
|
570
|
+
similar.push(candidate);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
575
|
+
if (searchingOptions) {
|
|
576
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
577
|
+
}
|
|
578
|
+
if (similar.length > 1) {
|
|
579
|
+
return `\n(Did you mean one of ${similar.join(", ")}?)`;
|
|
580
|
+
}
|
|
581
|
+
if (similar.length === 1) {
|
|
582
|
+
return `\n(Did you mean ${similar[0]}?)`;
|
|
583
|
+
}
|
|
584
|
+
return "";
|
|
585
|
+
};
|
|
586
|
+
var maxDistance = 3;
|
|
587
|
+
exports.suggestSimilar = suggestSimilar;
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
// bine_modules/commander/lib/suggestSim
|
|
591
|
+
var require_command = __commonJS((exports) => {
|
|
592
|
+
var outputHelpIfRequested = function(cmd, args) {
|
|
593
|
+
const helpOption = cmd._hasHelpOption && args.find((arg) => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
|
|
594
|
+
if (helpOption) {
|
|
595
|
+
cmd.outputHelp();
|
|
596
|
+
cmd._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
var incrementNodeInspectorPort = function(args) {
|
|
600
|
+
return args.map((arg) => {
|
|
601
|
+
if (!arg.startsWith("--inspect")) {
|
|
602
|
+
return arg;
|
|
603
|
+
}
|
|
604
|
+
let debugOption;
|
|
605
|
+
let debugHost = "127.0.0.1";
|
|
606
|
+
let debugPort = "9229";
|
|
607
|
+
let match;
|
|
608
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
609
|
+
debugOption = match[1];
|
|
610
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
611
|
+
debugOption = match[1];
|
|
612
|
+
if (/^\d+$/.test(match[3])) {
|
|
613
|
+
debugPort = match[3];
|
|
614
|
+
} else {
|
|
615
|
+
debugHost = match[3];
|
|
616
|
+
}
|
|
617
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
618
|
+
debugOption = match[1];
|
|
619
|
+
debugHost = match[3];
|
|
620
|
+
debugPort = match[4];
|
|
621
|
+
}
|
|
622
|
+
if (debugOption && debugPort !== "0") {
|
|
623
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
624
|
+
}
|
|
625
|
+
return arg;
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
var getCommandAndParents = function(startCommand) {
|
|
629
|
+
const result = [];
|
|
630
|
+
for (let command = startCommand;command; command = command.parent) {
|
|
631
|
+
result.push(command);
|
|
632
|
+
}
|
|
633
|
+
return result;
|
|
634
|
+
};
|
|
635
|
+
var EventEmitter = import.meta.require("events").EventEmitter;
|
|
636
|
+
var childProcess = import.meta.require("child_process");
|
|
637
|
+
var path = import.meta.require("path");
|
|
638
|
+
var fs = import.meta.require("fs");
|
|
639
|
+
var process2 = import.meta.require("process");
|
|
640
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
641
|
+
var { CommanderError } = require_error();
|
|
642
|
+
var { Help } = require_help();
|
|
643
|
+
var { Option, splitOptionFlags, DualOptions } = require_option();
|
|
644
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
645
|
+
|
|
646
|
+
class Command extends EventEmitter {
|
|
647
|
+
constructor(name) {
|
|
648
|
+
super();
|
|
649
|
+
this.commands = [];
|
|
650
|
+
this.options = [];
|
|
651
|
+
this.parent = null;
|
|
652
|
+
this._allowUnknownOption = false;
|
|
653
|
+
this._allowExcessArguments = true;
|
|
654
|
+
this._args = [];
|
|
655
|
+
this.args = [];
|
|
656
|
+
this.rawArgs = [];
|
|
657
|
+
this.processedArgs = [];
|
|
658
|
+
this._scriptPath = null;
|
|
659
|
+
this._name = name || "";
|
|
660
|
+
this._optionValues = {};
|
|
661
|
+
this._optionValueSources = {};
|
|
662
|
+
this._storeOptionsAsProperties = false;
|
|
663
|
+
this._actionHandler = null;
|
|
664
|
+
this._executableHandler = false;
|
|
665
|
+
this._executableFile = null;
|
|
666
|
+
this._executableDir = null;
|
|
667
|
+
this._defaultCommandName = null;
|
|
668
|
+
this._exitCallback = null;
|
|
669
|
+
this._aliases = [];
|
|
670
|
+
this._combineFlagAndOptionalValue = true;
|
|
671
|
+
this._description = "";
|
|
672
|
+
this._summary = "";
|
|
673
|
+
this._argsDescription = undefined;
|
|
674
|
+
this._enablePositionalOptions = false;
|
|
675
|
+
this._passThroughOptions = false;
|
|
676
|
+
this._lifeCycleHooks = {};
|
|
677
|
+
this._showHelpAfterError = false;
|
|
678
|
+
this._showSuggestionAfterError = true;
|
|
679
|
+
this._outputConfiguration = {
|
|
680
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
681
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
682
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
683
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
684
|
+
outputError: (str, write) => write(str)
|
|
685
|
+
};
|
|
686
|
+
this._hidden = false;
|
|
687
|
+
this._hasHelpOption = true;
|
|
688
|
+
this._helpFlags = "-h, --help";
|
|
689
|
+
this._helpDescription = "display help for command";
|
|
690
|
+
this._helpShortFlag = "-h";
|
|
691
|
+
this._helpLongFlag = "--help";
|
|
692
|
+
this._addImplicitHelpCommand = undefined;
|
|
693
|
+
this._helpCommandName = "help";
|
|
694
|
+
this._helpCommandnameAndArgs = "help [command]";
|
|
695
|
+
this._helpCommandDescription = "display help for command";
|
|
696
|
+
this._helpConfiguration = {};
|
|
697
|
+
}
|
|
698
|
+
copyInheritedSettings(sourceCommand) {
|
|
699
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
700
|
+
this._hasHelpOption = sourceCommand._hasHelpOption;
|
|
701
|
+
this._helpFlags = sourceCommand._helpFlags;
|
|
702
|
+
this._helpDescription = sourceCommand._helpDescription;
|
|
703
|
+
this._helpShortFlag = sourceCommand._helpShortFlag;
|
|
704
|
+
this._helpLongFlag = sourceCommand._helpLongFlag;
|
|
705
|
+
this._helpCommandName = sourceCommand._helpCommandName;
|
|
706
|
+
this._helpCommandnameAndArgs = sourceCommand._helpCommandnameAndArgs;
|
|
707
|
+
this._helpCommandDescription = sourceCommand._helpCommandDescription;
|
|
708
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
709
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
710
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
711
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
712
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
713
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
714
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
715
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
716
|
+
return this;
|
|
717
|
+
}
|
|
718
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
719
|
+
let desc = actionOptsOrExecDesc;
|
|
720
|
+
let opts = execOpts;
|
|
721
|
+
if (typeof desc === "object" && desc !== null) {
|
|
722
|
+
opts = desc;
|
|
723
|
+
desc = null;
|
|
724
|
+
}
|
|
725
|
+
opts = opts || {};
|
|
726
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
727
|
+
const cmd = this.createCommand(name);
|
|
728
|
+
if (desc) {
|
|
729
|
+
cmd.description(desc);
|
|
730
|
+
cmd._executableHandler = true;
|
|
731
|
+
}
|
|
732
|
+
if (opts.isDefault)
|
|
733
|
+
this._defaultCommandName = cmd._name;
|
|
734
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
735
|
+
cmd._executableFile = opts.executableFile || null;
|
|
736
|
+
if (args)
|
|
737
|
+
cmd.arguments(args);
|
|
738
|
+
this.commands.push(cmd);
|
|
739
|
+
cmd.parent = this;
|
|
740
|
+
cmd.copyInheritedSettings(this);
|
|
741
|
+
if (desc)
|
|
742
|
+
return this;
|
|
743
|
+
return cmd;
|
|
744
|
+
}
|
|
745
|
+
createCommand(name) {
|
|
746
|
+
return new Command(name);
|
|
747
|
+
}
|
|
748
|
+
createHelp() {
|
|
749
|
+
return Object.assign(new Help, this.configureHelp());
|
|
750
|
+
}
|
|
751
|
+
configureHelp(configuration) {
|
|
752
|
+
if (configuration === undefined)
|
|
753
|
+
return this._helpConfiguration;
|
|
754
|
+
this._helpConfiguration = configuration;
|
|
755
|
+
return this;
|
|
756
|
+
}
|
|
757
|
+
configureOutput(configuration) {
|
|
758
|
+
if (configuration === undefined)
|
|
759
|
+
return this._outputConfiguration;
|
|
760
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
761
|
+
return this;
|
|
762
|
+
}
|
|
763
|
+
showHelpAfterError(displayHelp = true) {
|
|
764
|
+
if (typeof displayHelp !== "string")
|
|
765
|
+
displayHelp = !!displayHelp;
|
|
766
|
+
this._showHelpAfterError = displayHelp;
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
770
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
771
|
+
return this;
|
|
772
|
+
}
|
|
773
|
+
addCommand(cmd, opts) {
|
|
774
|
+
if (!cmd._name) {
|
|
775
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
776
|
+
- specify the name in Command constructor or using .name()`);
|
|
777
|
+
}
|
|
778
|
+
opts = opts || {};
|
|
779
|
+
if (opts.isDefault)
|
|
780
|
+
this._defaultCommandName = cmd._name;
|
|
781
|
+
if (opts.noHelp || opts.hidden)
|
|
782
|
+
cmd._hidden = true;
|
|
783
|
+
this.commands.push(cmd);
|
|
784
|
+
cmd.parent = this;
|
|
785
|
+
return this;
|
|
786
|
+
}
|
|
787
|
+
createArgument(name, description) {
|
|
788
|
+
return new Argument(name, description);
|
|
789
|
+
}
|
|
790
|
+
argument(name, description, fn, defaultValue) {
|
|
791
|
+
const argument = this.createArgument(name, description);
|
|
792
|
+
if (typeof fn === "function") {
|
|
793
|
+
argument.default(defaultValue).argParser(fn);
|
|
794
|
+
} else {
|
|
795
|
+
argument.default(fn);
|
|
796
|
+
}
|
|
797
|
+
this.addArgument(argument);
|
|
798
|
+
return this;
|
|
799
|
+
}
|
|
800
|
+
arguments(names) {
|
|
801
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
802
|
+
this.argument(detail);
|
|
803
|
+
});
|
|
804
|
+
return this;
|
|
805
|
+
}
|
|
806
|
+
addArgument(argument) {
|
|
807
|
+
const previousArgument = this._args.slice(-1)[0];
|
|
808
|
+
if (previousArgument && previousArgument.variadic) {
|
|
809
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
810
|
+
}
|
|
811
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
812
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
813
|
+
}
|
|
814
|
+
this._args.push(argument);
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
addHelpCommand(enableOrNameAndArgs, description) {
|
|
818
|
+
if (enableOrNameAndArgs === false) {
|
|
819
|
+
this._addImplicitHelpCommand = false;
|
|
820
|
+
} else {
|
|
821
|
+
this._addImplicitHelpCommand = true;
|
|
822
|
+
if (typeof enableOrNameAndArgs === "string") {
|
|
823
|
+
this._helpCommandName = enableOrNameAndArgs.split(" ")[0];
|
|
824
|
+
this._helpCommandnameAndArgs = enableOrNameAndArgs;
|
|
825
|
+
}
|
|
826
|
+
this._helpCommandDescription = description || this._helpCommandDescription;
|
|
827
|
+
}
|
|
828
|
+
return this;
|
|
829
|
+
}
|
|
830
|
+
_hasImplicitHelpCommand() {
|
|
831
|
+
if (this._addImplicitHelpCommand === undefined) {
|
|
832
|
+
return this.commands.length && !this._actionHandler && !this._findCommand("help");
|
|
833
|
+
}
|
|
834
|
+
return this._addImplicitHelpCommand;
|
|
835
|
+
}
|
|
836
|
+
hook(event, listener) {
|
|
837
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
838
|
+
if (!allowedValues.includes(event)) {
|
|
839
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
840
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
841
|
+
}
|
|
842
|
+
if (this._lifeCycleHooks[event]) {
|
|
843
|
+
this._lifeCycleHooks[event].push(listener);
|
|
844
|
+
} else {
|
|
845
|
+
this._lifeCycleHooks[event] = [listener];
|
|
846
|
+
}
|
|
847
|
+
return this;
|
|
848
|
+
}
|
|
849
|
+
exitOverride(fn) {
|
|
850
|
+
if (fn) {
|
|
851
|
+
this._exitCallback = fn;
|
|
852
|
+
} else {
|
|
853
|
+
this._exitCallback = (err) => {
|
|
854
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
855
|
+
throw err;
|
|
856
|
+
} else {
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
return this;
|
|
861
|
+
}
|
|
862
|
+
_exit(exitCode, code, message) {
|
|
863
|
+
if (this._exitCallback) {
|
|
864
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
865
|
+
}
|
|
866
|
+
process2.exit(exitCode);
|
|
867
|
+
}
|
|
868
|
+
action(fn) {
|
|
869
|
+
const listener = (args) => {
|
|
870
|
+
const expectedArgsCount = this._args.length;
|
|
871
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
872
|
+
if (this._storeOptionsAsProperties) {
|
|
873
|
+
actionArgs[expectedArgsCount] = this;
|
|
874
|
+
} else {
|
|
875
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
876
|
+
}
|
|
877
|
+
actionArgs.push(this);
|
|
878
|
+
return fn.apply(this, actionArgs);
|
|
879
|
+
};
|
|
880
|
+
this._actionHandler = listener;
|
|
881
|
+
return this;
|
|
882
|
+
}
|
|
883
|
+
createOption(flags, description) {
|
|
884
|
+
return new Option(flags, description);
|
|
885
|
+
}
|
|
886
|
+
addOption(option) {
|
|
887
|
+
const oname = option.name();
|
|
888
|
+
const name = option.attributeName();
|
|
889
|
+
if (option.negate) {
|
|
890
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
891
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
892
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
893
|
+
}
|
|
894
|
+
} else if (option.defaultValue !== undefined) {
|
|
895
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
896
|
+
}
|
|
897
|
+
this.options.push(option);
|
|
898
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
899
|
+
if (val == null && option.presetArg !== undefined) {
|
|
900
|
+
val = option.presetArg;
|
|
901
|
+
}
|
|
902
|
+
const oldValue = this.getOptionValue(name);
|
|
903
|
+
if (val !== null && option.parseArg) {
|
|
904
|
+
try {
|
|
905
|
+
val = option.parseArg(val, oldValue);
|
|
906
|
+
} catch (err) {
|
|
907
|
+
if (err.code === "commander.invalidArgument") {
|
|
908
|
+
const message = `${invalidValueMessage} ${err.message}`;
|
|
909
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
910
|
+
}
|
|
911
|
+
throw err;
|
|
912
|
+
}
|
|
913
|
+
} else if (val !== null && option.variadic) {
|
|
914
|
+
val = option._concatValue(val, oldValue);
|
|
915
|
+
}
|
|
916
|
+
if (val == null) {
|
|
917
|
+
if (option.negate) {
|
|
918
|
+
val = false;
|
|
919
|
+
} else if (option.isBoolean() || option.optional) {
|
|
920
|
+
val = true;
|
|
921
|
+
} else {
|
|
922
|
+
val = "";
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
926
|
+
};
|
|
927
|
+
this.on("option:" + oname, (val) => {
|
|
928
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
929
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
930
|
+
});
|
|
931
|
+
if (option.envVar) {
|
|
932
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
933
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
934
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
return this;
|
|
938
|
+
}
|
|
939
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
940
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
941
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
942
|
+
}
|
|
943
|
+
const option = this.createOption(flags, description);
|
|
944
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
945
|
+
if (typeof fn === "function") {
|
|
946
|
+
option.default(defaultValue).argParser(fn);
|
|
947
|
+
} else if (fn instanceof RegExp) {
|
|
948
|
+
const regex = fn;
|
|
949
|
+
fn = (val, def) => {
|
|
950
|
+
const m = regex.exec(val);
|
|
951
|
+
return m ? m[0] : def;
|
|
952
|
+
};
|
|
953
|
+
option.default(defaultValue).argParser(fn);
|
|
954
|
+
} else {
|
|
955
|
+
option.default(fn);
|
|
956
|
+
}
|
|
957
|
+
return this.addOption(option);
|
|
958
|
+
}
|
|
959
|
+
option(flags, description, fn, defaultValue) {
|
|
960
|
+
return this._optionEx({}, flags, description, fn, defaultValue);
|
|
961
|
+
}
|
|
962
|
+
requiredOption(flags, description, fn, defaultValue) {
|
|
963
|
+
return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);
|
|
964
|
+
}
|
|
965
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
966
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
967
|
+
return this;
|
|
968
|
+
}
|
|
969
|
+
allowUnknownOption(allowUnknown = true) {
|
|
970
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
971
|
+
return this;
|
|
972
|
+
}
|
|
973
|
+
allowExcessArguments(allowExcess = true) {
|
|
974
|
+
this._allowExcessArguments = !!allowExcess;
|
|
975
|
+
return this;
|
|
976
|
+
}
|
|
977
|
+
enablePositionalOptions(positional = true) {
|
|
978
|
+
this._enablePositionalOptions = !!positional;
|
|
979
|
+
return this;
|
|
980
|
+
}
|
|
981
|
+
passThroughOptions(passThrough = true) {
|
|
982
|
+
this._passThroughOptions = !!passThrough;
|
|
983
|
+
if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
|
|
984
|
+
throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");
|
|
985
|
+
}
|
|
986
|
+
return this;
|
|
987
|
+
}
|
|
988
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
989
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
990
|
+
if (this.options.length) {
|
|
991
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
992
|
+
}
|
|
993
|
+
return this;
|
|
994
|
+
}
|
|
995
|
+
getOptionValue(key) {
|
|
996
|
+
if (this._storeOptionsAsProperties) {
|
|
997
|
+
return this[key];
|
|
998
|
+
}
|
|
999
|
+
return this._optionValues[key];
|
|
1000
|
+
}
|
|
1001
|
+
setOptionValue(key, value) {
|
|
1002
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1003
|
+
}
|
|
1004
|
+
setOptionValueWithSource(key, value, source) {
|
|
1005
|
+
if (this._storeOptionsAsProperties) {
|
|
1006
|
+
this[key] = value;
|
|
1007
|
+
} else {
|
|
1008
|
+
this._optionValues[key] = value;
|
|
1009
|
+
}
|
|
1010
|
+
this._optionValueSources[key] = source;
|
|
1011
|
+
return this;
|
|
1012
|
+
}
|
|
1013
|
+
getOptionValueSource(key) {
|
|
1014
|
+
return this._optionValueSources[key];
|
|
1015
|
+
}
|
|
1016
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1017
|
+
let source;
|
|
1018
|
+
getCommandAndParents(this).forEach((cmd) => {
|
|
1019
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1020
|
+
source = cmd.getOptionValueSource(key);
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
return source;
|
|
1024
|
+
}
|
|
1025
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1026
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1027
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1028
|
+
}
|
|
1029
|
+
parseOptions = parseOptions || {};
|
|
1030
|
+
if (argv === undefined) {
|
|
1031
|
+
argv = process2.argv;
|
|
1032
|
+
if (process2.versions && process2.versions.electron) {
|
|
1033
|
+
parseOptions.from = "electron";
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
this.rawArgs = argv.slice();
|
|
1037
|
+
let userArgs;
|
|
1038
|
+
switch (parseOptions.from) {
|
|
1039
|
+
case undefined:
|
|
1040
|
+
case "node":
|
|
1041
|
+
this._scriptPath = argv[1];
|
|
1042
|
+
userArgs = argv.slice(2);
|
|
1043
|
+
break;
|
|
1044
|
+
case "electron":
|
|
1045
|
+
if (process2.defaultApp) {
|
|
1046
|
+
this._scriptPath = argv[1];
|
|
1047
|
+
userArgs = argv.slice(2);
|
|
1048
|
+
} else {
|
|
1049
|
+
userArgs = argv.slice(1);
|
|
1050
|
+
}
|
|
1051
|
+
break;
|
|
1052
|
+
case "user":
|
|
1053
|
+
userArgs = argv.slice(0);
|
|
1054
|
+
break;
|
|
1055
|
+
default:
|
|
1056
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1057
|
+
}
|
|
1058
|
+
if (!this._name && this._scriptPath)
|
|
1059
|
+
this.nameFromFilename(this._scriptPath);
|
|
1060
|
+
this._name = this._name || "program";
|
|
1061
|
+
return userArgs;
|
|
1062
|
+
}
|
|
1063
|
+
parse(argv, parseOptions) {
|
|
1064
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1065
|
+
this._parseCommand([], userArgs);
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
async parseAsync(argv, parseOptions) {
|
|
1069
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1070
|
+
await this._parseCommand([], userArgs);
|
|
1071
|
+
return this;
|
|
1072
|
+
}
|
|
1073
|
+
_executeSubCommand(subcommand, args) {
|
|
1074
|
+
args = args.slice();
|
|
1075
|
+
let launchWithNode = false;
|
|
1076
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1077
|
+
function findFile(baseDir, baseName) {
|
|
1078
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1079
|
+
if (fs.existsSync(localBin))
|
|
1080
|
+
return localBin;
|
|
1081
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1082
|
+
return;
|
|
1083
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1084
|
+
if (foundExt)
|
|
1085
|
+
return `${localBin}${foundExt}`;
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
this._checkForMissingMandatoryOptions();
|
|
1089
|
+
this._checkForConflictingOptions();
|
|
1090
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1091
|
+
let executableDir = this._executableDir || "";
|
|
1092
|
+
if (this._scriptPath) {
|
|
1093
|
+
let resolvedScriptPath;
|
|
1094
|
+
try {
|
|
1095
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1096
|
+
} catch (err) {
|
|
1097
|
+
resolvedScriptPath = this._scriptPath;
|
|
1098
|
+
}
|
|
1099
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1100
|
+
}
|
|
1101
|
+
if (executableDir) {
|
|
1102
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1103
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1104
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1105
|
+
if (legacyName !== this._name) {
|
|
1106
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
executableFile = localFile || executableFile;
|
|
1110
|
+
}
|
|
1111
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1112
|
+
let proc;
|
|
1113
|
+
if (process2.platform !== "win32") {
|
|
1114
|
+
if (launchWithNode) {
|
|
1115
|
+
args.unshift(executableFile);
|
|
1116
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1117
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1118
|
+
} else {
|
|
1119
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1120
|
+
}
|
|
1121
|
+
} else {
|
|
1122
|
+
args.unshift(executableFile);
|
|
1123
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1124
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1125
|
+
}
|
|
1126
|
+
if (!proc.killed) {
|
|
1127
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1128
|
+
signals.forEach((signal) => {
|
|
1129
|
+
process2.on(signal, () => {
|
|
1130
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1131
|
+
proc.kill(signal);
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
const exitCallback = this._exitCallback;
|
|
1137
|
+
if (!exitCallback) {
|
|
1138
|
+
proc.on("close", process2.exit.bind(process2));
|
|
1139
|
+
} else {
|
|
1140
|
+
proc.on("close", () => {
|
|
1141
|
+
exitCallback(new CommanderError(process2.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
proc.on("error", (err) => {
|
|
1145
|
+
if (err.code === "ENOENT") {
|
|
1146
|
+
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";
|
|
1147
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1148
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1149
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1150
|
+
- ${executableDirMessage}`;
|
|
1151
|
+
throw new Error(executableMissing);
|
|
1152
|
+
} else if (err.code === "EACCES") {
|
|
1153
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1154
|
+
}
|
|
1155
|
+
if (!exitCallback) {
|
|
1156
|
+
process2.exit(1);
|
|
1157
|
+
} else {
|
|
1158
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1159
|
+
wrappedError.nestedError = err;
|
|
1160
|
+
exitCallback(wrappedError);
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
this.runningCommand = proc;
|
|
1164
|
+
}
|
|
1165
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1166
|
+
const subCommand = this._findCommand(commandName);
|
|
1167
|
+
if (!subCommand)
|
|
1168
|
+
this.help({ error: true });
|
|
1169
|
+
let hookResult;
|
|
1170
|
+
hookResult = this._chainOrCallSubCommandHook(hookResult, subCommand, "preSubcommand");
|
|
1171
|
+
hookResult = this._chainOrCall(hookResult, () => {
|
|
1172
|
+
if (subCommand._executableHandler) {
|
|
1173
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1174
|
+
} else {
|
|
1175
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
return hookResult;
|
|
1179
|
+
}
|
|
1180
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1181
|
+
if (!subcommandName) {
|
|
1182
|
+
this.help();
|
|
1183
|
+
}
|
|
1184
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1185
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1186
|
+
subCommand.help();
|
|
1187
|
+
}
|
|
1188
|
+
return this._dispatchSubcommand(subcommandName, [], [this._helpLongFlag]);
|
|
1189
|
+
}
|
|
1190
|
+
_checkNumberOfArguments() {
|
|
1191
|
+
this._args.forEach((arg, i) => {
|
|
1192
|
+
if (arg.required && this.args[i] == null) {
|
|
1193
|
+
this.missingArgument(arg.name());
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
if (this._args.length > 0 && this._args[this._args.length - 1].variadic) {
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
if (this.args.length > this._args.length) {
|
|
1200
|
+
this._excessArguments(this.args);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
_processArguments() {
|
|
1204
|
+
const myParseArg = (argument, value, previous) => {
|
|
1205
|
+
let parsedValue = value;
|
|
1206
|
+
if (value !== null && argument.parseArg) {
|
|
1207
|
+
try {
|
|
1208
|
+
parsedValue = argument.parseArg(value, previous);
|
|
1209
|
+
} catch (err) {
|
|
1210
|
+
if (err.code === "commander.invalidArgument") {
|
|
1211
|
+
const message = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'. ${err.message}`;
|
|
1212
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1213
|
+
}
|
|
1214
|
+
throw err;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
return parsedValue;
|
|
1218
|
+
};
|
|
1219
|
+
this._checkNumberOfArguments();
|
|
1220
|
+
const processedArgs = [];
|
|
1221
|
+
this._args.forEach((declaredArg, index) => {
|
|
1222
|
+
let value = declaredArg.defaultValue;
|
|
1223
|
+
if (declaredArg.variadic) {
|
|
1224
|
+
if (index < this.args.length) {
|
|
1225
|
+
value = this.args.slice(index);
|
|
1226
|
+
if (declaredArg.parseArg) {
|
|
1227
|
+
value = value.reduce((processed, v) => {
|
|
1228
|
+
return myParseArg(declaredArg, v, processed);
|
|
1229
|
+
}, declaredArg.defaultValue);
|
|
1230
|
+
}
|
|
1231
|
+
} else if (value === undefined) {
|
|
1232
|
+
value = [];
|
|
1233
|
+
}
|
|
1234
|
+
} else if (index < this.args.length) {
|
|
1235
|
+
value = this.args[index];
|
|
1236
|
+
if (declaredArg.parseArg) {
|
|
1237
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
processedArgs[index] = value;
|
|
1241
|
+
});
|
|
1242
|
+
this.processedArgs = processedArgs;
|
|
1243
|
+
}
|
|
1244
|
+
_chainOrCall(promise, fn) {
|
|
1245
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1246
|
+
return promise.then(() => fn());
|
|
1247
|
+
}
|
|
1248
|
+
return fn();
|
|
1249
|
+
}
|
|
1250
|
+
_chainOrCallHooks(promise, event) {
|
|
1251
|
+
let result = promise;
|
|
1252
|
+
const hooks = [];
|
|
1253
|
+
getCommandAndParents(this).reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1254
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1255
|
+
hooks.push({ hookedCommand, callback });
|
|
1256
|
+
});
|
|
1257
|
+
});
|
|
1258
|
+
if (event === "postAction") {
|
|
1259
|
+
hooks.reverse();
|
|
1260
|
+
}
|
|
1261
|
+
hooks.forEach((hookDetail) => {
|
|
1262
|
+
result = this._chainOrCall(result, () => {
|
|
1263
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1264
|
+
});
|
|
1265
|
+
});
|
|
1266
|
+
return result;
|
|
1267
|
+
}
|
|
1268
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1269
|
+
let result = promise;
|
|
1270
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1271
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1272
|
+
result = this._chainOrCall(result, () => {
|
|
1273
|
+
return hook(this, subCommand);
|
|
1274
|
+
});
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
return result;
|
|
1278
|
+
}
|
|
1279
|
+
_parseCommand(operands, unknown) {
|
|
1280
|
+
const parsed = this.parseOptions(unknown);
|
|
1281
|
+
this._parseOptionsEnv();
|
|
1282
|
+
this._parseOptionsImplied();
|
|
1283
|
+
operands = operands.concat(parsed.operands);
|
|
1284
|
+
unknown = parsed.unknown;
|
|
1285
|
+
this.args = operands.concat(unknown);
|
|
1286
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1287
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1288
|
+
}
|
|
1289
|
+
if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
|
|
1290
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1291
|
+
}
|
|
1292
|
+
if (this._defaultCommandName) {
|
|
1293
|
+
outputHelpIfRequested(this, unknown);
|
|
1294
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1295
|
+
}
|
|
1296
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1297
|
+
this.help({ error: true });
|
|
1298
|
+
}
|
|
1299
|
+
outputHelpIfRequested(this, parsed.unknown);
|
|
1300
|
+
this._checkForMissingMandatoryOptions();
|
|
1301
|
+
this._checkForConflictingOptions();
|
|
1302
|
+
const checkForUnknownOptions = () => {
|
|
1303
|
+
if (parsed.unknown.length > 0) {
|
|
1304
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
const commandEvent = `command:${this.name()}`;
|
|
1308
|
+
if (this._actionHandler) {
|
|
1309
|
+
checkForUnknownOptions();
|
|
1310
|
+
this._processArguments();
|
|
1311
|
+
let actionResult;
|
|
1312
|
+
actionResult = this._chainOrCallHooks(actionResult, "preAction");
|
|
1313
|
+
actionResult = this._chainOrCall(actionResult, () => this._actionHandler(this.processedArgs));
|
|
1314
|
+
if (this.parent) {
|
|
1315
|
+
actionResult = this._chainOrCall(actionResult, () => {
|
|
1316
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
actionResult = this._chainOrCallHooks(actionResult, "postAction");
|
|
1320
|
+
return actionResult;
|
|
1321
|
+
}
|
|
1322
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1323
|
+
checkForUnknownOptions();
|
|
1324
|
+
this._processArguments();
|
|
1325
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1326
|
+
} else if (operands.length) {
|
|
1327
|
+
if (this._findCommand("*")) {
|
|
1328
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1329
|
+
}
|
|
1330
|
+
if (this.listenerCount("command:*")) {
|
|
1331
|
+
this.emit("command:*", operands, unknown);
|
|
1332
|
+
} else if (this.commands.length) {
|
|
1333
|
+
this.unknownCommand();
|
|
1334
|
+
} else {
|
|
1335
|
+
checkForUnknownOptions();
|
|
1336
|
+
this._processArguments();
|
|
1337
|
+
}
|
|
1338
|
+
} else if (this.commands.length) {
|
|
1339
|
+
checkForUnknownOptions();
|
|
1340
|
+
this.help({ error: true });
|
|
1341
|
+
} else {
|
|
1342
|
+
checkForUnknownOptions();
|
|
1343
|
+
this._processArguments();
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
_findCommand(name) {
|
|
1347
|
+
if (!name)
|
|
1348
|
+
return;
|
|
1349
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1350
|
+
}
|
|
1351
|
+
_findOption(arg) {
|
|
1352
|
+
return this.options.find((option) => option.is(arg));
|
|
1353
|
+
}
|
|
1354
|
+
_checkForMissingMandatoryOptions() {
|
|
1355
|
+
for (let cmd = this;cmd; cmd = cmd.parent) {
|
|
1356
|
+
cmd.options.forEach((anOption) => {
|
|
1357
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1358
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
_checkForConflictingLocalOptions() {
|
|
1364
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1365
|
+
const optionKey = option.attributeName();
|
|
1366
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1370
|
+
});
|
|
1371
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1372
|
+
optionsWithConflicting.forEach((option) => {
|
|
1373
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1374
|
+
if (conflictingAndDefined) {
|
|
1375
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
_checkForConflictingOptions() {
|
|
1380
|
+
for (let cmd = this;cmd; cmd = cmd.parent) {
|
|
1381
|
+
cmd._checkForConflictingLocalOptions();
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
parseOptions(argv) {
|
|
1385
|
+
const operands = [];
|
|
1386
|
+
const unknown = [];
|
|
1387
|
+
let dest = operands;
|
|
1388
|
+
const args = argv.slice();
|
|
1389
|
+
function maybeOption(arg) {
|
|
1390
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1391
|
+
}
|
|
1392
|
+
let activeVariadicOption = null;
|
|
1393
|
+
while (args.length) {
|
|
1394
|
+
const arg = args.shift();
|
|
1395
|
+
if (arg === "--") {
|
|
1396
|
+
if (dest === unknown)
|
|
1397
|
+
dest.push(arg);
|
|
1398
|
+
dest.push(...args);
|
|
1399
|
+
break;
|
|
1400
|
+
}
|
|
1401
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1402
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
activeVariadicOption = null;
|
|
1406
|
+
if (maybeOption(arg)) {
|
|
1407
|
+
const option = this._findOption(arg);
|
|
1408
|
+
if (option) {
|
|
1409
|
+
if (option.required) {
|
|
1410
|
+
const value = args.shift();
|
|
1411
|
+
if (value === undefined)
|
|
1412
|
+
this.optionMissingArgument(option);
|
|
1413
|
+
this.emit(`option:${option.name()}`, value);
|
|
1414
|
+
} else if (option.optional) {
|
|
1415
|
+
let value = null;
|
|
1416
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1417
|
+
value = args.shift();
|
|
1418
|
+
}
|
|
1419
|
+
this.emit(`option:${option.name()}`, value);
|
|
1420
|
+
} else {
|
|
1421
|
+
this.emit(`option:${option.name()}`);
|
|
1422
|
+
}
|
|
1423
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1428
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1429
|
+
if (option) {
|
|
1430
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1431
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1432
|
+
} else {
|
|
1433
|
+
this.emit(`option:${option.name()}`);
|
|
1434
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1435
|
+
}
|
|
1436
|
+
continue;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1440
|
+
const index = arg.indexOf("=");
|
|
1441
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1442
|
+
if (option && (option.required || option.optional)) {
|
|
1443
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (maybeOption(arg)) {
|
|
1448
|
+
dest = unknown;
|
|
1449
|
+
}
|
|
1450
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1451
|
+
if (this._findCommand(arg)) {
|
|
1452
|
+
operands.push(arg);
|
|
1453
|
+
if (args.length > 0)
|
|
1454
|
+
unknown.push(...args);
|
|
1455
|
+
break;
|
|
1456
|
+
} else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
|
|
1457
|
+
operands.push(arg);
|
|
1458
|
+
if (args.length > 0)
|
|
1459
|
+
operands.push(...args);
|
|
1460
|
+
break;
|
|
1461
|
+
} else if (this._defaultCommandName) {
|
|
1462
|
+
unknown.push(arg);
|
|
1463
|
+
if (args.length > 0)
|
|
1464
|
+
unknown.push(...args);
|
|
1465
|
+
break;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
if (this._passThroughOptions) {
|
|
1469
|
+
dest.push(arg);
|
|
1470
|
+
if (args.length > 0)
|
|
1471
|
+
dest.push(...args);
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
dest.push(arg);
|
|
1475
|
+
}
|
|
1476
|
+
return { operands, unknown };
|
|
1477
|
+
}
|
|
1478
|
+
opts() {
|
|
1479
|
+
if (this._storeOptionsAsProperties) {
|
|
1480
|
+
const result = {};
|
|
1481
|
+
const len = this.options.length;
|
|
1482
|
+
for (let i = 0;i < len; i++) {
|
|
1483
|
+
const key = this.options[i].attributeName();
|
|
1484
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1485
|
+
}
|
|
1486
|
+
return result;
|
|
1487
|
+
}
|
|
1488
|
+
return this._optionValues;
|
|
1489
|
+
}
|
|
1490
|
+
optsWithGlobals() {
|
|
1491
|
+
return getCommandAndParents(this).reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1492
|
+
}
|
|
1493
|
+
error(message, errorOptions) {
|
|
1494
|
+
this._outputConfiguration.outputError(`${message}\n`, this._outputConfiguration.writeErr);
|
|
1495
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1496
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
|
|
1497
|
+
} else if (this._showHelpAfterError) {
|
|
1498
|
+
this._outputConfiguration.writeErr("\n");
|
|
1499
|
+
this.outputHelp({ error: true });
|
|
1500
|
+
}
|
|
1501
|
+
const config = errorOptions || {};
|
|
1502
|
+
const exitCode = config.exitCode || 1;
|
|
1503
|
+
const code = config.code || "commander.error";
|
|
1504
|
+
this._exit(exitCode, code, message);
|
|
1505
|
+
}
|
|
1506
|
+
_parseOptionsEnv() {
|
|
1507
|
+
this.options.forEach((option) => {
|
|
1508
|
+
if (option.envVar && (option.envVar in process2.env)) {
|
|
1509
|
+
const optionKey = option.attributeName();
|
|
1510
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1511
|
+
if (option.required || option.optional) {
|
|
1512
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1513
|
+
} else {
|
|
1514
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
_parseOptionsImplied() {
|
|
1521
|
+
const dualHelper = new DualOptions(this.options);
|
|
1522
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1523
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1524
|
+
};
|
|
1525
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1526
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1527
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1528
|
+
});
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
missingArgument(name) {
|
|
1532
|
+
const message = `error: missing required argument '${name}'`;
|
|
1533
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1534
|
+
}
|
|
1535
|
+
optionMissingArgument(option) {
|
|
1536
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1537
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1538
|
+
}
|
|
1539
|
+
missingMandatoryOptionValue(option) {
|
|
1540
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1541
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1542
|
+
}
|
|
1543
|
+
_conflictingOption(option, conflictingOption) {
|
|
1544
|
+
const findBestOptionFromValue = (option2) => {
|
|
1545
|
+
const optionKey = option2.attributeName();
|
|
1546
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1547
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1548
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1549
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1550
|
+
return negativeOption;
|
|
1551
|
+
}
|
|
1552
|
+
return positiveOption || option2;
|
|
1553
|
+
};
|
|
1554
|
+
const getErrorMessage = (option2) => {
|
|
1555
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1556
|
+
const optionKey = bestOption.attributeName();
|
|
1557
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1558
|
+
if (source === "env") {
|
|
1559
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1560
|
+
}
|
|
1561
|
+
return `option '${bestOption.flags}'`;
|
|
1562
|
+
};
|
|
1563
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1564
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1565
|
+
}
|
|
1566
|
+
unknownOption(flag) {
|
|
1567
|
+
if (this._allowUnknownOption)
|
|
1568
|
+
return;
|
|
1569
|
+
let suggestion = "";
|
|
1570
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1571
|
+
let candidateFlags = [];
|
|
1572
|
+
let command = this;
|
|
1573
|
+
do {
|
|
1574
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1575
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1576
|
+
command = command.parent;
|
|
1577
|
+
} while (command && !command._enablePositionalOptions);
|
|
1578
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1579
|
+
}
|
|
1580
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1581
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1582
|
+
}
|
|
1583
|
+
_excessArguments(receivedArgs) {
|
|
1584
|
+
if (this._allowExcessArguments)
|
|
1585
|
+
return;
|
|
1586
|
+
const expected = this._args.length;
|
|
1587
|
+
const s = expected === 1 ? "" : "s";
|
|
1588
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1589
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1590
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1591
|
+
}
|
|
1592
|
+
unknownCommand() {
|
|
1593
|
+
const unknownName = this.args[0];
|
|
1594
|
+
let suggestion = "";
|
|
1595
|
+
if (this._showSuggestionAfterError) {
|
|
1596
|
+
const candidateNames = [];
|
|
1597
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1598
|
+
candidateNames.push(command.name());
|
|
1599
|
+
if (command.alias())
|
|
1600
|
+
candidateNames.push(command.alias());
|
|
1601
|
+
});
|
|
1602
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1603
|
+
}
|
|
1604
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1605
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1606
|
+
}
|
|
1607
|
+
version(str, flags, description) {
|
|
1608
|
+
if (str === undefined)
|
|
1609
|
+
return this._version;
|
|
1610
|
+
this._version = str;
|
|
1611
|
+
flags = flags || "-V, --version";
|
|
1612
|
+
description = description || "output the version number";
|
|
1613
|
+
const versionOption = this.createOption(flags, description);
|
|
1614
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1615
|
+
this.options.push(versionOption);
|
|
1616
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1617
|
+
this._outputConfiguration.writeOut(`${str}\n`);
|
|
1618
|
+
this._exit(0, "commander.version", str);
|
|
1619
|
+
});
|
|
1620
|
+
return this;
|
|
1621
|
+
}
|
|
1622
|
+
description(str, argsDescription) {
|
|
1623
|
+
if (str === undefined && argsDescription === undefined)
|
|
1624
|
+
return this._description;
|
|
1625
|
+
this._description = str;
|
|
1626
|
+
if (argsDescription) {
|
|
1627
|
+
this._argsDescription = argsDescription;
|
|
1628
|
+
}
|
|
1629
|
+
return this;
|
|
1630
|
+
}
|
|
1631
|
+
summary(str) {
|
|
1632
|
+
if (str === undefined)
|
|
1633
|
+
return this._summary;
|
|
1634
|
+
this._summary = str;
|
|
1635
|
+
return this;
|
|
1636
|
+
}
|
|
1637
|
+
alias(alias) {
|
|
1638
|
+
if (alias === undefined)
|
|
1639
|
+
return this._aliases[0];
|
|
1640
|
+
let command = this;
|
|
1641
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1642
|
+
command = this.commands[this.commands.length - 1];
|
|
1643
|
+
}
|
|
1644
|
+
if (alias === command._name)
|
|
1645
|
+
throw new Error("Command alias can\'t be the same as its name");
|
|
1646
|
+
command._aliases.push(alias);
|
|
1647
|
+
return this;
|
|
1648
|
+
}
|
|
1649
|
+
aliases(aliases) {
|
|
1650
|
+
if (aliases === undefined)
|
|
1651
|
+
return this._aliases;
|
|
1652
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1653
|
+
return this;
|
|
1654
|
+
}
|
|
1655
|
+
usage(str) {
|
|
1656
|
+
if (str === undefined) {
|
|
1657
|
+
if (this._usage)
|
|
1658
|
+
return this._usage;
|
|
1659
|
+
const args = this._args.map((arg) => {
|
|
1660
|
+
return humanReadableArgName(arg);
|
|
1661
|
+
});
|
|
1662
|
+
return [].concat(this.options.length || this._hasHelpOption ? "[options]" : [], this.commands.length ? "[command]" : [], this._args.length ? args : []).join(" ");
|
|
1663
|
+
}
|
|
1664
|
+
this._usage = str;
|
|
1665
|
+
return this;
|
|
1666
|
+
}
|
|
1667
|
+
name(str) {
|
|
1668
|
+
if (str === undefined)
|
|
1669
|
+
return this._name;
|
|
1670
|
+
this._name = str;
|
|
1671
|
+
return this;
|
|
1672
|
+
}
|
|
1673
|
+
nameFromFilename(filename) {
|
|
1674
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1675
|
+
return this;
|
|
1676
|
+
}
|
|
1677
|
+
executableDir(path2) {
|
|
1678
|
+
if (path2 === undefined)
|
|
1679
|
+
return this._executableDir;
|
|
1680
|
+
this._executableDir = path2;
|
|
1681
|
+
return this;
|
|
1682
|
+
}
|
|
1683
|
+
helpInformation(contextOptions) {
|
|
1684
|
+
const helper = this.createHelp();
|
|
1685
|
+
if (helper.helpWidth === undefined) {
|
|
1686
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1687
|
+
}
|
|
1688
|
+
return helper.formatHelp(this, helper);
|
|
1689
|
+
}
|
|
1690
|
+
_getHelpContext(contextOptions) {
|
|
1691
|
+
contextOptions = contextOptions || {};
|
|
1692
|
+
const context = { error: !!contextOptions.error };
|
|
1693
|
+
let write;
|
|
1694
|
+
if (context.error) {
|
|
1695
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1696
|
+
} else {
|
|
1697
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1698
|
+
}
|
|
1699
|
+
context.write = contextOptions.write || write;
|
|
1700
|
+
context.command = this;
|
|
1701
|
+
return context;
|
|
1702
|
+
}
|
|
1703
|
+
outputHelp(contextOptions) {
|
|
1704
|
+
let deprecatedCallback;
|
|
1705
|
+
if (typeof contextOptions === "function") {
|
|
1706
|
+
deprecatedCallback = contextOptions;
|
|
1707
|
+
contextOptions = undefined;
|
|
1708
|
+
}
|
|
1709
|
+
const context = this._getHelpContext(contextOptions);
|
|
1710
|
+
getCommandAndParents(this).reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1711
|
+
this.emit("beforeHelp", context);
|
|
1712
|
+
let helpInformation = this.helpInformation(context);
|
|
1713
|
+
if (deprecatedCallback) {
|
|
1714
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1715
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1716
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
context.write(helpInformation);
|
|
1720
|
+
this.emit(this._helpLongFlag);
|
|
1721
|
+
this.emit("afterHelp", context);
|
|
1722
|
+
getCommandAndParents(this).forEach((command) => command.emit("afterAllHelp", context));
|
|
1723
|
+
}
|
|
1724
|
+
helpOption(flags, description) {
|
|
1725
|
+
if (typeof flags === "boolean") {
|
|
1726
|
+
this._hasHelpOption = flags;
|
|
1727
|
+
return this;
|
|
1728
|
+
}
|
|
1729
|
+
this._helpFlags = flags || this._helpFlags;
|
|
1730
|
+
this._helpDescription = description || this._helpDescription;
|
|
1731
|
+
const helpFlags = splitOptionFlags(this._helpFlags);
|
|
1732
|
+
this._helpShortFlag = helpFlags.shortFlag;
|
|
1733
|
+
this._helpLongFlag = helpFlags.longFlag;
|
|
1734
|
+
return this;
|
|
1735
|
+
}
|
|
1736
|
+
help(contextOptions) {
|
|
1737
|
+
this.outputHelp(contextOptions);
|
|
1738
|
+
let exitCode = process2.exitCode || 0;
|
|
1739
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1740
|
+
exitCode = 1;
|
|
1741
|
+
}
|
|
1742
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1743
|
+
}
|
|
1744
|
+
addHelpText(position, text) {
|
|
1745
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1746
|
+
if (!allowedValues.includes(position)) {
|
|
1747
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1748
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1749
|
+
}
|
|
1750
|
+
const helpEvent = `${position}Help`;
|
|
1751
|
+
this.on(helpEvent, (context) => {
|
|
1752
|
+
let helpStr;
|
|
1753
|
+
if (typeof text === "function") {
|
|
1754
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1755
|
+
} else {
|
|
1756
|
+
helpStr = text;
|
|
1757
|
+
}
|
|
1758
|
+
if (helpStr) {
|
|
1759
|
+
context.write(`${helpStr}\n`);
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
return this;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
exports.Command = Command;
|
|
1766
|
+
});
|
|
1767
|
+
|
|
1768
|
+
// bine_modules/commander/lib/sugg
|
|
1769
|
+
var require_commander = __commonJS((exports, module) => {
|
|
1770
|
+
var { Argument } = require_argument();
|
|
1771
|
+
var { Command } = require_command();
|
|
1772
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1773
|
+
var { Help } = require_help();
|
|
1774
|
+
var { Option } = require_option();
|
|
1775
|
+
exports = module.exports = new Command;
|
|
1776
|
+
exports.program = exports;
|
|
1777
|
+
exports.Argument = Argument;
|
|
1778
|
+
exports.Command = Command;
|
|
1779
|
+
exports.CommanderError = CommanderError;
|
|
1780
|
+
exports.Help = Help;
|
|
1781
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1782
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1783
|
+
exports.Option = Option;
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1786
|
+
// bine_modules/commander/l
|
|
1787
|
+
var require_ms = __commonJS((exports, module) => {
|
|
1788
|
+
var parse = function(str) {
|
|
1789
|
+
str = String(str);
|
|
1790
|
+
if (str.length > 100) {
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
1794
|
+
if (!match) {
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
var n = parseFloat(match[1]);
|
|
1798
|
+
var type = (match[2] || "ms").toLowerCase();
|
|
1799
|
+
switch (type) {
|
|
1800
|
+
case "years":
|
|
1801
|
+
case "year":
|
|
1802
|
+
case "yrs":
|
|
1803
|
+
case "yr":
|
|
1804
|
+
case "y":
|
|
1805
|
+
return n * y;
|
|
1806
|
+
case "weeks":
|
|
1807
|
+
case "week":
|
|
1808
|
+
case "w":
|
|
1809
|
+
return n * w;
|
|
1810
|
+
case "days":
|
|
1811
|
+
case "day":
|
|
1812
|
+
case "d":
|
|
1813
|
+
return n * d;
|
|
1814
|
+
case "hours":
|
|
1815
|
+
case "hour":
|
|
1816
|
+
case "hrs":
|
|
1817
|
+
case "hr":
|
|
1818
|
+
case "h":
|
|
1819
|
+
return n * h;
|
|
1820
|
+
case "minutes":
|
|
1821
|
+
case "minute":
|
|
1822
|
+
case "mins":
|
|
1823
|
+
case "min":
|
|
1824
|
+
case "m":
|
|
1825
|
+
return n * m;
|
|
1826
|
+
case "seconds":
|
|
1827
|
+
case "second":
|
|
1828
|
+
case "secs":
|
|
1829
|
+
case "sec":
|
|
1830
|
+
case "s":
|
|
1831
|
+
return n * s;
|
|
1832
|
+
case "milliseconds":
|
|
1833
|
+
case "millisecond":
|
|
1834
|
+
case "msecs":
|
|
1835
|
+
case "msec":
|
|
1836
|
+
case "ms":
|
|
1837
|
+
return n;
|
|
1838
|
+
default:
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
var fmtShort = function(ms) {
|
|
1843
|
+
var msAbs = Math.abs(ms);
|
|
1844
|
+
if (msAbs >= d) {
|
|
1845
|
+
return Math.round(ms / d) + "d";
|
|
1846
|
+
}
|
|
1847
|
+
if (msAbs >= h) {
|
|
1848
|
+
return Math.round(ms / h) + "h";
|
|
1849
|
+
}
|
|
1850
|
+
if (msAbs >= m) {
|
|
1851
|
+
return Math.round(ms / m) + "m";
|
|
1852
|
+
}
|
|
1853
|
+
if (msAbs >= s) {
|
|
1854
|
+
return Math.round(ms / s) + "s";
|
|
1855
|
+
}
|
|
1856
|
+
return ms + "ms";
|
|
1857
|
+
};
|
|
1858
|
+
var fmtLong = function(ms) {
|
|
1859
|
+
var msAbs = Math.abs(ms);
|
|
1860
|
+
if (msAbs >= d) {
|
|
1861
|
+
return plural(ms, msAbs, d, "day");
|
|
1862
|
+
}
|
|
1863
|
+
if (msAbs >= h) {
|
|
1864
|
+
return plural(ms, msAbs, h, "hour");
|
|
1865
|
+
}
|
|
1866
|
+
if (msAbs >= m) {
|
|
1867
|
+
return plural(ms, msAbs, m, "minute");
|
|
1868
|
+
}
|
|
1869
|
+
if (msAbs >= s) {
|
|
1870
|
+
return plural(ms, msAbs, s, "second");
|
|
1871
|
+
}
|
|
1872
|
+
return ms + " ms";
|
|
1873
|
+
};
|
|
1874
|
+
var plural = function(ms, msAbs, n, name) {
|
|
1875
|
+
var isPlural = msAbs >= n * 1.5;
|
|
1876
|
+
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
1877
|
+
};
|
|
1878
|
+
var s = 1000;
|
|
1879
|
+
var m = s * 60;
|
|
1880
|
+
var h = m * 60;
|
|
1881
|
+
var d = h * 24;
|
|
1882
|
+
var w = d * 7;
|
|
1883
|
+
var y = d * 365.25;
|
|
1884
|
+
module.exports = function(val, options) {
|
|
1885
|
+
options = options || {};
|
|
1886
|
+
var type = typeof val;
|
|
1887
|
+
if (type === "string" && val.length > 0) {
|
|
1888
|
+
return parse(val);
|
|
1889
|
+
} else if (type === "number" && isFinite(val)) {
|
|
1890
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
1891
|
+
}
|
|
1892
|
+
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
1893
|
+
};
|
|
1894
|
+
});
|
|
1895
|
+
|
|
1896
|
+
// bine_modules/commander/lib/sugge
|
|
1897
|
+
var require_common = __commonJS((exports, module) => {
|
|
1898
|
+
var setup = function(env) {
|
|
1899
|
+
createDebug.debug = createDebug;
|
|
1900
|
+
createDebug.default = createDebug;
|
|
1901
|
+
createDebug.coerce = coerce;
|
|
1902
|
+
createDebug.disable = disable;
|
|
1903
|
+
createDebug.enable = enable;
|
|
1904
|
+
createDebug.enabled = enabled;
|
|
1905
|
+
createDebug.humanize = require_ms();
|
|
1906
|
+
createDebug.destroy = destroy;
|
|
1907
|
+
Object.keys(env).forEach((key) => {
|
|
1908
|
+
createDebug[key] = env[key];
|
|
1909
|
+
});
|
|
1910
|
+
createDebug.names = [];
|
|
1911
|
+
createDebug.skips = [];
|
|
1912
|
+
createDebug.formatters = {};
|
|
1913
|
+
function selectColor(namespace) {
|
|
1914
|
+
let hash = 0;
|
|
1915
|
+
for (let i = 0;i < namespace.length; i++) {
|
|
1916
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
1917
|
+
hash |= 0;
|
|
1918
|
+
}
|
|
1919
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
1920
|
+
}
|
|
1921
|
+
createDebug.selectColor = selectColor;
|
|
1922
|
+
function createDebug(namespace) {
|
|
1923
|
+
let prevTime;
|
|
1924
|
+
let enableOverride = null;
|
|
1925
|
+
let namespacesCache;
|
|
1926
|
+
let enabledCache;
|
|
1927
|
+
function debug(...args) {
|
|
1928
|
+
if (!debug.enabled) {
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
const self = debug;
|
|
1932
|
+
const curr = Number(new Date);
|
|
1933
|
+
const ms = curr - (prevTime || curr);
|
|
1934
|
+
self.diff = ms;
|
|
1935
|
+
self.prev = prevTime;
|
|
1936
|
+
self.curr = curr;
|
|
1937
|
+
prevTime = curr;
|
|
1938
|
+
args[0] = createDebug.coerce(args[0]);
|
|
1939
|
+
if (typeof args[0] !== "string") {
|
|
1940
|
+
args.unshift("%O");
|
|
1941
|
+
}
|
|
1942
|
+
let index = 0;
|
|
1943
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
1944
|
+
if (match === "%%") {
|
|
1945
|
+
return "%";
|
|
1946
|
+
}
|
|
1947
|
+
index++;
|
|
1948
|
+
const formatter = createDebug.formatters[format];
|
|
1949
|
+
if (typeof formatter === "function") {
|
|
1950
|
+
const val = args[index];
|
|
1951
|
+
match = formatter.call(self, val);
|
|
1952
|
+
args.splice(index, 1);
|
|
1953
|
+
index--;
|
|
1954
|
+
}
|
|
1955
|
+
return match;
|
|
1956
|
+
});
|
|
1957
|
+
createDebug.formatArgs.call(self, args);
|
|
1958
|
+
const logFn = self.log || createDebug.log;
|
|
1959
|
+
logFn.apply(self, args);
|
|
1960
|
+
}
|
|
1961
|
+
debug.namespace = namespace;
|
|
1962
|
+
debug.useColors = createDebug.useColors();
|
|
1963
|
+
debug.color = createDebug.selectColor(namespace);
|
|
1964
|
+
debug.extend = extend;
|
|
1965
|
+
debug.destroy = createDebug.destroy;
|
|
1966
|
+
Object.defineProperty(debug, "enabled", {
|
|
1967
|
+
enumerable: true,
|
|
1968
|
+
configurable: false,
|
|
1969
|
+
get: () => {
|
|
1970
|
+
if (enableOverride !== null) {
|
|
1971
|
+
return enableOverride;
|
|
1972
|
+
}
|
|
1973
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
1974
|
+
namespacesCache = createDebug.namespaces;
|
|
1975
|
+
enabledCache = createDebug.enabled(namespace);
|
|
1976
|
+
}
|
|
1977
|
+
return enabledCache;
|
|
1978
|
+
},
|
|
1979
|
+
set: (v) => {
|
|
1980
|
+
enableOverride = v;
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
if (typeof createDebug.init === "function") {
|
|
1984
|
+
createDebug.init(debug);
|
|
1985
|
+
}
|
|
1986
|
+
return debug;
|
|
1987
|
+
}
|
|
1988
|
+
function extend(namespace, delimiter) {
|
|
1989
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
1990
|
+
newDebug.log = this.log;
|
|
1991
|
+
return newDebug;
|
|
1992
|
+
}
|
|
1993
|
+
function enable(namespaces) {
|
|
1994
|
+
createDebug.save(namespaces);
|
|
1995
|
+
createDebug.namespaces = namespaces;
|
|
1996
|
+
createDebug.names = [];
|
|
1997
|
+
createDebug.skips = [];
|
|
1998
|
+
let i;
|
|
1999
|
+
const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
|
|
2000
|
+
const len = split.length;
|
|
2001
|
+
for (i = 0;i < len; i++) {
|
|
2002
|
+
if (!split[i]) {
|
|
2003
|
+
continue;
|
|
2004
|
+
}
|
|
2005
|
+
namespaces = split[i].replace(/\*/g, ".*?");
|
|
2006
|
+
if (namespaces[0] === "-") {
|
|
2007
|
+
createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
|
|
2008
|
+
} else {
|
|
2009
|
+
createDebug.names.push(new RegExp("^" + namespaces + "$"));
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
function disable() {
|
|
2014
|
+
const namespaces = [
|
|
2015
|
+
...createDebug.names.map(toNamespace),
|
|
2016
|
+
...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
|
|
2017
|
+
].join(",");
|
|
2018
|
+
createDebug.enable("");
|
|
2019
|
+
return namespaces;
|
|
2020
|
+
}
|
|
2021
|
+
function enabled(name) {
|
|
2022
|
+
if (name[name.length - 1] === "*") {
|
|
2023
|
+
return true;
|
|
2024
|
+
}
|
|
2025
|
+
let i;
|
|
2026
|
+
let len;
|
|
2027
|
+
for (i = 0, len = createDebug.skips.length;i < len; i++) {
|
|
2028
|
+
if (createDebug.skips[i].test(name)) {
|
|
2029
|
+
return false;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
for (i = 0, len = createDebug.names.length;i < len; i++) {
|
|
2033
|
+
if (createDebug.names[i].test(name)) {
|
|
2034
|
+
return true;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return false;
|
|
2038
|
+
}
|
|
2039
|
+
function toNamespace(regexp) {
|
|
2040
|
+
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
|
|
2041
|
+
}
|
|
2042
|
+
function coerce(val) {
|
|
2043
|
+
if (val instanceof Error) {
|
|
2044
|
+
return val.stack || val.message;
|
|
2045
|
+
}
|
|
2046
|
+
return val;
|
|
2047
|
+
}
|
|
2048
|
+
function destroy() {
|
|
2049
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2050
|
+
}
|
|
2051
|
+
createDebug.enable(createDebug.load());
|
|
2052
|
+
return createDebug;
|
|
2053
|
+
};
|
|
2054
|
+
module.exports = setup;
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
// bine_modules/commander/lib/sugges
|
|
2058
|
+
var require_browser = __commonJS((exports, module) => {
|
|
2059
|
+
var useColors = function() {
|
|
2060
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
|
|
2061
|
+
return true;
|
|
2062
|
+
}
|
|
2063
|
+
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
2064
|
+
return false;
|
|
2065
|
+
}
|
|
2066
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
2067
|
+
};
|
|
2068
|
+
var formatArgs = function(args) {
|
|
2069
|
+
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + exports.humanize(this.diff);
|
|
2070
|
+
if (!this.useColors) {
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2073
|
+
const c = "color: " + this.color;
|
|
2074
|
+
args.splice(1, 0, c, "color: inherit");
|
|
2075
|
+
let index = 0;
|
|
2076
|
+
let lastC = 0;
|
|
2077
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
2078
|
+
if (match === "%%") {
|
|
2079
|
+
return;
|
|
2080
|
+
}
|
|
2081
|
+
index++;
|
|
2082
|
+
if (match === "%c") {
|
|
2083
|
+
lastC = index;
|
|
2084
|
+
}
|
|
2085
|
+
});
|
|
2086
|
+
args.splice(lastC, 0, c);
|
|
2087
|
+
};
|
|
2088
|
+
var save = function(namespaces) {
|
|
2089
|
+
try {
|
|
2090
|
+
if (namespaces) {
|
|
2091
|
+
exports.storage.setItem("debug", namespaces);
|
|
2092
|
+
} else {
|
|
2093
|
+
exports.storage.removeItem("debug");
|
|
2094
|
+
}
|
|
2095
|
+
} catch (error) {
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
var load = function() {
|
|
2099
|
+
let r;
|
|
2100
|
+
try {
|
|
2101
|
+
r = exports.storage.getItem("debug");
|
|
2102
|
+
} catch (error) {
|
|
2103
|
+
}
|
|
2104
|
+
if (!r && typeof process !== "undefined" && ("env" in process)) {
|
|
2105
|
+
r = process.env.DEBUG;
|
|
2106
|
+
}
|
|
2107
|
+
return r;
|
|
2108
|
+
};
|
|
2109
|
+
var localstorage = function() {
|
|
2110
|
+
try {
|
|
2111
|
+
return localStorage;
|
|
2112
|
+
} catch (error) {
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
exports.formatArgs = formatArgs;
|
|
2116
|
+
exports.save = save;
|
|
2117
|
+
exports.load = load;
|
|
2118
|
+
exports.useColors = useColors;
|
|
2119
|
+
exports.storage = localstorage();
|
|
2120
|
+
exports.destroy = (() => {
|
|
2121
|
+
let warned = false;
|
|
2122
|
+
return () => {
|
|
2123
|
+
if (!warned) {
|
|
2124
|
+
warned = true;
|
|
2125
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
})();
|
|
2129
|
+
exports.colors = [
|
|
2130
|
+
"#0000CC",
|
|
2131
|
+
"#0000FF",
|
|
2132
|
+
"#0033CC",
|
|
2133
|
+
"#0033FF",
|
|
2134
|
+
"#0066CC",
|
|
2135
|
+
"#0066FF",
|
|
2136
|
+
"#0099CC",
|
|
2137
|
+
"#0099FF",
|
|
2138
|
+
"#00CC00",
|
|
2139
|
+
"#00CC33",
|
|
2140
|
+
"#00CC66",
|
|
2141
|
+
"#00CC99",
|
|
2142
|
+
"#00CCCC",
|
|
2143
|
+
"#00CCFF",
|
|
2144
|
+
"#3300CC",
|
|
2145
|
+
"#3300FF",
|
|
2146
|
+
"#3333CC",
|
|
2147
|
+
"#3333FF",
|
|
2148
|
+
"#3366CC",
|
|
2149
|
+
"#3366FF",
|
|
2150
|
+
"#3399CC",
|
|
2151
|
+
"#3399FF",
|
|
2152
|
+
"#33CC00",
|
|
2153
|
+
"#33CC33",
|
|
2154
|
+
"#33CC66",
|
|
2155
|
+
"#33CC99",
|
|
2156
|
+
"#33CCCC",
|
|
2157
|
+
"#33CCFF",
|
|
2158
|
+
"#6600CC",
|
|
2159
|
+
"#6600FF",
|
|
2160
|
+
"#6633CC",
|
|
2161
|
+
"#6633FF",
|
|
2162
|
+
"#66CC00",
|
|
2163
|
+
"#66CC33",
|
|
2164
|
+
"#9900CC",
|
|
2165
|
+
"#9900FF",
|
|
2166
|
+
"#9933CC",
|
|
2167
|
+
"#9933FF",
|
|
2168
|
+
"#99CC00",
|
|
2169
|
+
"#99CC33",
|
|
2170
|
+
"#CC0000",
|
|
2171
|
+
"#CC0033",
|
|
2172
|
+
"#CC0066",
|
|
2173
|
+
"#CC0099",
|
|
2174
|
+
"#CC00CC",
|
|
2175
|
+
"#CC00FF",
|
|
2176
|
+
"#CC3300",
|
|
2177
|
+
"#CC3333",
|
|
2178
|
+
"#CC3366",
|
|
2179
|
+
"#CC3399",
|
|
2180
|
+
"#CC33CC",
|
|
2181
|
+
"#CC33FF",
|
|
2182
|
+
"#CC6600",
|
|
2183
|
+
"#CC6633",
|
|
2184
|
+
"#CC9900",
|
|
2185
|
+
"#CC9933",
|
|
2186
|
+
"#CCCC00",
|
|
2187
|
+
"#CCCC33",
|
|
2188
|
+
"#FF0000",
|
|
2189
|
+
"#FF0033",
|
|
2190
|
+
"#FF0066",
|
|
2191
|
+
"#FF0099",
|
|
2192
|
+
"#FF00CC",
|
|
2193
|
+
"#FF00FF",
|
|
2194
|
+
"#FF3300",
|
|
2195
|
+
"#FF3333",
|
|
2196
|
+
"#FF3366",
|
|
2197
|
+
"#FF3399",
|
|
2198
|
+
"#FF33CC",
|
|
2199
|
+
"#FF33FF",
|
|
2200
|
+
"#FF6600",
|
|
2201
|
+
"#FF6633",
|
|
2202
|
+
"#FF9900",
|
|
2203
|
+
"#FF9933",
|
|
2204
|
+
"#FFCC00",
|
|
2205
|
+
"#FFCC33"
|
|
2206
|
+
];
|
|
2207
|
+
exports.log = console.debug || console.log || (() => {
|
|
2208
|
+
});
|
|
2209
|
+
module.exports = require_common()(exports);
|
|
2210
|
+
var { formatters } = module.exports;
|
|
2211
|
+
formatters.j = function(v) {
|
|
2212
|
+
try {
|
|
2213
|
+
return JSON.stringify(v);
|
|
2214
|
+
} catch (error) {
|
|
2215
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
2216
|
+
}
|
|
2217
|
+
};
|
|
2218
|
+
});
|
|
2219
|
+
|
|
2220
|
+
// /home/jim/node_modules/has-flag/index.js
|
|
2221
|
+
var require_has_flag = __commonJS((exports, module) => {
|
|
2222
|
+
module.exports = (flag, argv = process.argv) => {
|
|
2223
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
2224
|
+
const position = argv.indexOf(prefix + flag);
|
|
2225
|
+
const terminatorPosition = argv.indexOf("--");
|
|
2226
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
2227
|
+
};
|
|
2228
|
+
});
|
|
2229
|
+
|
|
2230
|
+
// /home/jim/node_modules/supports-color/index.js
|
|
2231
|
+
var require_supports_color = __commonJS((exports, module) => {
|
|
2232
|
+
var translateLevel = function(level) {
|
|
2233
|
+
if (level === 0) {
|
|
2234
|
+
return false;
|
|
2235
|
+
}
|
|
2236
|
+
return {
|
|
2237
|
+
level,
|
|
2238
|
+
hasBasic: true,
|
|
2239
|
+
has256: level >= 2,
|
|
2240
|
+
has16m: level >= 3
|
|
2241
|
+
};
|
|
2242
|
+
};
|
|
2243
|
+
var supportsColor = function(haveStream, streamIsTTY) {
|
|
2244
|
+
if (forceColor === 0) {
|
|
2245
|
+
return 0;
|
|
2246
|
+
}
|
|
2247
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
2248
|
+
return 3;
|
|
2249
|
+
}
|
|
2250
|
+
if (hasFlag("color=256")) {
|
|
2251
|
+
return 2;
|
|
2252
|
+
}
|
|
2253
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
2254
|
+
return 0;
|
|
2255
|
+
}
|
|
2256
|
+
const min = forceColor || 0;
|
|
2257
|
+
if (env.TERM === "dumb") {
|
|
2258
|
+
return min;
|
|
2259
|
+
}
|
|
2260
|
+
if (process.platform === "win32") {
|
|
2261
|
+
const osRelease = os.release().split(".");
|
|
2262
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
2263
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
2264
|
+
}
|
|
2265
|
+
return 1;
|
|
2266
|
+
}
|
|
2267
|
+
if ("CI" in env) {
|
|
2268
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
2269
|
+
return 1;
|
|
2270
|
+
}
|
|
2271
|
+
return min;
|
|
2272
|
+
}
|
|
2273
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
2274
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
2275
|
+
}
|
|
2276
|
+
if (env.COLORTERM === "truecolor") {
|
|
2277
|
+
return 3;
|
|
2278
|
+
}
|
|
2279
|
+
if ("TERM_PROGRAM" in env) {
|
|
2280
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
2281
|
+
switch (env.TERM_PROGRAM) {
|
|
2282
|
+
case "iTerm.app":
|
|
2283
|
+
return version >= 3 ? 3 : 2;
|
|
2284
|
+
case "Apple_Terminal":
|
|
2285
|
+
return 2;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
2289
|
+
return 2;
|
|
2290
|
+
}
|
|
2291
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
2292
|
+
return 1;
|
|
2293
|
+
}
|
|
2294
|
+
if ("COLORTERM" in env) {
|
|
2295
|
+
return 1;
|
|
2296
|
+
}
|
|
2297
|
+
return min;
|
|
2298
|
+
};
|
|
2299
|
+
var getSupportLevel = function(stream) {
|
|
2300
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
2301
|
+
return translateLevel(level);
|
|
2302
|
+
};
|
|
2303
|
+
var os = import.meta.require("os");
|
|
2304
|
+
var tty = import.meta.require("tty");
|
|
2305
|
+
var hasFlag = require_has_flag();
|
|
2306
|
+
var { env } = process;
|
|
2307
|
+
var forceColor;
|
|
2308
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
2309
|
+
forceColor = 0;
|
|
2310
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
2311
|
+
forceColor = 1;
|
|
2312
|
+
}
|
|
2313
|
+
if ("FORCE_COLOR" in env) {
|
|
2314
|
+
if (env.FORCE_COLOR === "true") {
|
|
2315
|
+
forceColor = 1;
|
|
2316
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
2317
|
+
forceColor = 0;
|
|
2318
|
+
} else {
|
|
2319
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
module.exports = {
|
|
2323
|
+
supportsColor: getSupportLevel,
|
|
2324
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
2325
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
2326
|
+
};
|
|
2327
|
+
});
|
|
2328
|
+
|
|
2329
|
+
// bine_modules/commander/lib/sug
|
|
2330
|
+
var require_node = __commonJS((exports, module) => {
|
|
2331
|
+
var useColors = function() {
|
|
2332
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
2333
|
+
};
|
|
2334
|
+
var formatArgs = function(args) {
|
|
2335
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
2336
|
+
if (useColors2) {
|
|
2337
|
+
const c = this.color;
|
|
2338
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
2339
|
+
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
2340
|
+
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
2341
|
+
args.push(colorCode + "m+" + exports.humanize(this.diff) + "\x1B[0m");
|
|
2342
|
+
} else {
|
|
2343
|
+
args[0] = getDate() + name + " " + args[0];
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
var getDate = function() {
|
|
2347
|
+
if (exports.inspectOpts.hideDate) {
|
|
2348
|
+
return "";
|
|
2349
|
+
}
|
|
2350
|
+
return new Date().toISOString() + " ";
|
|
2351
|
+
};
|
|
2352
|
+
var log = function(...args) {
|
|
2353
|
+
return process.stderr.write(util.format(...args) + "\n");
|
|
2354
|
+
};
|
|
2355
|
+
var save = function(namespaces) {
|
|
2356
|
+
if (namespaces) {
|
|
2357
|
+
process.env.DEBUG = namespaces;
|
|
2358
|
+
} else {
|
|
2359
|
+
delete process.env.DEBUG;
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2362
|
+
var load = function() {
|
|
2363
|
+
return process.env.DEBUG;
|
|
2364
|
+
};
|
|
2365
|
+
var init = function(debug) {
|
|
2366
|
+
debug.inspectOpts = {};
|
|
2367
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
2368
|
+
for (let i = 0;i < keys.length; i++) {
|
|
2369
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
2370
|
+
}
|
|
2371
|
+
};
|
|
2372
|
+
var tty = import.meta.require("tty");
|
|
2373
|
+
var util = import.meta.require("util");
|
|
2374
|
+
exports.init = init;
|
|
2375
|
+
exports.log = log;
|
|
2376
|
+
exports.formatArgs = formatArgs;
|
|
2377
|
+
exports.save = save;
|
|
2378
|
+
exports.load = load;
|
|
2379
|
+
exports.useColors = useColors;
|
|
2380
|
+
exports.destroy = util.deprecate(() => {
|
|
2381
|
+
}, "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2382
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
2383
|
+
try {
|
|
2384
|
+
const supportsColor = require_supports_color();
|
|
2385
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
2386
|
+
exports.colors = [
|
|
2387
|
+
20,
|
|
2388
|
+
21,
|
|
2389
|
+
26,
|
|
2390
|
+
27,
|
|
2391
|
+
32,
|
|
2392
|
+
33,
|
|
2393
|
+
38,
|
|
2394
|
+
39,
|
|
2395
|
+
40,
|
|
2396
|
+
41,
|
|
2397
|
+
42,
|
|
2398
|
+
43,
|
|
2399
|
+
44,
|
|
2400
|
+
45,
|
|
2401
|
+
56,
|
|
2402
|
+
57,
|
|
2403
|
+
62,
|
|
2404
|
+
63,
|
|
2405
|
+
68,
|
|
2406
|
+
69,
|
|
2407
|
+
74,
|
|
2408
|
+
75,
|
|
2409
|
+
76,
|
|
2410
|
+
77,
|
|
2411
|
+
78,
|
|
2412
|
+
79,
|
|
2413
|
+
80,
|
|
2414
|
+
81,
|
|
2415
|
+
92,
|
|
2416
|
+
93,
|
|
2417
|
+
98,
|
|
2418
|
+
99,
|
|
2419
|
+
112,
|
|
2420
|
+
113,
|
|
2421
|
+
128,
|
|
2422
|
+
129,
|
|
2423
|
+
134,
|
|
2424
|
+
135,
|
|
2425
|
+
148,
|
|
2426
|
+
149,
|
|
2427
|
+
160,
|
|
2428
|
+
161,
|
|
2429
|
+
162,
|
|
2430
|
+
163,
|
|
2431
|
+
164,
|
|
2432
|
+
165,
|
|
2433
|
+
166,
|
|
2434
|
+
167,
|
|
2435
|
+
168,
|
|
2436
|
+
169,
|
|
2437
|
+
170,
|
|
2438
|
+
171,
|
|
2439
|
+
172,
|
|
2440
|
+
173,
|
|
2441
|
+
178,
|
|
2442
|
+
179,
|
|
2443
|
+
184,
|
|
2444
|
+
185,
|
|
2445
|
+
196,
|
|
2446
|
+
197,
|
|
2447
|
+
198,
|
|
2448
|
+
199,
|
|
2449
|
+
200,
|
|
2450
|
+
201,
|
|
2451
|
+
202,
|
|
2452
|
+
203,
|
|
2453
|
+
204,
|
|
2454
|
+
205,
|
|
2455
|
+
206,
|
|
2456
|
+
207,
|
|
2457
|
+
208,
|
|
2458
|
+
209,
|
|
2459
|
+
214,
|
|
2460
|
+
215,
|
|
2461
|
+
220,
|
|
2462
|
+
221
|
|
2463
|
+
];
|
|
2464
|
+
}
|
|
2465
|
+
} catch (error) {
|
|
2466
|
+
}
|
|
2467
|
+
exports.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
2468
|
+
return /^debug_/i.test(key);
|
|
2469
|
+
}).reduce((obj, key) => {
|
|
2470
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
2471
|
+
return k.toUpperCase();
|
|
2472
|
+
});
|
|
2473
|
+
let val = process.env[key];
|
|
2474
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
2475
|
+
val = true;
|
|
2476
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
2477
|
+
val = false;
|
|
2478
|
+
} else if (val === "null") {
|
|
2479
|
+
val = null;
|
|
2480
|
+
} else {
|
|
2481
|
+
val = Number(val);
|
|
2482
|
+
}
|
|
2483
|
+
obj[prop] = val;
|
|
2484
|
+
return obj;
|
|
2485
|
+
}, {});
|
|
2486
|
+
module.exports = require_common()(exports);
|
|
2487
|
+
var { formatters } = module.exports;
|
|
2488
|
+
formatters.o = function(v) {
|
|
2489
|
+
this.inspectOpts.colors = this.useColors;
|
|
2490
|
+
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
2491
|
+
};
|
|
2492
|
+
formatters.O = function(v) {
|
|
2493
|
+
this.inspectOpts.colors = this.useColors;
|
|
2494
|
+
return util.inspect(v, this.inspectOpts);
|
|
2495
|
+
};
|
|
2496
|
+
});
|
|
2497
|
+
|
|
2498
|
+
// bine_modules/commander/lib/sugg
|
|
2499
|
+
var require_src = __commonJS((exports, module) => {
|
|
2500
|
+
if (typeof process === "undefined" || process.type === "renderer" || false || process.__nwjs) {
|
|
2501
|
+
module.exports = require_browser();
|
|
2502
|
+
} else {
|
|
2503
|
+
module.exports = require_node();
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
|
|
2507
|
+
// bine_modules/commander/lib/sug
|
|
2508
|
+
var import_ = __toESM(require_commander(), 1);
|
|
2509
|
+
var {
|
|
2510
|
+
program,
|
|
2511
|
+
createCommand,
|
|
2512
|
+
createArgument,
|
|
2513
|
+
createOption,
|
|
2514
|
+
CommanderError,
|
|
2515
|
+
InvalidArgumentError,
|
|
2516
|
+
InvalidOptionArgumentError,
|
|
2517
|
+
Command,
|
|
2518
|
+
Argument,
|
|
2519
|
+
Option,
|
|
2520
|
+
Help
|
|
2521
|
+
} = import_.default;
|
|
2522
|
+
|
|
2523
|
+
// bine_modules/c
|
|
2524
|
+
import path from "path";
|
|
2525
|
+
import fs from "fs";
|
|
2526
|
+
function findPackageJson() {
|
|
2527
|
+
const cwd = import.meta.dir;
|
|
2528
|
+
let dir = cwd;
|
|
2529
|
+
while (dir !== "/") {
|
|
2530
|
+
const packageJson = path.join(dir, "package.json");
|
|
2531
|
+
if (fs.existsSync(packageJson)) {
|
|
2532
|
+
return packageJson;
|
|
2533
|
+
}
|
|
2534
|
+
dir = path.dirname(dir);
|
|
2535
|
+
}
|
|
2536
|
+
return null;
|
|
2537
|
+
}
|
|
2538
|
+
async function getPackageJson() {
|
|
2539
|
+
const packagePath = findPackageJson();
|
|
2540
|
+
if (!packagePath) {
|
|
2541
|
+
throw new Error(`No package.json found in ${import.meta.dir} or any parent directory`);
|
|
2542
|
+
}
|
|
2543
|
+
const packageJsonText = fs.readFileSync(packagePath, "utf8");
|
|
2544
|
+
return JSON.parse(packageJsonText);
|
|
2545
|
+
}
|
|
2546
|
+
async function getPackageVersion() {
|
|
2547
|
+
const packageJson = await packageJsonPromise;
|
|
2548
|
+
return packageJson.version;
|
|
2549
|
+
}
|
|
2550
|
+
var packageJsonPromise = getPackageJson();
|
|
2551
|
+
|
|
2552
|
+
// bine_modules/c
|
|
2553
|
+
import path2 from "path";
|
|
2554
|
+
var justBase = function(filename) {
|
|
2555
|
+
const ext = path2.extname(filename);
|
|
2556
|
+
const base = path2.basename(filename, ext);
|
|
2557
|
+
return base;
|
|
2558
|
+
};
|
|
2559
|
+
function isMain(self) {
|
|
2560
|
+
const arg1 = Bun.argv[1];
|
|
2561
|
+
const argv1Base = justBase(arg1);
|
|
2562
|
+
const selfBase = justBase(self);
|
|
2563
|
+
const result = argv1Base === selfBase;
|
|
2564
|
+
return result;
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
// bine_modules
|
|
2568
|
+
async function spawn(args, options = defaultOptions) {
|
|
2569
|
+
const proc = Bun.spawn(args, { stdout: "pipe", stderr: "pipe" });
|
|
2570
|
+
const stdout = new Response(proc.stdout);
|
|
2571
|
+
const stderr = new Response(proc.stderr);
|
|
2572
|
+
const [out, err, exitCode, signal] = await Promise.all([stdout.text(), stderr.text(), proc.exitCode, proc.signalCode]);
|
|
2573
|
+
let code = 0;
|
|
2574
|
+
if (exitCode !== null) {
|
|
2575
|
+
code = exitCode;
|
|
2576
|
+
}
|
|
2577
|
+
if (!out && !err && !options.expectQuiet) {
|
|
2578
|
+
console.warn(`No output from ${args.join(" ")}`);
|
|
2579
|
+
}
|
|
2580
|
+
return { out: out.trim(), err: err.trim(), code };
|
|
2581
|
+
}
|
|
2582
|
+
async function doCommand(args) {
|
|
2583
|
+
const { out, err } = await spawn(args);
|
|
2584
|
+
if (err)
|
|
2585
|
+
console.error(err);
|
|
2586
|
+
return out;
|
|
2587
|
+
}
|
|
2588
|
+
var defaultOptions = {
|
|
2589
|
+
expectQuiet: false
|
|
2590
|
+
};
|
|
2591
|
+
|
|
2592
|
+
// bine_modul
|
|
2593
|
+
async function getConfig(key) {
|
|
2594
|
+
return doCommand(["git", "config", "--get", key]);
|
|
2595
|
+
}
|
|
2596
|
+
async function createBranch(name) {
|
|
2597
|
+
return doCommand(["git", "checkout", "-b", name]);
|
|
2598
|
+
}
|
|
2599
|
+
async function getCurrentBranch() {
|
|
2600
|
+
return doCommand(["git", "rev-parse", "--abbrev-ref", "HEAD"]);
|
|
2601
|
+
}
|
|
2602
|
+
async function getRemote() {
|
|
2603
|
+
return doCommand(["git", "ls-remote", "--get-url", "origin"]);
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
// bine_modules/command
|
|
2607
|
+
async function getGitlabConfig() {
|
|
2608
|
+
const host = await hostP;
|
|
2609
|
+
if (!host)
|
|
2610
|
+
throw new Error("gitlab.host not in git config");
|
|
2611
|
+
const user = await userP;
|
|
2612
|
+
if (!user)
|
|
2613
|
+
throw new Error("user.email not in git config");
|
|
2614
|
+
const token = await tokenP;
|
|
2615
|
+
if (!token)
|
|
2616
|
+
throw new Error("gitlab.token not in git config");
|
|
2617
|
+
return { host, user, token };
|
|
2618
|
+
}
|
|
2619
|
+
var hostP = getConfig("gitlab.host");
|
|
2620
|
+
var userP = getConfig("user.email");
|
|
2621
|
+
var tokenP = getConfig("gitlab.token");
|
|
2622
|
+
|
|
2623
|
+
// bine_modules/comm
|
|
2624
|
+
var getNextLink = function(link) {
|
|
2625
|
+
if (!link) {
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
const regex = /<([^>]+)>; rel="next"/;
|
|
2629
|
+
const match = link.match(regex);
|
|
2630
|
+
const next = match ? match[1] : undefined;
|
|
2631
|
+
return next;
|
|
2632
|
+
};
|
|
2633
|
+
async function gitlabApi(endpoint) {
|
|
2634
|
+
if (endpoint.startsWith("/")) {
|
|
2635
|
+
console.warn(`gitlabApi: endpoint ${endpoint} starts with /, removing it`);
|
|
2636
|
+
endpoint = endpoint.slice(1);
|
|
2637
|
+
}
|
|
2638
|
+
const method = "GET";
|
|
2639
|
+
const { host, token } = await getGitlabConfig();
|
|
2640
|
+
const base = `https://${host}/api/v4`;
|
|
2641
|
+
const requested = 100;
|
|
2642
|
+
const sep = endpoint.includes("?") ? "&" : "?";
|
|
2643
|
+
const uri = `${base}/${endpoint}${sep}per_page=${requested}`;
|
|
2644
|
+
const headers = new Headers;
|
|
2645
|
+
headers.append("Accept", "application/json");
|
|
2646
|
+
headers.append("Private-Token", token);
|
|
2647
|
+
const options = {
|
|
2648
|
+
method,
|
|
2649
|
+
headers
|
|
2650
|
+
};
|
|
2651
|
+
let request = new Request(uri, options);
|
|
2652
|
+
const response = await fetch(request);
|
|
2653
|
+
let link = getNextLink(response.headers.get("Link"));
|
|
2654
|
+
let partial = await response.json();
|
|
2655
|
+
let result = partial;
|
|
2656
|
+
while (partial.length == requested && link) {
|
|
2657
|
+
let request2 = new Request(link, options);
|
|
2658
|
+
const next_response = await fetch(request2);
|
|
2659
|
+
link = getNextLink(next_response.headers.get("Link"));
|
|
2660
|
+
partial = await next_response.json();
|
|
2661
|
+
result = result.concat(partial);
|
|
2662
|
+
}
|
|
2663
|
+
return result;
|
|
2664
|
+
}
|
|
2665
|
+
// bine_modules/comman
|
|
2666
|
+
async function getGroups() {
|
|
2667
|
+
return await gitlabApi(`groups`);
|
|
2668
|
+
}
|
|
2669
|
+
// bine_modules/commande
|
|
2670
|
+
import path3 from "path";
|
|
2671
|
+
|
|
2672
|
+
// bine_modules/comma
|
|
2673
|
+
var import_debug = __toESM(require_src(), 1);
|
|
2674
|
+
var dlog = import_debug.default("gitlab");
|
|
2675
|
+
|
|
2676
|
+
// bine_modules/commande
|
|
2677
|
+
async function getProjects(match) {
|
|
2678
|
+
let search = "";
|
|
2679
|
+
if (match) {
|
|
2680
|
+
const m = encodeURIComponent(match);
|
|
2681
|
+
search = `&search=${m}`;
|
|
2682
|
+
}
|
|
2683
|
+
const projects = await gitlabApi(`projects?membership=true&simple=true${search}`);
|
|
2684
|
+
if (!projects) {
|
|
2685
|
+
throw new Error(`No projects!`);
|
|
2686
|
+
} else if (!Array.isArray(projects)) {
|
|
2687
|
+
console.log(projects);
|
|
2688
|
+
throw new Error(`Projects is not an array!`);
|
|
2689
|
+
}
|
|
2690
|
+
const projs = projects;
|
|
2691
|
+
const filtered = projs.filter((p) => {
|
|
2692
|
+
return p.path_with_namespace.toLowerCase().includes(match.toLowerCase());
|
|
2693
|
+
});
|
|
2694
|
+
return filtered;
|
|
2695
|
+
}
|
|
2696
|
+
async function findProject(ssh_url) {
|
|
2697
|
+
const parts = ssh_url.split(":");
|
|
2698
|
+
if (parts.length != 2) {
|
|
2699
|
+
throw new Error(`${ssh_url} is invalid, could not be split into two parts at :`);
|
|
2700
|
+
}
|
|
2701
|
+
const name = path3.basename(parts[1], ".git");
|
|
2702
|
+
const projects = await getProjects(name);
|
|
2703
|
+
const project = projects.find((p) => {
|
|
2704
|
+
return p.ssh_url_to_repo === ssh_url;
|
|
2705
|
+
});
|
|
2706
|
+
return project;
|
|
2707
|
+
}
|
|
2708
|
+
async function projectScopedGet(endpoint) {
|
|
2709
|
+
if (endpoint.startsWith("/")) {
|
|
2710
|
+
console.warn(`gitlabApi: endpoint ${endpoint} starts with /, removing it`);
|
|
2711
|
+
endpoint = endpoint.slice(1);
|
|
2712
|
+
}
|
|
2713
|
+
const method = "GET";
|
|
2714
|
+
const { host, token } = await getGitlabConfig();
|
|
2715
|
+
const remote = await getRemote();
|
|
2716
|
+
const project = await findProject(remote);
|
|
2717
|
+
if (!project) {
|
|
2718
|
+
throw new Error(`Could not find project for remote ${remote}`);
|
|
2719
|
+
}
|
|
2720
|
+
const base = `https://${host}/api/v4/projects/${project.id}`;
|
|
2721
|
+
const uri = `${base}/${endpoint}`;
|
|
2722
|
+
dlog(`projectScopedGet uri: ${uri}`);
|
|
2723
|
+
const headers = new Headers;
|
|
2724
|
+
headers.append("Accept", "application/json");
|
|
2725
|
+
headers.append("Private-Token", token);
|
|
2726
|
+
const options = {
|
|
2727
|
+
method,
|
|
2728
|
+
headers
|
|
2729
|
+
};
|
|
2730
|
+
const request = new Request(uri, options);
|
|
2731
|
+
const response = await fetch(request);
|
|
2732
|
+
return await response.json();
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
// bine_modules/comma
|
|
2736
|
+
async function whoami() {
|
|
2737
|
+
return await gitlabApi("user");
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
// bine_modules/commander/lib/
|
|
2741
|
+
async function getMergeRequest(id) {
|
|
2742
|
+
return await projectScopedGet(`merge_requests/${id}`);
|
|
2743
|
+
}
|
|
2744
|
+
async function getMyMergeRequestsInProgress() {
|
|
2745
|
+
const me = await whoami();
|
|
2746
|
+
return await gitlabApi(`merge_requests?state=opened&author_id=${me.id}`);
|
|
2747
|
+
}
|
|
2748
|
+
async function getMyMergeRequestsToReview() {
|
|
2749
|
+
const me = await whoami();
|
|
2750
|
+
return await gitlabApi(`merge_requests?state=opened&reviewer_id=${me.id}`);
|
|
2751
|
+
}
|
|
2752
|
+
// bine_modules/commander/
|
|
2753
|
+
async function getNamespaces() {
|
|
2754
|
+
return await gitlabApi(`namespaces`);
|
|
2755
|
+
}
|
|
2756
|
+
// bine_modules/commander
|
|
2757
|
+
async function getProjectPipelines(options) {
|
|
2758
|
+
const { days, status } = options;
|
|
2759
|
+
const me = await whoami();
|
|
2760
|
+
const username = me.username;
|
|
2761
|
+
const date = new Date;
|
|
2762
|
+
const pastDate = date.getDate() - days;
|
|
2763
|
+
date.setDate(pastDate);
|
|
2764
|
+
const updated = date.toISOString();
|
|
2765
|
+
dlog(`updated: ${updated}`);
|
|
2766
|
+
return await projectScopedGet(`pipelines?status=${status}&username=${username}&updated_after=${updated}`);
|
|
2767
|
+
}
|
|
2768
|
+
// bine_modules/commander/li
|
|
2769
|
+
function create() {
|
|
2770
|
+
const program2 = new Command;
|
|
2771
|
+
program2.version(version).name("list").description("List groups for the current user").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
2772
|
+
const groups = await getGroups();
|
|
2773
|
+
if (options.verbose)
|
|
2774
|
+
console.log(groups);
|
|
2775
|
+
else {
|
|
2776
|
+
const filtered = groups.map((g) => {
|
|
2777
|
+
const { id, name, full_path } = g;
|
|
2778
|
+
return { id, name, full_path };
|
|
2779
|
+
});
|
|
2780
|
+
console.log(filtered);
|
|
2781
|
+
}
|
|
2782
|
+
});
|
|
2783
|
+
return program2;
|
|
2784
|
+
}
|
|
2785
|
+
var version = await getPackageVersion();
|
|
2786
|
+
var git_lab_group_list_default = create;
|
|
2787
|
+
if (isMain("git-lab-group-list")) {
|
|
2788
|
+
await create().parseAsync(Bun.argv);
|
|
2789
|
+
}
|
|
2790
|
+
export {
|
|
2791
|
+
git_lab_group_list_default as default,
|
|
2792
|
+
create
|
|
2793
|
+
};
|