ya-git-jira 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/skills/architecture/SKILL.md +45 -0
- package/.opencode/skills/code-style/SKILL.md +76 -0
- package/.opencode/skills/git-confluence/SKILL.md +82 -0
- package/.opencode/skills/git-jira/SKILL.md +63 -0
- package/.opencode/skills/git-lab/SKILL.md +102 -0
- package/AGENTS.md +50 -0
- package/README.md +106 -106
- package/bin/git-api.ts +70 -0
- package/bin/git-confluence-page-search.ts +58 -0
- package/bin/git-confluence-page-show.ts +61 -0
- package/bin/git-confluence-page-update.ts +77 -0
- package/bin/git-confluence-page.ts +28 -0
- package/bin/git-confluence-space-list.ts +34 -0
- package/bin/git-confluence-space.ts +24 -0
- package/bin/git-confluence-whoami.ts +33 -0
- package/bin/git-confluence.ts +27 -0
- package/bin/git-jira-start.ts +1 -1
- package/bin/git-jira-whoami.ts +32 -0
- package/bin/git-jira.ts +2 -0
- package/bin/git-lab-project-mr-list.ts +57 -0
- package/bin/git-lab-project-mr.ts +24 -0
- package/bin/git-lab-project-pipeline-jobs.ts +46 -0
- package/bin/git-lab-project-pipeline-latest.ts +47 -0
- package/bin/git-lab-project-pipeline-log.ts +49 -0
- package/bin/git-lab-project-pipeline.ts +6 -0
- package/bin/git-lab-project.ts +5 -1
- package/bin/gitj-install-skills.ts +126 -0
- package/bin/gitj.ts +12 -0
- package/dist/bin/git-api.js +2156 -0
- package/dist/bin/git-bump.js +132 -121
- package/dist/bin/git-confluence-page-search.js +2079 -0
- package/dist/bin/git-confluence-page-show.js +2082 -0
- package/dist/bin/git-confluence-page-update.js +2093 -0
- package/dist/bin/git-confluence-page.js +2186 -0
- package/dist/bin/git-confluence-space-list.js +2061 -0
- package/dist/bin/git-confluence-space.js +2073 -0
- package/dist/bin/git-confluence-whoami.js +2060 -0
- package/dist/bin/git-confluence.js +2251 -0
- package/dist/bin/git-jira-issue-list.js +136 -125
- package/dist/bin/git-jira-issue-show.js +136 -125
- package/dist/bin/git-jira-issue.js +140 -129
- package/dist/bin/git-jira-start.js +138 -127
- package/dist/bin/git-jira-whoami.js +1972 -0
- package/dist/bin/git-jira.js +170 -139
- package/dist/bin/git-lab-group-list.js +321 -279
- package/dist/bin/git-lab-group.js +323 -281
- package/dist/bin/git-lab-merge-active.js +321 -279
- package/dist/bin/git-lab-merge-todo.js +321 -279
- package/dist/bin/git-lab-merge-train-list.js +289 -273
- package/dist/bin/git-lab-merge-train.js +291 -275
- package/dist/bin/git-lab-merge.js +330 -288
- package/dist/bin/git-lab-namespace-list.js +138 -127
- package/dist/bin/git-lab-namespace.js +140 -129
- package/dist/bin/git-lab-project-list.js +288 -272
- package/dist/bin/git-lab-project-mr-list.js +2740 -0
- package/dist/bin/git-lab-project-mr.js +2752 -0
- package/dist/bin/git-lab-project-pipeline-jobs.js +2734 -0
- package/dist/bin/git-lab-project-pipeline-latest.js +2736 -0
- package/dist/bin/git-lab-project-pipeline-list.js +323 -281
- package/dist/bin/git-lab-project-pipeline-log.js +2739 -0
- package/dist/bin/git-lab-project-pipeline.js +437 -292
- package/dist/bin/git-lab-project-whereami.js +292 -276
- package/dist/bin/git-lab-project.js +563 -288
- package/dist/bin/git-lab-whoami.js +142 -131
- package/dist/bin/git-lab.js +575 -338
- package/dist/bin/gitj-install-skills.js +1954 -0
- package/dist/bin/gitj.js +1385 -473
- package/dist/index.js +371 -187
- package/index.ts +1 -0
- package/lib/api.ts +177 -0
- package/lib/confluence/api.ts +132 -0
- package/lib/confluence/config.ts +25 -0
- package/lib/confluence/index.ts +3 -0
- package/lib/confluence/types.ts +59 -0
- package/lib/gitlab/index.ts +1 -0
- package/lib/gitlab/job.ts +31 -0
- package/lib/gitlab/merge-request.ts +20 -0
- package/lib/gitlab/pipeline.ts +28 -1
- package/lib/gitlab/project.ts +14 -5
- package/lib/help.ts +40 -0
- package/lib/jira.ts +2 -2
- package/package.json +18 -2
- package/tests/all-help.test.ts +6 -1
- package/tests/gitj.test.ts +1 -1
- package/tests/help-all.test.ts +29 -0
- package/bun.lockb +0 -0
|
@@ -0,0 +1,2251 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
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 = import.meta.require;
|
|
21
|
+
|
|
22
|
+
// node_modules/commander/lib/error.js
|
|
23
|
+
var require_error = __commonJS((exports) => {
|
|
24
|
+
class CommanderError extends Error {
|
|
25
|
+
constructor(exitCode, code, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
Error.captureStackTrace(this, this.constructor);
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.exitCode = exitCode;
|
|
31
|
+
this.nestedError = undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class InvalidArgumentError extends CommanderError {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(1, "commander.invalidArgument", message);
|
|
38
|
+
Error.captureStackTrace(this, this.constructor);
|
|
39
|
+
this.name = this.constructor.name;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.CommanderError = CommanderError;
|
|
43
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// node_modules/commander/lib/argument.js
|
|
47
|
+
var require_argument = __commonJS((exports) => {
|
|
48
|
+
var { InvalidArgumentError } = require_error();
|
|
49
|
+
|
|
50
|
+
class Argument {
|
|
51
|
+
constructor(name, description) {
|
|
52
|
+
this.description = description || "";
|
|
53
|
+
this.variadic = false;
|
|
54
|
+
this.parseArg = undefined;
|
|
55
|
+
this.defaultValue = undefined;
|
|
56
|
+
this.defaultValueDescription = undefined;
|
|
57
|
+
this.argChoices = undefined;
|
|
58
|
+
switch (name[0]) {
|
|
59
|
+
case "<":
|
|
60
|
+
this.required = true;
|
|
61
|
+
this._name = name.slice(1, -1);
|
|
62
|
+
break;
|
|
63
|
+
case "[":
|
|
64
|
+
this.required = false;
|
|
65
|
+
this._name = name.slice(1, -1);
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
this.required = true;
|
|
69
|
+
this._name = name;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
73
|
+
this.variadic = true;
|
|
74
|
+
this._name = this._name.slice(0, -3);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
name() {
|
|
78
|
+
return this._name;
|
|
79
|
+
}
|
|
80
|
+
_concatValue(value, previous) {
|
|
81
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
82
|
+
return [value];
|
|
83
|
+
}
|
|
84
|
+
return previous.concat(value);
|
|
85
|
+
}
|
|
86
|
+
default(value, description) {
|
|
87
|
+
this.defaultValue = value;
|
|
88
|
+
this.defaultValueDescription = description;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
argParser(fn) {
|
|
92
|
+
this.parseArg = fn;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
choices(values) {
|
|
96
|
+
this.argChoices = values.slice();
|
|
97
|
+
this.parseArg = (arg, previous) => {
|
|
98
|
+
if (!this.argChoices.includes(arg)) {
|
|
99
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
100
|
+
}
|
|
101
|
+
if (this.variadic) {
|
|
102
|
+
return this._concatValue(arg, previous);
|
|
103
|
+
}
|
|
104
|
+
return arg;
|
|
105
|
+
};
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
argRequired() {
|
|
109
|
+
this.required = true;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
argOptional() {
|
|
113
|
+
this.required = false;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function humanReadableArgName(arg) {
|
|
118
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
119
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
120
|
+
}
|
|
121
|
+
exports.Argument = Argument;
|
|
122
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// node_modules/commander/lib/help.js
|
|
126
|
+
var require_help = __commonJS((exports) => {
|
|
127
|
+
var { humanReadableArgName } = require_argument();
|
|
128
|
+
|
|
129
|
+
class Help {
|
|
130
|
+
constructor() {
|
|
131
|
+
this.helpWidth = undefined;
|
|
132
|
+
this.sortSubcommands = false;
|
|
133
|
+
this.sortOptions = false;
|
|
134
|
+
this.showGlobalOptions = false;
|
|
135
|
+
}
|
|
136
|
+
visibleCommands(cmd) {
|
|
137
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
138
|
+
if (cmd._hasImplicitHelpCommand()) {
|
|
139
|
+
const [, helpName, helpArgs] = cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/);
|
|
140
|
+
const helpCommand = cmd.createCommand(helpName).helpOption(false);
|
|
141
|
+
helpCommand.description(cmd._helpCommandDescription);
|
|
142
|
+
if (helpArgs)
|
|
143
|
+
helpCommand.arguments(helpArgs);
|
|
144
|
+
visibleCommands.push(helpCommand);
|
|
145
|
+
}
|
|
146
|
+
if (this.sortSubcommands) {
|
|
147
|
+
visibleCommands.sort((a, b) => {
|
|
148
|
+
return a.name().localeCompare(b.name());
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return visibleCommands;
|
|
152
|
+
}
|
|
153
|
+
compareOptions(a, b) {
|
|
154
|
+
const getSortKey = (option) => {
|
|
155
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
156
|
+
};
|
|
157
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
158
|
+
}
|
|
159
|
+
visibleOptions(cmd) {
|
|
160
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
161
|
+
const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
|
|
162
|
+
const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
|
|
163
|
+
if (showShortHelpFlag || showLongHelpFlag) {
|
|
164
|
+
let helpOption;
|
|
165
|
+
if (!showShortHelpFlag) {
|
|
166
|
+
helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
|
|
167
|
+
} else if (!showLongHelpFlag) {
|
|
168
|
+
helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
|
|
169
|
+
} else {
|
|
170
|
+
helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
|
|
171
|
+
}
|
|
172
|
+
visibleOptions.push(helpOption);
|
|
173
|
+
}
|
|
174
|
+
if (this.sortOptions) {
|
|
175
|
+
visibleOptions.sort(this.compareOptions);
|
|
176
|
+
}
|
|
177
|
+
return visibleOptions;
|
|
178
|
+
}
|
|
179
|
+
visibleGlobalOptions(cmd) {
|
|
180
|
+
if (!this.showGlobalOptions)
|
|
181
|
+
return [];
|
|
182
|
+
const globalOptions = [];
|
|
183
|
+
for (let parentCmd = cmd.parent;parentCmd; parentCmd = parentCmd.parent) {
|
|
184
|
+
const visibleOptions = parentCmd.options.filter((option) => !option.hidden);
|
|
185
|
+
globalOptions.push(...visibleOptions);
|
|
186
|
+
}
|
|
187
|
+
if (this.sortOptions) {
|
|
188
|
+
globalOptions.sort(this.compareOptions);
|
|
189
|
+
}
|
|
190
|
+
return globalOptions;
|
|
191
|
+
}
|
|
192
|
+
visibleArguments(cmd) {
|
|
193
|
+
if (cmd._argsDescription) {
|
|
194
|
+
cmd._args.forEach((argument) => {
|
|
195
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (cmd._args.find((argument) => argument.description)) {
|
|
199
|
+
return cmd._args;
|
|
200
|
+
}
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
subcommandTerm(cmd) {
|
|
204
|
+
const args = cmd._args.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
205
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
206
|
+
}
|
|
207
|
+
optionTerm(option) {
|
|
208
|
+
return option.flags;
|
|
209
|
+
}
|
|
210
|
+
argumentTerm(argument) {
|
|
211
|
+
return argument.name();
|
|
212
|
+
}
|
|
213
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
214
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
215
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
216
|
+
}, 0);
|
|
217
|
+
}
|
|
218
|
+
longestOptionTermLength(cmd, helper) {
|
|
219
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
220
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
221
|
+
}, 0);
|
|
222
|
+
}
|
|
223
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
224
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
225
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
226
|
+
}, 0);
|
|
227
|
+
}
|
|
228
|
+
longestArgumentTermLength(cmd, helper) {
|
|
229
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
230
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
231
|
+
}, 0);
|
|
232
|
+
}
|
|
233
|
+
commandUsage(cmd) {
|
|
234
|
+
let cmdName = cmd._name;
|
|
235
|
+
if (cmd._aliases[0]) {
|
|
236
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
237
|
+
}
|
|
238
|
+
let parentCmdNames = "";
|
|
239
|
+
for (let parentCmd = cmd.parent;parentCmd; parentCmd = parentCmd.parent) {
|
|
240
|
+
parentCmdNames = parentCmd.name() + " " + parentCmdNames;
|
|
241
|
+
}
|
|
242
|
+
return parentCmdNames + cmdName + " " + cmd.usage();
|
|
243
|
+
}
|
|
244
|
+
commandDescription(cmd) {
|
|
245
|
+
return cmd.description();
|
|
246
|
+
}
|
|
247
|
+
subcommandDescription(cmd) {
|
|
248
|
+
return cmd.summary() || cmd.description();
|
|
249
|
+
}
|
|
250
|
+
optionDescription(option) {
|
|
251
|
+
const extraInfo = [];
|
|
252
|
+
if (option.argChoices) {
|
|
253
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
254
|
+
}
|
|
255
|
+
if (option.defaultValue !== undefined) {
|
|
256
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
257
|
+
if (showDefault) {
|
|
258
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
262
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
263
|
+
}
|
|
264
|
+
if (option.envVar !== undefined) {
|
|
265
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
266
|
+
}
|
|
267
|
+
if (extraInfo.length > 0) {
|
|
268
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
269
|
+
}
|
|
270
|
+
return option.description;
|
|
271
|
+
}
|
|
272
|
+
argumentDescription(argument) {
|
|
273
|
+
const extraInfo = [];
|
|
274
|
+
if (argument.argChoices) {
|
|
275
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
276
|
+
}
|
|
277
|
+
if (argument.defaultValue !== undefined) {
|
|
278
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
279
|
+
}
|
|
280
|
+
if (extraInfo.length > 0) {
|
|
281
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
282
|
+
if (argument.description) {
|
|
283
|
+
return `${argument.description} ${extraDescripton}`;
|
|
284
|
+
}
|
|
285
|
+
return extraDescripton;
|
|
286
|
+
}
|
|
287
|
+
return argument.description;
|
|
288
|
+
}
|
|
289
|
+
formatHelp(cmd, helper) {
|
|
290
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
291
|
+
const helpWidth = helper.helpWidth || 80;
|
|
292
|
+
const itemIndentWidth = 2;
|
|
293
|
+
const itemSeparatorWidth = 2;
|
|
294
|
+
function formatItem(term, description) {
|
|
295
|
+
if (description) {
|
|
296
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
297
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
298
|
+
}
|
|
299
|
+
return term;
|
|
300
|
+
}
|
|
301
|
+
function formatList(textArray) {
|
|
302
|
+
return textArray.join(`
|
|
303
|
+
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
304
|
+
}
|
|
305
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
306
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
307
|
+
if (commandDescription.length > 0) {
|
|
308
|
+
output = output.concat([helper.wrap(commandDescription, helpWidth, 0), ""]);
|
|
309
|
+
}
|
|
310
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
311
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
312
|
+
});
|
|
313
|
+
if (argumentList.length > 0) {
|
|
314
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
315
|
+
}
|
|
316
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
317
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
318
|
+
});
|
|
319
|
+
if (optionList.length > 0) {
|
|
320
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
321
|
+
}
|
|
322
|
+
if (this.showGlobalOptions) {
|
|
323
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
324
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
325
|
+
});
|
|
326
|
+
if (globalOptionList.length > 0) {
|
|
327
|
+
output = output.concat(["Global Options:", formatList(globalOptionList), ""]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
331
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
332
|
+
});
|
|
333
|
+
if (commandList.length > 0) {
|
|
334
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
335
|
+
}
|
|
336
|
+
return output.join(`
|
|
337
|
+
`);
|
|
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
|
|
352
|
+
`, `
|
|
353
|
+
`);
|
|
354
|
+
const indentString = " ".repeat(indent);
|
|
355
|
+
const zeroWidthSpace = "\u200B";
|
|
356
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
357
|
+
const regex = new RegExp(`
|
|
358
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
|
|
359
|
+
const lines = columnText.match(regex) || [];
|
|
360
|
+
return leadingStr + lines.map((line, i) => {
|
|
361
|
+
if (line === `
|
|
362
|
+
`)
|
|
363
|
+
return "";
|
|
364
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
365
|
+
}).join(`
|
|
366
|
+
`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
exports.Help = Help;
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// node_modules/commander/lib/option.js
|
|
373
|
+
var require_option = __commonJS((exports) => {
|
|
374
|
+
var { InvalidArgumentError } = require_error();
|
|
375
|
+
|
|
376
|
+
class Option {
|
|
377
|
+
constructor(flags, description) {
|
|
378
|
+
this.flags = flags;
|
|
379
|
+
this.description = description || "";
|
|
380
|
+
this.required = flags.includes("<");
|
|
381
|
+
this.optional = flags.includes("[");
|
|
382
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
383
|
+
this.mandatory = false;
|
|
384
|
+
const optionFlags = splitOptionFlags(flags);
|
|
385
|
+
this.short = optionFlags.shortFlag;
|
|
386
|
+
this.long = optionFlags.longFlag;
|
|
387
|
+
this.negate = false;
|
|
388
|
+
if (this.long) {
|
|
389
|
+
this.negate = this.long.startsWith("--no-");
|
|
390
|
+
}
|
|
391
|
+
this.defaultValue = undefined;
|
|
392
|
+
this.defaultValueDescription = undefined;
|
|
393
|
+
this.presetArg = undefined;
|
|
394
|
+
this.envVar = undefined;
|
|
395
|
+
this.parseArg = undefined;
|
|
396
|
+
this.hidden = false;
|
|
397
|
+
this.argChoices = undefined;
|
|
398
|
+
this.conflictsWith = [];
|
|
399
|
+
this.implied = undefined;
|
|
400
|
+
}
|
|
401
|
+
default(value, description) {
|
|
402
|
+
this.defaultValue = value;
|
|
403
|
+
this.defaultValueDescription = description;
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
preset(arg) {
|
|
407
|
+
this.presetArg = arg;
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
conflicts(names) {
|
|
411
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
implies(impliedOptionValues) {
|
|
415
|
+
let newImplied = impliedOptionValues;
|
|
416
|
+
if (typeof impliedOptionValues === "string") {
|
|
417
|
+
newImplied = { [impliedOptionValues]: true };
|
|
418
|
+
}
|
|
419
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
env(name) {
|
|
423
|
+
this.envVar = name;
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
argParser(fn) {
|
|
427
|
+
this.parseArg = fn;
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
makeOptionMandatory(mandatory = true) {
|
|
431
|
+
this.mandatory = !!mandatory;
|
|
432
|
+
return this;
|
|
433
|
+
}
|
|
434
|
+
hideHelp(hide = true) {
|
|
435
|
+
this.hidden = !!hide;
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
_concatValue(value, previous) {
|
|
439
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
440
|
+
return [value];
|
|
441
|
+
}
|
|
442
|
+
return previous.concat(value);
|
|
443
|
+
}
|
|
444
|
+
choices(values) {
|
|
445
|
+
this.argChoices = values.slice();
|
|
446
|
+
this.parseArg = (arg, previous) => {
|
|
447
|
+
if (!this.argChoices.includes(arg)) {
|
|
448
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
449
|
+
}
|
|
450
|
+
if (this.variadic) {
|
|
451
|
+
return this._concatValue(arg, previous);
|
|
452
|
+
}
|
|
453
|
+
return arg;
|
|
454
|
+
};
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
name() {
|
|
458
|
+
if (this.long) {
|
|
459
|
+
return this.long.replace(/^--/, "");
|
|
460
|
+
}
|
|
461
|
+
return this.short.replace(/^-/, "");
|
|
462
|
+
}
|
|
463
|
+
attributeName() {
|
|
464
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
465
|
+
}
|
|
466
|
+
is(arg) {
|
|
467
|
+
return this.short === arg || this.long === arg;
|
|
468
|
+
}
|
|
469
|
+
isBoolean() {
|
|
470
|
+
return !this.required && !this.optional && !this.negate;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
class DualOptions {
|
|
475
|
+
constructor(options) {
|
|
476
|
+
this.positiveOptions = new Map;
|
|
477
|
+
this.negativeOptions = new Map;
|
|
478
|
+
this.dualOptions = new Set;
|
|
479
|
+
options.forEach((option) => {
|
|
480
|
+
if (option.negate) {
|
|
481
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
482
|
+
} else {
|
|
483
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
this.negativeOptions.forEach((value, key) => {
|
|
487
|
+
if (this.positiveOptions.has(key)) {
|
|
488
|
+
this.dualOptions.add(key);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
valueFromOption(value, option) {
|
|
493
|
+
const optionKey = option.attributeName();
|
|
494
|
+
if (!this.dualOptions.has(optionKey))
|
|
495
|
+
return true;
|
|
496
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
497
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
498
|
+
return option.negate === (negativeValue === value);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function camelcase(str) {
|
|
502
|
+
return str.split("-").reduce((str2, word) => {
|
|
503
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
function splitOptionFlags(flags) {
|
|
507
|
+
let shortFlag;
|
|
508
|
+
let longFlag;
|
|
509
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
510
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
511
|
+
shortFlag = flagParts.shift();
|
|
512
|
+
longFlag = flagParts.shift();
|
|
513
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
514
|
+
shortFlag = longFlag;
|
|
515
|
+
longFlag = undefined;
|
|
516
|
+
}
|
|
517
|
+
return { shortFlag, longFlag };
|
|
518
|
+
}
|
|
519
|
+
exports.Option = Option;
|
|
520
|
+
exports.splitOptionFlags = splitOptionFlags;
|
|
521
|
+
exports.DualOptions = DualOptions;
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
525
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
526
|
+
var maxDistance = 3;
|
|
527
|
+
function editDistance(a, b) {
|
|
528
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
529
|
+
return Math.max(a.length, b.length);
|
|
530
|
+
const d = [];
|
|
531
|
+
for (let i = 0;i <= a.length; i++) {
|
|
532
|
+
d[i] = [i];
|
|
533
|
+
}
|
|
534
|
+
for (let j = 0;j <= b.length; j++) {
|
|
535
|
+
d[0][j] = j;
|
|
536
|
+
}
|
|
537
|
+
for (let j = 1;j <= b.length; j++) {
|
|
538
|
+
for (let i = 1;i <= a.length; i++) {
|
|
539
|
+
let cost = 1;
|
|
540
|
+
if (a[i - 1] === b[j - 1]) {
|
|
541
|
+
cost = 0;
|
|
542
|
+
} else {
|
|
543
|
+
cost = 1;
|
|
544
|
+
}
|
|
545
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
546
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
547
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return d[a.length][b.length];
|
|
552
|
+
}
|
|
553
|
+
function suggestSimilar(word, candidates) {
|
|
554
|
+
if (!candidates || candidates.length === 0)
|
|
555
|
+
return "";
|
|
556
|
+
candidates = Array.from(new Set(candidates));
|
|
557
|
+
const searchingOptions = word.startsWith("--");
|
|
558
|
+
if (searchingOptions) {
|
|
559
|
+
word = word.slice(2);
|
|
560
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
561
|
+
}
|
|
562
|
+
let similar = [];
|
|
563
|
+
let bestDistance = maxDistance;
|
|
564
|
+
const minSimilarity = 0.4;
|
|
565
|
+
candidates.forEach((candidate) => {
|
|
566
|
+
if (candidate.length <= 1)
|
|
567
|
+
return;
|
|
568
|
+
const distance = editDistance(word, candidate);
|
|
569
|
+
const length = Math.max(word.length, candidate.length);
|
|
570
|
+
const similarity = (length - distance) / length;
|
|
571
|
+
if (similarity > minSimilarity) {
|
|
572
|
+
if (distance < bestDistance) {
|
|
573
|
+
bestDistance = distance;
|
|
574
|
+
similar = [candidate];
|
|
575
|
+
} else if (distance === bestDistance) {
|
|
576
|
+
similar.push(candidate);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
581
|
+
if (searchingOptions) {
|
|
582
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
583
|
+
}
|
|
584
|
+
if (similar.length > 1) {
|
|
585
|
+
return `
|
|
586
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
587
|
+
}
|
|
588
|
+
if (similar.length === 1) {
|
|
589
|
+
return `
|
|
590
|
+
(Did you mean ${similar[0]}?)`;
|
|
591
|
+
}
|
|
592
|
+
return "";
|
|
593
|
+
}
|
|
594
|
+
exports.suggestSimilar = suggestSimilar;
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// node_modules/commander/lib/command.js
|
|
598
|
+
var require_command = __commonJS((exports) => {
|
|
599
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
600
|
+
var childProcess = __require("child_process");
|
|
601
|
+
var path = __require("path");
|
|
602
|
+
var fs = __require("fs");
|
|
603
|
+
var process2 = __require("process");
|
|
604
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
605
|
+
var { CommanderError } = require_error();
|
|
606
|
+
var { Help } = require_help();
|
|
607
|
+
var { Option, splitOptionFlags, DualOptions } = require_option();
|
|
608
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
609
|
+
|
|
610
|
+
class Command extends EventEmitter {
|
|
611
|
+
constructor(name) {
|
|
612
|
+
super();
|
|
613
|
+
this.commands = [];
|
|
614
|
+
this.options = [];
|
|
615
|
+
this.parent = null;
|
|
616
|
+
this._allowUnknownOption = false;
|
|
617
|
+
this._allowExcessArguments = true;
|
|
618
|
+
this._args = [];
|
|
619
|
+
this.args = [];
|
|
620
|
+
this.rawArgs = [];
|
|
621
|
+
this.processedArgs = [];
|
|
622
|
+
this._scriptPath = null;
|
|
623
|
+
this._name = name || "";
|
|
624
|
+
this._optionValues = {};
|
|
625
|
+
this._optionValueSources = {};
|
|
626
|
+
this._storeOptionsAsProperties = false;
|
|
627
|
+
this._actionHandler = null;
|
|
628
|
+
this._executableHandler = false;
|
|
629
|
+
this._executableFile = null;
|
|
630
|
+
this._executableDir = null;
|
|
631
|
+
this._defaultCommandName = null;
|
|
632
|
+
this._exitCallback = null;
|
|
633
|
+
this._aliases = [];
|
|
634
|
+
this._combineFlagAndOptionalValue = true;
|
|
635
|
+
this._description = "";
|
|
636
|
+
this._summary = "";
|
|
637
|
+
this._argsDescription = undefined;
|
|
638
|
+
this._enablePositionalOptions = false;
|
|
639
|
+
this._passThroughOptions = false;
|
|
640
|
+
this._lifeCycleHooks = {};
|
|
641
|
+
this._showHelpAfterError = false;
|
|
642
|
+
this._showSuggestionAfterError = true;
|
|
643
|
+
this._outputConfiguration = {
|
|
644
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
645
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
646
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
647
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
648
|
+
outputError: (str, write) => write(str)
|
|
649
|
+
};
|
|
650
|
+
this._hidden = false;
|
|
651
|
+
this._hasHelpOption = true;
|
|
652
|
+
this._helpFlags = "-h, --help";
|
|
653
|
+
this._helpDescription = "display help for command";
|
|
654
|
+
this._helpShortFlag = "-h";
|
|
655
|
+
this._helpLongFlag = "--help";
|
|
656
|
+
this._addImplicitHelpCommand = undefined;
|
|
657
|
+
this._helpCommandName = "help";
|
|
658
|
+
this._helpCommandnameAndArgs = "help [command]";
|
|
659
|
+
this._helpCommandDescription = "display help for command";
|
|
660
|
+
this._helpConfiguration = {};
|
|
661
|
+
}
|
|
662
|
+
copyInheritedSettings(sourceCommand) {
|
|
663
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
664
|
+
this._hasHelpOption = sourceCommand._hasHelpOption;
|
|
665
|
+
this._helpFlags = sourceCommand._helpFlags;
|
|
666
|
+
this._helpDescription = sourceCommand._helpDescription;
|
|
667
|
+
this._helpShortFlag = sourceCommand._helpShortFlag;
|
|
668
|
+
this._helpLongFlag = sourceCommand._helpLongFlag;
|
|
669
|
+
this._helpCommandName = sourceCommand._helpCommandName;
|
|
670
|
+
this._helpCommandnameAndArgs = sourceCommand._helpCommandnameAndArgs;
|
|
671
|
+
this._helpCommandDescription = sourceCommand._helpCommandDescription;
|
|
672
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
673
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
674
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
675
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
676
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
677
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
678
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
679
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
680
|
+
return this;
|
|
681
|
+
}
|
|
682
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
683
|
+
let desc = actionOptsOrExecDesc;
|
|
684
|
+
let opts = execOpts;
|
|
685
|
+
if (typeof desc === "object" && desc !== null) {
|
|
686
|
+
opts = desc;
|
|
687
|
+
desc = null;
|
|
688
|
+
}
|
|
689
|
+
opts = opts || {};
|
|
690
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
691
|
+
const cmd = this.createCommand(name);
|
|
692
|
+
if (desc) {
|
|
693
|
+
cmd.description(desc);
|
|
694
|
+
cmd._executableHandler = true;
|
|
695
|
+
}
|
|
696
|
+
if (opts.isDefault)
|
|
697
|
+
this._defaultCommandName = cmd._name;
|
|
698
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
699
|
+
cmd._executableFile = opts.executableFile || null;
|
|
700
|
+
if (args)
|
|
701
|
+
cmd.arguments(args);
|
|
702
|
+
this.commands.push(cmd);
|
|
703
|
+
cmd.parent = this;
|
|
704
|
+
cmd.copyInheritedSettings(this);
|
|
705
|
+
if (desc)
|
|
706
|
+
return this;
|
|
707
|
+
return cmd;
|
|
708
|
+
}
|
|
709
|
+
createCommand(name) {
|
|
710
|
+
return new Command(name);
|
|
711
|
+
}
|
|
712
|
+
createHelp() {
|
|
713
|
+
return Object.assign(new Help, this.configureHelp());
|
|
714
|
+
}
|
|
715
|
+
configureHelp(configuration) {
|
|
716
|
+
if (configuration === undefined)
|
|
717
|
+
return this._helpConfiguration;
|
|
718
|
+
this._helpConfiguration = configuration;
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
721
|
+
configureOutput(configuration) {
|
|
722
|
+
if (configuration === undefined)
|
|
723
|
+
return this._outputConfiguration;
|
|
724
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
725
|
+
return this;
|
|
726
|
+
}
|
|
727
|
+
showHelpAfterError(displayHelp = true) {
|
|
728
|
+
if (typeof displayHelp !== "string")
|
|
729
|
+
displayHelp = !!displayHelp;
|
|
730
|
+
this._showHelpAfterError = displayHelp;
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
734
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
735
|
+
return this;
|
|
736
|
+
}
|
|
737
|
+
addCommand(cmd, opts) {
|
|
738
|
+
if (!cmd._name) {
|
|
739
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
740
|
+
- specify the name in Command constructor or using .name()`);
|
|
741
|
+
}
|
|
742
|
+
opts = opts || {};
|
|
743
|
+
if (opts.isDefault)
|
|
744
|
+
this._defaultCommandName = cmd._name;
|
|
745
|
+
if (opts.noHelp || opts.hidden)
|
|
746
|
+
cmd._hidden = true;
|
|
747
|
+
this.commands.push(cmd);
|
|
748
|
+
cmd.parent = this;
|
|
749
|
+
return this;
|
|
750
|
+
}
|
|
751
|
+
createArgument(name, description) {
|
|
752
|
+
return new Argument(name, description);
|
|
753
|
+
}
|
|
754
|
+
argument(name, description, fn, defaultValue) {
|
|
755
|
+
const argument = this.createArgument(name, description);
|
|
756
|
+
if (typeof fn === "function") {
|
|
757
|
+
argument.default(defaultValue).argParser(fn);
|
|
758
|
+
} else {
|
|
759
|
+
argument.default(fn);
|
|
760
|
+
}
|
|
761
|
+
this.addArgument(argument);
|
|
762
|
+
return this;
|
|
763
|
+
}
|
|
764
|
+
arguments(names) {
|
|
765
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
766
|
+
this.argument(detail);
|
|
767
|
+
});
|
|
768
|
+
return this;
|
|
769
|
+
}
|
|
770
|
+
addArgument(argument) {
|
|
771
|
+
const previousArgument = this._args.slice(-1)[0];
|
|
772
|
+
if (previousArgument && previousArgument.variadic) {
|
|
773
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
774
|
+
}
|
|
775
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
776
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
777
|
+
}
|
|
778
|
+
this._args.push(argument);
|
|
779
|
+
return this;
|
|
780
|
+
}
|
|
781
|
+
addHelpCommand(enableOrNameAndArgs, description) {
|
|
782
|
+
if (enableOrNameAndArgs === false) {
|
|
783
|
+
this._addImplicitHelpCommand = false;
|
|
784
|
+
} else {
|
|
785
|
+
this._addImplicitHelpCommand = true;
|
|
786
|
+
if (typeof enableOrNameAndArgs === "string") {
|
|
787
|
+
this._helpCommandName = enableOrNameAndArgs.split(" ")[0];
|
|
788
|
+
this._helpCommandnameAndArgs = enableOrNameAndArgs;
|
|
789
|
+
}
|
|
790
|
+
this._helpCommandDescription = description || this._helpCommandDescription;
|
|
791
|
+
}
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
_hasImplicitHelpCommand() {
|
|
795
|
+
if (this._addImplicitHelpCommand === undefined) {
|
|
796
|
+
return this.commands.length && !this._actionHandler && !this._findCommand("help");
|
|
797
|
+
}
|
|
798
|
+
return this._addImplicitHelpCommand;
|
|
799
|
+
}
|
|
800
|
+
hook(event, listener) {
|
|
801
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
802
|
+
if (!allowedValues.includes(event)) {
|
|
803
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
804
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
805
|
+
}
|
|
806
|
+
if (this._lifeCycleHooks[event]) {
|
|
807
|
+
this._lifeCycleHooks[event].push(listener);
|
|
808
|
+
} else {
|
|
809
|
+
this._lifeCycleHooks[event] = [listener];
|
|
810
|
+
}
|
|
811
|
+
return this;
|
|
812
|
+
}
|
|
813
|
+
exitOverride(fn) {
|
|
814
|
+
if (fn) {
|
|
815
|
+
this._exitCallback = fn;
|
|
816
|
+
} else {
|
|
817
|
+
this._exitCallback = (err) => {
|
|
818
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
819
|
+
throw err;
|
|
820
|
+
} else {}
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
return this;
|
|
824
|
+
}
|
|
825
|
+
_exit(exitCode, code, message) {
|
|
826
|
+
if (this._exitCallback) {
|
|
827
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
828
|
+
}
|
|
829
|
+
process2.exit(exitCode);
|
|
830
|
+
}
|
|
831
|
+
action(fn) {
|
|
832
|
+
const listener = (args) => {
|
|
833
|
+
const expectedArgsCount = this._args.length;
|
|
834
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
835
|
+
if (this._storeOptionsAsProperties) {
|
|
836
|
+
actionArgs[expectedArgsCount] = this;
|
|
837
|
+
} else {
|
|
838
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
839
|
+
}
|
|
840
|
+
actionArgs.push(this);
|
|
841
|
+
return fn.apply(this, actionArgs);
|
|
842
|
+
};
|
|
843
|
+
this._actionHandler = listener;
|
|
844
|
+
return this;
|
|
845
|
+
}
|
|
846
|
+
createOption(flags, description) {
|
|
847
|
+
return new Option(flags, description);
|
|
848
|
+
}
|
|
849
|
+
addOption(option) {
|
|
850
|
+
const oname = option.name();
|
|
851
|
+
const name = option.attributeName();
|
|
852
|
+
if (option.negate) {
|
|
853
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
854
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
855
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
856
|
+
}
|
|
857
|
+
} else if (option.defaultValue !== undefined) {
|
|
858
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
859
|
+
}
|
|
860
|
+
this.options.push(option);
|
|
861
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
862
|
+
if (val == null && option.presetArg !== undefined) {
|
|
863
|
+
val = option.presetArg;
|
|
864
|
+
}
|
|
865
|
+
const oldValue = this.getOptionValue(name);
|
|
866
|
+
if (val !== null && option.parseArg) {
|
|
867
|
+
try {
|
|
868
|
+
val = option.parseArg(val, oldValue);
|
|
869
|
+
} catch (err) {
|
|
870
|
+
if (err.code === "commander.invalidArgument") {
|
|
871
|
+
const message = `${invalidValueMessage} ${err.message}`;
|
|
872
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
873
|
+
}
|
|
874
|
+
throw err;
|
|
875
|
+
}
|
|
876
|
+
} else if (val !== null && option.variadic) {
|
|
877
|
+
val = option._concatValue(val, oldValue);
|
|
878
|
+
}
|
|
879
|
+
if (val == null) {
|
|
880
|
+
if (option.negate) {
|
|
881
|
+
val = false;
|
|
882
|
+
} else if (option.isBoolean() || option.optional) {
|
|
883
|
+
val = true;
|
|
884
|
+
} else {
|
|
885
|
+
val = "";
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
889
|
+
};
|
|
890
|
+
this.on("option:" + oname, (val) => {
|
|
891
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
892
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
893
|
+
});
|
|
894
|
+
if (option.envVar) {
|
|
895
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
896
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
897
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
return this;
|
|
901
|
+
}
|
|
902
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
903
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
904
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
905
|
+
}
|
|
906
|
+
const option = this.createOption(flags, description);
|
|
907
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
908
|
+
if (typeof fn === "function") {
|
|
909
|
+
option.default(defaultValue).argParser(fn);
|
|
910
|
+
} else if (fn instanceof RegExp) {
|
|
911
|
+
const regex = fn;
|
|
912
|
+
fn = (val, def) => {
|
|
913
|
+
const m = regex.exec(val);
|
|
914
|
+
return m ? m[0] : def;
|
|
915
|
+
};
|
|
916
|
+
option.default(defaultValue).argParser(fn);
|
|
917
|
+
} else {
|
|
918
|
+
option.default(fn);
|
|
919
|
+
}
|
|
920
|
+
return this.addOption(option);
|
|
921
|
+
}
|
|
922
|
+
option(flags, description, fn, defaultValue) {
|
|
923
|
+
return this._optionEx({}, flags, description, fn, defaultValue);
|
|
924
|
+
}
|
|
925
|
+
requiredOption(flags, description, fn, defaultValue) {
|
|
926
|
+
return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);
|
|
927
|
+
}
|
|
928
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
929
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
930
|
+
return this;
|
|
931
|
+
}
|
|
932
|
+
allowUnknownOption(allowUnknown = true) {
|
|
933
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
934
|
+
return this;
|
|
935
|
+
}
|
|
936
|
+
allowExcessArguments(allowExcess = true) {
|
|
937
|
+
this._allowExcessArguments = !!allowExcess;
|
|
938
|
+
return this;
|
|
939
|
+
}
|
|
940
|
+
enablePositionalOptions(positional = true) {
|
|
941
|
+
this._enablePositionalOptions = !!positional;
|
|
942
|
+
return this;
|
|
943
|
+
}
|
|
944
|
+
passThroughOptions(passThrough = true) {
|
|
945
|
+
this._passThroughOptions = !!passThrough;
|
|
946
|
+
if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
|
|
947
|
+
throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");
|
|
948
|
+
}
|
|
949
|
+
return this;
|
|
950
|
+
}
|
|
951
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
952
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
953
|
+
if (this.options.length) {
|
|
954
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
955
|
+
}
|
|
956
|
+
return this;
|
|
957
|
+
}
|
|
958
|
+
getOptionValue(key) {
|
|
959
|
+
if (this._storeOptionsAsProperties) {
|
|
960
|
+
return this[key];
|
|
961
|
+
}
|
|
962
|
+
return this._optionValues[key];
|
|
963
|
+
}
|
|
964
|
+
setOptionValue(key, value) {
|
|
965
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
966
|
+
}
|
|
967
|
+
setOptionValueWithSource(key, value, source) {
|
|
968
|
+
if (this._storeOptionsAsProperties) {
|
|
969
|
+
this[key] = value;
|
|
970
|
+
} else {
|
|
971
|
+
this._optionValues[key] = value;
|
|
972
|
+
}
|
|
973
|
+
this._optionValueSources[key] = source;
|
|
974
|
+
return this;
|
|
975
|
+
}
|
|
976
|
+
getOptionValueSource(key) {
|
|
977
|
+
return this._optionValueSources[key];
|
|
978
|
+
}
|
|
979
|
+
getOptionValueSourceWithGlobals(key) {
|
|
980
|
+
let source;
|
|
981
|
+
getCommandAndParents(this).forEach((cmd) => {
|
|
982
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
983
|
+
source = cmd.getOptionValueSource(key);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
return source;
|
|
987
|
+
}
|
|
988
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
989
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
990
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
991
|
+
}
|
|
992
|
+
parseOptions = parseOptions || {};
|
|
993
|
+
if (argv === undefined) {
|
|
994
|
+
argv = process2.argv;
|
|
995
|
+
if (process2.versions && process2.versions.electron) {
|
|
996
|
+
parseOptions.from = "electron";
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
this.rawArgs = argv.slice();
|
|
1000
|
+
let userArgs;
|
|
1001
|
+
switch (parseOptions.from) {
|
|
1002
|
+
case undefined:
|
|
1003
|
+
case "node":
|
|
1004
|
+
this._scriptPath = argv[1];
|
|
1005
|
+
userArgs = argv.slice(2);
|
|
1006
|
+
break;
|
|
1007
|
+
case "electron":
|
|
1008
|
+
if (process2.defaultApp) {
|
|
1009
|
+
this._scriptPath = argv[1];
|
|
1010
|
+
userArgs = argv.slice(2);
|
|
1011
|
+
} else {
|
|
1012
|
+
userArgs = argv.slice(1);
|
|
1013
|
+
}
|
|
1014
|
+
break;
|
|
1015
|
+
case "user":
|
|
1016
|
+
userArgs = argv.slice(0);
|
|
1017
|
+
break;
|
|
1018
|
+
default:
|
|
1019
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1020
|
+
}
|
|
1021
|
+
if (!this._name && this._scriptPath)
|
|
1022
|
+
this.nameFromFilename(this._scriptPath);
|
|
1023
|
+
this._name = this._name || "program";
|
|
1024
|
+
return userArgs;
|
|
1025
|
+
}
|
|
1026
|
+
parse(argv, parseOptions) {
|
|
1027
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1028
|
+
this._parseCommand([], userArgs);
|
|
1029
|
+
return this;
|
|
1030
|
+
}
|
|
1031
|
+
async parseAsync(argv, parseOptions) {
|
|
1032
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1033
|
+
await this._parseCommand([], userArgs);
|
|
1034
|
+
return this;
|
|
1035
|
+
}
|
|
1036
|
+
_executeSubCommand(subcommand, args) {
|
|
1037
|
+
args = args.slice();
|
|
1038
|
+
let launchWithNode = false;
|
|
1039
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1040
|
+
function findFile(baseDir, baseName) {
|
|
1041
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1042
|
+
if (fs.existsSync(localBin))
|
|
1043
|
+
return localBin;
|
|
1044
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1045
|
+
return;
|
|
1046
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1047
|
+
if (foundExt)
|
|
1048
|
+
return `${localBin}${foundExt}`;
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
this._checkForMissingMandatoryOptions();
|
|
1052
|
+
this._checkForConflictingOptions();
|
|
1053
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1054
|
+
let executableDir = this._executableDir || "";
|
|
1055
|
+
if (this._scriptPath) {
|
|
1056
|
+
let resolvedScriptPath;
|
|
1057
|
+
try {
|
|
1058
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1059
|
+
} catch (err) {
|
|
1060
|
+
resolvedScriptPath = this._scriptPath;
|
|
1061
|
+
}
|
|
1062
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1063
|
+
}
|
|
1064
|
+
if (executableDir) {
|
|
1065
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1066
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1067
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1068
|
+
if (legacyName !== this._name) {
|
|
1069
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
executableFile = localFile || executableFile;
|
|
1073
|
+
}
|
|
1074
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1075
|
+
let proc;
|
|
1076
|
+
if (process2.platform !== "win32") {
|
|
1077
|
+
if (launchWithNode) {
|
|
1078
|
+
args.unshift(executableFile);
|
|
1079
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1080
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1081
|
+
} else {
|
|
1082
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1083
|
+
}
|
|
1084
|
+
} else {
|
|
1085
|
+
args.unshift(executableFile);
|
|
1086
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1087
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1088
|
+
}
|
|
1089
|
+
if (!proc.killed) {
|
|
1090
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1091
|
+
signals.forEach((signal) => {
|
|
1092
|
+
process2.on(signal, () => {
|
|
1093
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1094
|
+
proc.kill(signal);
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
const exitCallback = this._exitCallback;
|
|
1100
|
+
if (!exitCallback) {
|
|
1101
|
+
proc.on("close", process2.exit.bind(process2));
|
|
1102
|
+
} else {
|
|
1103
|
+
proc.on("close", () => {
|
|
1104
|
+
exitCallback(new CommanderError(process2.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
proc.on("error", (err) => {
|
|
1108
|
+
if (err.code === "ENOENT") {
|
|
1109
|
+
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";
|
|
1110
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1111
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1112
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1113
|
+
- ${executableDirMessage}`;
|
|
1114
|
+
throw new Error(executableMissing);
|
|
1115
|
+
} else if (err.code === "EACCES") {
|
|
1116
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1117
|
+
}
|
|
1118
|
+
if (!exitCallback) {
|
|
1119
|
+
process2.exit(1);
|
|
1120
|
+
} else {
|
|
1121
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1122
|
+
wrappedError.nestedError = err;
|
|
1123
|
+
exitCallback(wrappedError);
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
this.runningCommand = proc;
|
|
1127
|
+
}
|
|
1128
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1129
|
+
const subCommand = this._findCommand(commandName);
|
|
1130
|
+
if (!subCommand)
|
|
1131
|
+
this.help({ error: true });
|
|
1132
|
+
let hookResult;
|
|
1133
|
+
hookResult = this._chainOrCallSubCommandHook(hookResult, subCommand, "preSubcommand");
|
|
1134
|
+
hookResult = this._chainOrCall(hookResult, () => {
|
|
1135
|
+
if (subCommand._executableHandler) {
|
|
1136
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1137
|
+
} else {
|
|
1138
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
return hookResult;
|
|
1142
|
+
}
|
|
1143
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1144
|
+
if (!subcommandName) {
|
|
1145
|
+
this.help();
|
|
1146
|
+
}
|
|
1147
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1148
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1149
|
+
subCommand.help();
|
|
1150
|
+
}
|
|
1151
|
+
return this._dispatchSubcommand(subcommandName, [], [this._helpLongFlag]);
|
|
1152
|
+
}
|
|
1153
|
+
_checkNumberOfArguments() {
|
|
1154
|
+
this._args.forEach((arg, i) => {
|
|
1155
|
+
if (arg.required && this.args[i] == null) {
|
|
1156
|
+
this.missingArgument(arg.name());
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
if (this._args.length > 0 && this._args[this._args.length - 1].variadic) {
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
if (this.args.length > this._args.length) {
|
|
1163
|
+
this._excessArguments(this.args);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
_processArguments() {
|
|
1167
|
+
const myParseArg = (argument, value, previous) => {
|
|
1168
|
+
let parsedValue = value;
|
|
1169
|
+
if (value !== null && argument.parseArg) {
|
|
1170
|
+
try {
|
|
1171
|
+
parsedValue = argument.parseArg(value, previous);
|
|
1172
|
+
} catch (err) {
|
|
1173
|
+
if (err.code === "commander.invalidArgument") {
|
|
1174
|
+
const message = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'. ${err.message}`;
|
|
1175
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1176
|
+
}
|
|
1177
|
+
throw err;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
return parsedValue;
|
|
1181
|
+
};
|
|
1182
|
+
this._checkNumberOfArguments();
|
|
1183
|
+
const processedArgs = [];
|
|
1184
|
+
this._args.forEach((declaredArg, index) => {
|
|
1185
|
+
let value = declaredArg.defaultValue;
|
|
1186
|
+
if (declaredArg.variadic) {
|
|
1187
|
+
if (index < this.args.length) {
|
|
1188
|
+
value = this.args.slice(index);
|
|
1189
|
+
if (declaredArg.parseArg) {
|
|
1190
|
+
value = value.reduce((processed, v) => {
|
|
1191
|
+
return myParseArg(declaredArg, v, processed);
|
|
1192
|
+
}, declaredArg.defaultValue);
|
|
1193
|
+
}
|
|
1194
|
+
} else if (value === undefined) {
|
|
1195
|
+
value = [];
|
|
1196
|
+
}
|
|
1197
|
+
} else if (index < this.args.length) {
|
|
1198
|
+
value = this.args[index];
|
|
1199
|
+
if (declaredArg.parseArg) {
|
|
1200
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
processedArgs[index] = value;
|
|
1204
|
+
});
|
|
1205
|
+
this.processedArgs = processedArgs;
|
|
1206
|
+
}
|
|
1207
|
+
_chainOrCall(promise, fn) {
|
|
1208
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1209
|
+
return promise.then(() => fn());
|
|
1210
|
+
}
|
|
1211
|
+
return fn();
|
|
1212
|
+
}
|
|
1213
|
+
_chainOrCallHooks(promise, event) {
|
|
1214
|
+
let result = promise;
|
|
1215
|
+
const hooks = [];
|
|
1216
|
+
getCommandAndParents(this).reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1217
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1218
|
+
hooks.push({ hookedCommand, callback });
|
|
1219
|
+
});
|
|
1220
|
+
});
|
|
1221
|
+
if (event === "postAction") {
|
|
1222
|
+
hooks.reverse();
|
|
1223
|
+
}
|
|
1224
|
+
hooks.forEach((hookDetail) => {
|
|
1225
|
+
result = this._chainOrCall(result, () => {
|
|
1226
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1227
|
+
});
|
|
1228
|
+
});
|
|
1229
|
+
return result;
|
|
1230
|
+
}
|
|
1231
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1232
|
+
let result = promise;
|
|
1233
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1234
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1235
|
+
result = this._chainOrCall(result, () => {
|
|
1236
|
+
return hook(this, subCommand);
|
|
1237
|
+
});
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
return result;
|
|
1241
|
+
}
|
|
1242
|
+
_parseCommand(operands, unknown) {
|
|
1243
|
+
const parsed = this.parseOptions(unknown);
|
|
1244
|
+
this._parseOptionsEnv();
|
|
1245
|
+
this._parseOptionsImplied();
|
|
1246
|
+
operands = operands.concat(parsed.operands);
|
|
1247
|
+
unknown = parsed.unknown;
|
|
1248
|
+
this.args = operands.concat(unknown);
|
|
1249
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1250
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1251
|
+
}
|
|
1252
|
+
if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
|
|
1253
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1254
|
+
}
|
|
1255
|
+
if (this._defaultCommandName) {
|
|
1256
|
+
outputHelpIfRequested(this, unknown);
|
|
1257
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1258
|
+
}
|
|
1259
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1260
|
+
this.help({ error: true });
|
|
1261
|
+
}
|
|
1262
|
+
outputHelpIfRequested(this, parsed.unknown);
|
|
1263
|
+
this._checkForMissingMandatoryOptions();
|
|
1264
|
+
this._checkForConflictingOptions();
|
|
1265
|
+
const checkForUnknownOptions = () => {
|
|
1266
|
+
if (parsed.unknown.length > 0) {
|
|
1267
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
const commandEvent = `command:${this.name()}`;
|
|
1271
|
+
if (this._actionHandler) {
|
|
1272
|
+
checkForUnknownOptions();
|
|
1273
|
+
this._processArguments();
|
|
1274
|
+
let actionResult;
|
|
1275
|
+
actionResult = this._chainOrCallHooks(actionResult, "preAction");
|
|
1276
|
+
actionResult = this._chainOrCall(actionResult, () => this._actionHandler(this.processedArgs));
|
|
1277
|
+
if (this.parent) {
|
|
1278
|
+
actionResult = this._chainOrCall(actionResult, () => {
|
|
1279
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
actionResult = this._chainOrCallHooks(actionResult, "postAction");
|
|
1283
|
+
return actionResult;
|
|
1284
|
+
}
|
|
1285
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1286
|
+
checkForUnknownOptions();
|
|
1287
|
+
this._processArguments();
|
|
1288
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1289
|
+
} else if (operands.length) {
|
|
1290
|
+
if (this._findCommand("*")) {
|
|
1291
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1292
|
+
}
|
|
1293
|
+
if (this.listenerCount("command:*")) {
|
|
1294
|
+
this.emit("command:*", operands, unknown);
|
|
1295
|
+
} else if (this.commands.length) {
|
|
1296
|
+
this.unknownCommand();
|
|
1297
|
+
} else {
|
|
1298
|
+
checkForUnknownOptions();
|
|
1299
|
+
this._processArguments();
|
|
1300
|
+
}
|
|
1301
|
+
} else if (this.commands.length) {
|
|
1302
|
+
checkForUnknownOptions();
|
|
1303
|
+
this.help({ error: true });
|
|
1304
|
+
} else {
|
|
1305
|
+
checkForUnknownOptions();
|
|
1306
|
+
this._processArguments();
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
_findCommand(name) {
|
|
1310
|
+
if (!name)
|
|
1311
|
+
return;
|
|
1312
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1313
|
+
}
|
|
1314
|
+
_findOption(arg) {
|
|
1315
|
+
return this.options.find((option) => option.is(arg));
|
|
1316
|
+
}
|
|
1317
|
+
_checkForMissingMandatoryOptions() {
|
|
1318
|
+
for (let cmd = this;cmd; cmd = cmd.parent) {
|
|
1319
|
+
cmd.options.forEach((anOption) => {
|
|
1320
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1321
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
_checkForConflictingLocalOptions() {
|
|
1327
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1328
|
+
const optionKey = option.attributeName();
|
|
1329
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1330
|
+
return false;
|
|
1331
|
+
}
|
|
1332
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1333
|
+
});
|
|
1334
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1335
|
+
optionsWithConflicting.forEach((option) => {
|
|
1336
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1337
|
+
if (conflictingAndDefined) {
|
|
1338
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
_checkForConflictingOptions() {
|
|
1343
|
+
for (let cmd = this;cmd; cmd = cmd.parent) {
|
|
1344
|
+
cmd._checkForConflictingLocalOptions();
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
parseOptions(argv) {
|
|
1348
|
+
const operands = [];
|
|
1349
|
+
const unknown = [];
|
|
1350
|
+
let dest = operands;
|
|
1351
|
+
const args = argv.slice();
|
|
1352
|
+
function maybeOption(arg) {
|
|
1353
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1354
|
+
}
|
|
1355
|
+
let activeVariadicOption = null;
|
|
1356
|
+
while (args.length) {
|
|
1357
|
+
const arg = args.shift();
|
|
1358
|
+
if (arg === "--") {
|
|
1359
|
+
if (dest === unknown)
|
|
1360
|
+
dest.push(arg);
|
|
1361
|
+
dest.push(...args);
|
|
1362
|
+
break;
|
|
1363
|
+
}
|
|
1364
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1365
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
activeVariadicOption = null;
|
|
1369
|
+
if (maybeOption(arg)) {
|
|
1370
|
+
const option = this._findOption(arg);
|
|
1371
|
+
if (option) {
|
|
1372
|
+
if (option.required) {
|
|
1373
|
+
const value = args.shift();
|
|
1374
|
+
if (value === undefined)
|
|
1375
|
+
this.optionMissingArgument(option);
|
|
1376
|
+
this.emit(`option:${option.name()}`, value);
|
|
1377
|
+
} else if (option.optional) {
|
|
1378
|
+
let value = null;
|
|
1379
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1380
|
+
value = args.shift();
|
|
1381
|
+
}
|
|
1382
|
+
this.emit(`option:${option.name()}`, value);
|
|
1383
|
+
} else {
|
|
1384
|
+
this.emit(`option:${option.name()}`);
|
|
1385
|
+
}
|
|
1386
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1391
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1392
|
+
if (option) {
|
|
1393
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1394
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1395
|
+
} else {
|
|
1396
|
+
this.emit(`option:${option.name()}`);
|
|
1397
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1398
|
+
}
|
|
1399
|
+
continue;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1403
|
+
const index = arg.indexOf("=");
|
|
1404
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1405
|
+
if (option && (option.required || option.optional)) {
|
|
1406
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1407
|
+
continue;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (maybeOption(arg)) {
|
|
1411
|
+
dest = unknown;
|
|
1412
|
+
}
|
|
1413
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1414
|
+
if (this._findCommand(arg)) {
|
|
1415
|
+
operands.push(arg);
|
|
1416
|
+
if (args.length > 0)
|
|
1417
|
+
unknown.push(...args);
|
|
1418
|
+
break;
|
|
1419
|
+
} else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
|
|
1420
|
+
operands.push(arg);
|
|
1421
|
+
if (args.length > 0)
|
|
1422
|
+
operands.push(...args);
|
|
1423
|
+
break;
|
|
1424
|
+
} else if (this._defaultCommandName) {
|
|
1425
|
+
unknown.push(arg);
|
|
1426
|
+
if (args.length > 0)
|
|
1427
|
+
unknown.push(...args);
|
|
1428
|
+
break;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (this._passThroughOptions) {
|
|
1432
|
+
dest.push(arg);
|
|
1433
|
+
if (args.length > 0)
|
|
1434
|
+
dest.push(...args);
|
|
1435
|
+
break;
|
|
1436
|
+
}
|
|
1437
|
+
dest.push(arg);
|
|
1438
|
+
}
|
|
1439
|
+
return { operands, unknown };
|
|
1440
|
+
}
|
|
1441
|
+
opts() {
|
|
1442
|
+
if (this._storeOptionsAsProperties) {
|
|
1443
|
+
const result = {};
|
|
1444
|
+
const len = this.options.length;
|
|
1445
|
+
for (let i = 0;i < len; i++) {
|
|
1446
|
+
const key = this.options[i].attributeName();
|
|
1447
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1448
|
+
}
|
|
1449
|
+
return result;
|
|
1450
|
+
}
|
|
1451
|
+
return this._optionValues;
|
|
1452
|
+
}
|
|
1453
|
+
optsWithGlobals() {
|
|
1454
|
+
return getCommandAndParents(this).reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1455
|
+
}
|
|
1456
|
+
error(message, errorOptions) {
|
|
1457
|
+
this._outputConfiguration.outputError(`${message}
|
|
1458
|
+
`, this._outputConfiguration.writeErr);
|
|
1459
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1460
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1461
|
+
`);
|
|
1462
|
+
} else if (this._showHelpAfterError) {
|
|
1463
|
+
this._outputConfiguration.writeErr(`
|
|
1464
|
+
`);
|
|
1465
|
+
this.outputHelp({ error: true });
|
|
1466
|
+
}
|
|
1467
|
+
const config = errorOptions || {};
|
|
1468
|
+
const exitCode = config.exitCode || 1;
|
|
1469
|
+
const code = config.code || "commander.error";
|
|
1470
|
+
this._exit(exitCode, code, message);
|
|
1471
|
+
}
|
|
1472
|
+
_parseOptionsEnv() {
|
|
1473
|
+
this.options.forEach((option) => {
|
|
1474
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1475
|
+
const optionKey = option.attributeName();
|
|
1476
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1477
|
+
if (option.required || option.optional) {
|
|
1478
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1479
|
+
} else {
|
|
1480
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
_parseOptionsImplied() {
|
|
1487
|
+
const dualHelper = new DualOptions(this.options);
|
|
1488
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1489
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1490
|
+
};
|
|
1491
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1492
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1493
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1494
|
+
});
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
missingArgument(name) {
|
|
1498
|
+
const message = `error: missing required argument '${name}'`;
|
|
1499
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1500
|
+
}
|
|
1501
|
+
optionMissingArgument(option) {
|
|
1502
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1503
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1504
|
+
}
|
|
1505
|
+
missingMandatoryOptionValue(option) {
|
|
1506
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1507
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1508
|
+
}
|
|
1509
|
+
_conflictingOption(option, conflictingOption) {
|
|
1510
|
+
const findBestOptionFromValue = (option2) => {
|
|
1511
|
+
const optionKey = option2.attributeName();
|
|
1512
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1513
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1514
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1515
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1516
|
+
return negativeOption;
|
|
1517
|
+
}
|
|
1518
|
+
return positiveOption || option2;
|
|
1519
|
+
};
|
|
1520
|
+
const getErrorMessage = (option2) => {
|
|
1521
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1522
|
+
const optionKey = bestOption.attributeName();
|
|
1523
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1524
|
+
if (source === "env") {
|
|
1525
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1526
|
+
}
|
|
1527
|
+
return `option '${bestOption.flags}'`;
|
|
1528
|
+
};
|
|
1529
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1530
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1531
|
+
}
|
|
1532
|
+
unknownOption(flag) {
|
|
1533
|
+
if (this._allowUnknownOption)
|
|
1534
|
+
return;
|
|
1535
|
+
let suggestion = "";
|
|
1536
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1537
|
+
let candidateFlags = [];
|
|
1538
|
+
let command = this;
|
|
1539
|
+
do {
|
|
1540
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1541
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1542
|
+
command = command.parent;
|
|
1543
|
+
} while (command && !command._enablePositionalOptions);
|
|
1544
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1545
|
+
}
|
|
1546
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1547
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1548
|
+
}
|
|
1549
|
+
_excessArguments(receivedArgs) {
|
|
1550
|
+
if (this._allowExcessArguments)
|
|
1551
|
+
return;
|
|
1552
|
+
const expected = this._args.length;
|
|
1553
|
+
const s = expected === 1 ? "" : "s";
|
|
1554
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1555
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1556
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1557
|
+
}
|
|
1558
|
+
unknownCommand() {
|
|
1559
|
+
const unknownName = this.args[0];
|
|
1560
|
+
let suggestion = "";
|
|
1561
|
+
if (this._showSuggestionAfterError) {
|
|
1562
|
+
const candidateNames = [];
|
|
1563
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1564
|
+
candidateNames.push(command.name());
|
|
1565
|
+
if (command.alias())
|
|
1566
|
+
candidateNames.push(command.alias());
|
|
1567
|
+
});
|
|
1568
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1569
|
+
}
|
|
1570
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1571
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1572
|
+
}
|
|
1573
|
+
version(str, flags, description) {
|
|
1574
|
+
if (str === undefined)
|
|
1575
|
+
return this._version;
|
|
1576
|
+
this._version = str;
|
|
1577
|
+
flags = flags || "-V, --version";
|
|
1578
|
+
description = description || "output the version number";
|
|
1579
|
+
const versionOption = this.createOption(flags, description);
|
|
1580
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1581
|
+
this.options.push(versionOption);
|
|
1582
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1583
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1584
|
+
`);
|
|
1585
|
+
this._exit(0, "commander.version", str);
|
|
1586
|
+
});
|
|
1587
|
+
return this;
|
|
1588
|
+
}
|
|
1589
|
+
description(str, argsDescription) {
|
|
1590
|
+
if (str === undefined && argsDescription === undefined)
|
|
1591
|
+
return this._description;
|
|
1592
|
+
this._description = str;
|
|
1593
|
+
if (argsDescription) {
|
|
1594
|
+
this._argsDescription = argsDescription;
|
|
1595
|
+
}
|
|
1596
|
+
return this;
|
|
1597
|
+
}
|
|
1598
|
+
summary(str) {
|
|
1599
|
+
if (str === undefined)
|
|
1600
|
+
return this._summary;
|
|
1601
|
+
this._summary = str;
|
|
1602
|
+
return this;
|
|
1603
|
+
}
|
|
1604
|
+
alias(alias) {
|
|
1605
|
+
if (alias === undefined)
|
|
1606
|
+
return this._aliases[0];
|
|
1607
|
+
let command = this;
|
|
1608
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1609
|
+
command = this.commands[this.commands.length - 1];
|
|
1610
|
+
}
|
|
1611
|
+
if (alias === command._name)
|
|
1612
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1613
|
+
command._aliases.push(alias);
|
|
1614
|
+
return this;
|
|
1615
|
+
}
|
|
1616
|
+
aliases(aliases) {
|
|
1617
|
+
if (aliases === undefined)
|
|
1618
|
+
return this._aliases;
|
|
1619
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1620
|
+
return this;
|
|
1621
|
+
}
|
|
1622
|
+
usage(str) {
|
|
1623
|
+
if (str === undefined) {
|
|
1624
|
+
if (this._usage)
|
|
1625
|
+
return this._usage;
|
|
1626
|
+
const args = this._args.map((arg) => {
|
|
1627
|
+
return humanReadableArgName(arg);
|
|
1628
|
+
});
|
|
1629
|
+
return [].concat(this.options.length || this._hasHelpOption ? "[options]" : [], this.commands.length ? "[command]" : [], this._args.length ? args : []).join(" ");
|
|
1630
|
+
}
|
|
1631
|
+
this._usage = str;
|
|
1632
|
+
return this;
|
|
1633
|
+
}
|
|
1634
|
+
name(str) {
|
|
1635
|
+
if (str === undefined)
|
|
1636
|
+
return this._name;
|
|
1637
|
+
this._name = str;
|
|
1638
|
+
return this;
|
|
1639
|
+
}
|
|
1640
|
+
nameFromFilename(filename) {
|
|
1641
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1642
|
+
return this;
|
|
1643
|
+
}
|
|
1644
|
+
executableDir(path2) {
|
|
1645
|
+
if (path2 === undefined)
|
|
1646
|
+
return this._executableDir;
|
|
1647
|
+
this._executableDir = path2;
|
|
1648
|
+
return this;
|
|
1649
|
+
}
|
|
1650
|
+
helpInformation(contextOptions) {
|
|
1651
|
+
const helper = this.createHelp();
|
|
1652
|
+
if (helper.helpWidth === undefined) {
|
|
1653
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1654
|
+
}
|
|
1655
|
+
return helper.formatHelp(this, helper);
|
|
1656
|
+
}
|
|
1657
|
+
_getHelpContext(contextOptions) {
|
|
1658
|
+
contextOptions = contextOptions || {};
|
|
1659
|
+
const context = { error: !!contextOptions.error };
|
|
1660
|
+
let write;
|
|
1661
|
+
if (context.error) {
|
|
1662
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1663
|
+
} else {
|
|
1664
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1665
|
+
}
|
|
1666
|
+
context.write = contextOptions.write || write;
|
|
1667
|
+
context.command = this;
|
|
1668
|
+
return context;
|
|
1669
|
+
}
|
|
1670
|
+
outputHelp(contextOptions) {
|
|
1671
|
+
let deprecatedCallback;
|
|
1672
|
+
if (typeof contextOptions === "function") {
|
|
1673
|
+
deprecatedCallback = contextOptions;
|
|
1674
|
+
contextOptions = undefined;
|
|
1675
|
+
}
|
|
1676
|
+
const context = this._getHelpContext(contextOptions);
|
|
1677
|
+
getCommandAndParents(this).reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1678
|
+
this.emit("beforeHelp", context);
|
|
1679
|
+
let helpInformation = this.helpInformation(context);
|
|
1680
|
+
if (deprecatedCallback) {
|
|
1681
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1682
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1683
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
context.write(helpInformation);
|
|
1687
|
+
this.emit(this._helpLongFlag);
|
|
1688
|
+
this.emit("afterHelp", context);
|
|
1689
|
+
getCommandAndParents(this).forEach((command) => command.emit("afterAllHelp", context));
|
|
1690
|
+
}
|
|
1691
|
+
helpOption(flags, description) {
|
|
1692
|
+
if (typeof flags === "boolean") {
|
|
1693
|
+
this._hasHelpOption = flags;
|
|
1694
|
+
return this;
|
|
1695
|
+
}
|
|
1696
|
+
this._helpFlags = flags || this._helpFlags;
|
|
1697
|
+
this._helpDescription = description || this._helpDescription;
|
|
1698
|
+
const helpFlags = splitOptionFlags(this._helpFlags);
|
|
1699
|
+
this._helpShortFlag = helpFlags.shortFlag;
|
|
1700
|
+
this._helpLongFlag = helpFlags.longFlag;
|
|
1701
|
+
return this;
|
|
1702
|
+
}
|
|
1703
|
+
help(contextOptions) {
|
|
1704
|
+
this.outputHelp(contextOptions);
|
|
1705
|
+
let exitCode = process2.exitCode || 0;
|
|
1706
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1707
|
+
exitCode = 1;
|
|
1708
|
+
}
|
|
1709
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1710
|
+
}
|
|
1711
|
+
addHelpText(position, text) {
|
|
1712
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1713
|
+
if (!allowedValues.includes(position)) {
|
|
1714
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1715
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1716
|
+
}
|
|
1717
|
+
const helpEvent = `${position}Help`;
|
|
1718
|
+
this.on(helpEvent, (context) => {
|
|
1719
|
+
let helpStr;
|
|
1720
|
+
if (typeof text === "function") {
|
|
1721
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1722
|
+
} else {
|
|
1723
|
+
helpStr = text;
|
|
1724
|
+
}
|
|
1725
|
+
if (helpStr) {
|
|
1726
|
+
context.write(`${helpStr}
|
|
1727
|
+
`);
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
return this;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function outputHelpIfRequested(cmd, args) {
|
|
1734
|
+
const helpOption = cmd._hasHelpOption && args.find((arg) => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
|
|
1735
|
+
if (helpOption) {
|
|
1736
|
+
cmd.outputHelp();
|
|
1737
|
+
cmd._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
function incrementNodeInspectorPort(args) {
|
|
1741
|
+
return args.map((arg) => {
|
|
1742
|
+
if (!arg.startsWith("--inspect")) {
|
|
1743
|
+
return arg;
|
|
1744
|
+
}
|
|
1745
|
+
let debugOption;
|
|
1746
|
+
let debugHost = "127.0.0.1";
|
|
1747
|
+
let debugPort = "9229";
|
|
1748
|
+
let match;
|
|
1749
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1750
|
+
debugOption = match[1];
|
|
1751
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1752
|
+
debugOption = match[1];
|
|
1753
|
+
if (/^\d+$/.test(match[3])) {
|
|
1754
|
+
debugPort = match[3];
|
|
1755
|
+
} else {
|
|
1756
|
+
debugHost = match[3];
|
|
1757
|
+
}
|
|
1758
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1759
|
+
debugOption = match[1];
|
|
1760
|
+
debugHost = match[3];
|
|
1761
|
+
debugPort = match[4];
|
|
1762
|
+
}
|
|
1763
|
+
if (debugOption && debugPort !== "0") {
|
|
1764
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1765
|
+
}
|
|
1766
|
+
return arg;
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
function getCommandAndParents(startCommand) {
|
|
1770
|
+
const result = [];
|
|
1771
|
+
for (let command = startCommand;command; command = command.parent) {
|
|
1772
|
+
result.push(command);
|
|
1773
|
+
}
|
|
1774
|
+
return result;
|
|
1775
|
+
}
|
|
1776
|
+
exports.Command = Command;
|
|
1777
|
+
});
|
|
1778
|
+
|
|
1779
|
+
// node_modules/commander/index.js
|
|
1780
|
+
var require_commander = __commonJS((exports, module) => {
|
|
1781
|
+
var { Argument } = require_argument();
|
|
1782
|
+
var { Command } = require_command();
|
|
1783
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1784
|
+
var { Help } = require_help();
|
|
1785
|
+
var { Option } = require_option();
|
|
1786
|
+
exports = module.exports = new Command;
|
|
1787
|
+
exports.program = exports;
|
|
1788
|
+
exports.Argument = Argument;
|
|
1789
|
+
exports.Command = Command;
|
|
1790
|
+
exports.CommanderError = CommanderError;
|
|
1791
|
+
exports.Help = Help;
|
|
1792
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1793
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1794
|
+
exports.Option = Option;
|
|
1795
|
+
});
|
|
1796
|
+
|
|
1797
|
+
// node_modules/commander/esm.mjs
|
|
1798
|
+
var import__ = __toESM(require_commander(), 1);
|
|
1799
|
+
var {
|
|
1800
|
+
program,
|
|
1801
|
+
createCommand,
|
|
1802
|
+
createArgument,
|
|
1803
|
+
createOption,
|
|
1804
|
+
CommanderError,
|
|
1805
|
+
InvalidArgumentError,
|
|
1806
|
+
InvalidOptionArgumentError,
|
|
1807
|
+
Command,
|
|
1808
|
+
Argument,
|
|
1809
|
+
Option,
|
|
1810
|
+
Help
|
|
1811
|
+
} = import__.default;
|
|
1812
|
+
|
|
1813
|
+
// lib/package.ts
|
|
1814
|
+
import path from "path";
|
|
1815
|
+
import fs from "fs";
|
|
1816
|
+
function findPackageJson() {
|
|
1817
|
+
const cwd = import.meta.dir;
|
|
1818
|
+
let dir = cwd;
|
|
1819
|
+
while (dir !== "/") {
|
|
1820
|
+
const packageJson = path.join(dir, "package.json");
|
|
1821
|
+
if (fs.existsSync(packageJson)) {
|
|
1822
|
+
return packageJson;
|
|
1823
|
+
}
|
|
1824
|
+
dir = path.dirname(dir);
|
|
1825
|
+
}
|
|
1826
|
+
return null;
|
|
1827
|
+
}
|
|
1828
|
+
async function getPackageJson() {
|
|
1829
|
+
const packagePath = findPackageJson();
|
|
1830
|
+
if (!packagePath) {
|
|
1831
|
+
throw new Error(`No package.json found in ${import.meta.dir} or any parent directory`);
|
|
1832
|
+
}
|
|
1833
|
+
const packageJsonText = fs.readFileSync(packagePath, "utf8");
|
|
1834
|
+
return JSON.parse(packageJsonText);
|
|
1835
|
+
}
|
|
1836
|
+
var packageJsonPromise = getPackageJson();
|
|
1837
|
+
async function getPackageVersion() {
|
|
1838
|
+
const packageJson = await packageJsonPromise;
|
|
1839
|
+
return packageJson.version;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
// lib/spawn.ts
|
|
1843
|
+
var defaultOptions = {
|
|
1844
|
+
expectQuiet: false
|
|
1845
|
+
};
|
|
1846
|
+
async function spawn(args, options = defaultOptions) {
|
|
1847
|
+
const proc = Bun.spawn(args, { stdout: "pipe", stderr: "pipe" });
|
|
1848
|
+
const stdout = new Response(proc.stdout);
|
|
1849
|
+
const stderr = new Response(proc.stderr);
|
|
1850
|
+
const [out, err, exitCode, signal] = await Promise.all([stdout.text(), stderr.text(), proc.exitCode, proc.signalCode]);
|
|
1851
|
+
let code = 0;
|
|
1852
|
+
if (exitCode !== null) {
|
|
1853
|
+
code = exitCode;
|
|
1854
|
+
}
|
|
1855
|
+
if (!out && !err && !options.expectQuiet) {
|
|
1856
|
+
console.warn(`No output from ${args.join(" ")}`);
|
|
1857
|
+
}
|
|
1858
|
+
return { out: out.trim(), err: err.trim(), code };
|
|
1859
|
+
}
|
|
1860
|
+
async function doCommand(args, options = defaultOptions) {
|
|
1861
|
+
const { out, err } = await spawn(args, options);
|
|
1862
|
+
if (err)
|
|
1863
|
+
console.error(err);
|
|
1864
|
+
return out;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// lib/git.ts
|
|
1868
|
+
async function getConfig(key, options = defaultOptions) {
|
|
1869
|
+
return doCommand(["git", "config", "--get", key], options);
|
|
1870
|
+
}
|
|
1871
|
+
async function createBranch(name) {
|
|
1872
|
+
return doCommand(["git", "checkout", "-b", name]);
|
|
1873
|
+
}
|
|
1874
|
+
async function getCurrentBranch() {
|
|
1875
|
+
return doCommand(["git", "rev-parse", "--abbrev-ref", "HEAD"]);
|
|
1876
|
+
}
|
|
1877
|
+
async function getRemote() {
|
|
1878
|
+
return doCommand(["git", "ls-remote", "--get-url", "origin"]);
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// lib/confluence/config.ts
|
|
1882
|
+
var gitEmailP = getConfig("user.email");
|
|
1883
|
+
var jiraEmailP = getConfig("jira.user");
|
|
1884
|
+
var confluenceEmailP = getConfig("confluence.user", { expectQuiet: true });
|
|
1885
|
+
var jiraHostP = getConfig("jira.host");
|
|
1886
|
+
var confluenceHostP = getConfig("confluence.host", { expectQuiet: true });
|
|
1887
|
+
var jiraTokenP = getConfig("jira.token");
|
|
1888
|
+
var confluenceTokenP = getConfig("confluence.token", { expectQuiet: true });
|
|
1889
|
+
async function getConfluenceConfig() {
|
|
1890
|
+
const host = await confluenceHostP || await jiraHostP;
|
|
1891
|
+
if (!host)
|
|
1892
|
+
throw new Error("confluence.host or jira.host not in git config");
|
|
1893
|
+
const user = await confluenceEmailP || await jiraEmailP || await gitEmailP;
|
|
1894
|
+
if (!user)
|
|
1895
|
+
throw new Error("confluence.user, jira.user, or user.email not in git config");
|
|
1896
|
+
const pat = await confluenceTokenP || await jiraTokenP;
|
|
1897
|
+
if (!pat)
|
|
1898
|
+
throw new Error("confluence.token or jira.token not in git config");
|
|
1899
|
+
const token = Buffer.from(`${user}:${pat}`).toString("base64");
|
|
1900
|
+
return { host, token };
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
// lib/confluence/api.ts
|
|
1904
|
+
function getNextLink(link) {
|
|
1905
|
+
if (!link) {
|
|
1906
|
+
return;
|
|
1907
|
+
}
|
|
1908
|
+
const regex = /<([^>]+)>; rel="next"/;
|
|
1909
|
+
const match = link.match(regex);
|
|
1910
|
+
const next = match ? match[1] : undefined;
|
|
1911
|
+
return next;
|
|
1912
|
+
}
|
|
1913
|
+
async function confluenceApi(endpoint) {
|
|
1914
|
+
if (endpoint.startsWith("/")) {
|
|
1915
|
+
console.warn(`confluenceApi: endpoint ${endpoint} starts with /, removing it`);
|
|
1916
|
+
endpoint = endpoint.slice(1);
|
|
1917
|
+
}
|
|
1918
|
+
const method = "GET";
|
|
1919
|
+
const { host, token } = await getConfluenceConfig();
|
|
1920
|
+
const base = `https://${host}/wiki/api/v2`;
|
|
1921
|
+
const uri = `${base}/${endpoint}`;
|
|
1922
|
+
const auth = `Basic ${token}`;
|
|
1923
|
+
const headers = new Headers;
|
|
1924
|
+
headers.append("Authorization", auth);
|
|
1925
|
+
headers.append("Accept", "application/json");
|
|
1926
|
+
const options = {
|
|
1927
|
+
method,
|
|
1928
|
+
headers
|
|
1929
|
+
};
|
|
1930
|
+
let request = new Request(uri, options);
|
|
1931
|
+
const response = await fetch(request);
|
|
1932
|
+
let link = getNextLink(response.headers.get("Link"));
|
|
1933
|
+
const body = await response.json();
|
|
1934
|
+
if (!body.results) {
|
|
1935
|
+
return body;
|
|
1936
|
+
}
|
|
1937
|
+
let result = body.results;
|
|
1938
|
+
const origin = `https://${host}`;
|
|
1939
|
+
while (link) {
|
|
1940
|
+
const url = link.startsWith("/") ? `${origin}${link}` : link;
|
|
1941
|
+
let request2 = new Request(url, options);
|
|
1942
|
+
const next_response = await fetch(request2);
|
|
1943
|
+
link = getNextLink(next_response.headers.get("Link"));
|
|
1944
|
+
const next_body = await next_response.json();
|
|
1945
|
+
if (next_body.results) {
|
|
1946
|
+
result = result.concat(next_body.results);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
return result;
|
|
1950
|
+
}
|
|
1951
|
+
async function confluenceApiWrite(endpoint, method, body) {
|
|
1952
|
+
if (endpoint.startsWith("/")) {
|
|
1953
|
+
console.warn(`confluenceApiWrite: endpoint ${endpoint} starts with /, removing it`);
|
|
1954
|
+
endpoint = endpoint.slice(1);
|
|
1955
|
+
}
|
|
1956
|
+
const { host, token } = await getConfluenceConfig();
|
|
1957
|
+
const base = `https://${host}/wiki/api/v2`;
|
|
1958
|
+
const uri = `${base}/${endpoint}`;
|
|
1959
|
+
const auth = `Basic ${token}`;
|
|
1960
|
+
const headers = new Headers;
|
|
1961
|
+
headers.append("Authorization", auth);
|
|
1962
|
+
headers.append("Accept", "application/json");
|
|
1963
|
+
headers.append("Content-Type", "application/json");
|
|
1964
|
+
const options = {
|
|
1965
|
+
method,
|
|
1966
|
+
headers,
|
|
1967
|
+
body: JSON.stringify(body)
|
|
1968
|
+
};
|
|
1969
|
+
const request = new Request(uri, options);
|
|
1970
|
+
const response = await fetch(request);
|
|
1971
|
+
if (!response.ok) {
|
|
1972
|
+
const text = await response.text();
|
|
1973
|
+
throw new Error(`Confluence API ${method} ${endpoint} failed (${response.status}): ${text}`);
|
|
1974
|
+
}
|
|
1975
|
+
const result = await response.json();
|
|
1976
|
+
return result;
|
|
1977
|
+
}
|
|
1978
|
+
async function confluenceSearch(cql) {
|
|
1979
|
+
const { host, token } = await getConfluenceConfig();
|
|
1980
|
+
const base = `https://${host}/wiki/rest/api`;
|
|
1981
|
+
const auth = `Basic ${token}`;
|
|
1982
|
+
const headers = new Headers;
|
|
1983
|
+
headers.append("Authorization", auth);
|
|
1984
|
+
headers.append("Accept", "application/json");
|
|
1985
|
+
const options = { method: "GET", headers };
|
|
1986
|
+
const origin = `https://${host}`;
|
|
1987
|
+
let uri = `${base}/search?cql=${encodeURIComponent(cql)}&limit=25`;
|
|
1988
|
+
let allResults = [];
|
|
1989
|
+
while (uri) {
|
|
1990
|
+
const request = new Request(uri, options);
|
|
1991
|
+
const response = await fetch(request);
|
|
1992
|
+
const body = await response.json();
|
|
1993
|
+
if (body.results) {
|
|
1994
|
+
allResults = allResults.concat(body.results);
|
|
1995
|
+
}
|
|
1996
|
+
const next = body._links?.next;
|
|
1997
|
+
uri = next ? next.startsWith("/") ? `${origin}${next}` : next : "";
|
|
1998
|
+
}
|
|
1999
|
+
return allResults;
|
|
2000
|
+
}
|
|
2001
|
+
async function confluenceApiV1(endpoint) {
|
|
2002
|
+
if (endpoint.startsWith("/")) {
|
|
2003
|
+
console.warn(`confluenceApiV1: endpoint ${endpoint} starts with /, removing it`);
|
|
2004
|
+
endpoint = endpoint.slice(1);
|
|
2005
|
+
}
|
|
2006
|
+
const method = "GET";
|
|
2007
|
+
const { host, token } = await getConfluenceConfig();
|
|
2008
|
+
const base = `https://${host}/wiki/rest/api`;
|
|
2009
|
+
const uri = `${base}/${endpoint}`;
|
|
2010
|
+
const auth = `Basic ${token}`;
|
|
2011
|
+
const headers = new Headers;
|
|
2012
|
+
headers.append("Authorization", auth);
|
|
2013
|
+
headers.append("Accept", "application/json");
|
|
2014
|
+
const options = {
|
|
2015
|
+
method,
|
|
2016
|
+
headers
|
|
2017
|
+
};
|
|
2018
|
+
const request = new Request(uri, options);
|
|
2019
|
+
const response = await fetch(request);
|
|
2020
|
+
const result = await response.json();
|
|
2021
|
+
return result;
|
|
2022
|
+
}
|
|
2023
|
+
// lib/is_main.ts
|
|
2024
|
+
import path2 from "path";
|
|
2025
|
+
function justBase(filename) {
|
|
2026
|
+
const ext = path2.extname(filename);
|
|
2027
|
+
const base = path2.basename(filename, ext);
|
|
2028
|
+
return base;
|
|
2029
|
+
}
|
|
2030
|
+
function isMain(self) {
|
|
2031
|
+
const arg1 = Bun.argv[1];
|
|
2032
|
+
const argv1Base = justBase(arg1);
|
|
2033
|
+
const selfBase = justBase(self);
|
|
2034
|
+
const result = argv1Base === selfBase;
|
|
2035
|
+
return result;
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
// bin/git-confluence-space-list.ts
|
|
2039
|
+
var version = await getPackageVersion();
|
|
2040
|
+
function create() {
|
|
2041
|
+
const program2 = new Command;
|
|
2042
|
+
program2.version(version).name("list").description("List Confluence spaces").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
2043
|
+
const spaces = await confluenceApi("spaces");
|
|
2044
|
+
if (options.verbose) {
|
|
2045
|
+
console.log(spaces);
|
|
2046
|
+
} else {
|
|
2047
|
+
for (const space of spaces) {
|
|
2048
|
+
console.log(`${space.key} ${space.name}`);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
return program2;
|
|
2053
|
+
}
|
|
2054
|
+
var git_confluence_space_list_default = create;
|
|
2055
|
+
if (isMain("git-confluence-space-list")) {
|
|
2056
|
+
await create().parseAsync(Bun.argv);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// bin/git-confluence-page-search.ts
|
|
2060
|
+
var version2 = await getPackageVersion();
|
|
2061
|
+
function create2() {
|
|
2062
|
+
const program2 = new Command;
|
|
2063
|
+
program2.version(version2).name("search").description("Search for Confluence pages by title (fuzzy by default)").argument("query", "Search query").option("-v, --verbose", "Verbose output").option("--exact", "Exact title match (uses v2 API)").option("--full-text", "Search page body content in addition to title").action(async (query, options) => {
|
|
2064
|
+
const { host } = await getConfluenceConfig();
|
|
2065
|
+
if (options.exact) {
|
|
2066
|
+
const pages = await confluenceApi(`pages?title=${encodeURIComponent(query)}`);
|
|
2067
|
+
if (options.verbose) {
|
|
2068
|
+
console.log(pages);
|
|
2069
|
+
} else {
|
|
2070
|
+
for (const page of pages) {
|
|
2071
|
+
const url = `https://${host}/wiki/spaces/${page.spaceId}/pages/${page.id}`;
|
|
2072
|
+
console.log(`${page.id} ${page.title} ${url}`);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
const field = options.fullText ? "text" : "title";
|
|
2078
|
+
const cql = `type=page AND ${field} ~ "${query}"`;
|
|
2079
|
+
const results = await confluenceSearch(cql);
|
|
2080
|
+
if (options.verbose) {
|
|
2081
|
+
console.log(results);
|
|
2082
|
+
} else {
|
|
2083
|
+
for (const result of results) {
|
|
2084
|
+
const id = result.content.id;
|
|
2085
|
+
const title = result.content.title;
|
|
2086
|
+
const url = `https://${host}${result.url}`;
|
|
2087
|
+
console.log(`${id} ${title} ${url}`);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
});
|
|
2091
|
+
return program2;
|
|
2092
|
+
}
|
|
2093
|
+
var git_confluence_page_search_default = create2;
|
|
2094
|
+
if (isMain("git-confluence-page-search")) {
|
|
2095
|
+
await create2().parseAsync(Bun.argv);
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
// bin/git-confluence-page-show.ts
|
|
2099
|
+
var version3 = await getPackageVersion();
|
|
2100
|
+
function create3() {
|
|
2101
|
+
const program2 = new Command;
|
|
2102
|
+
program2.version(version3).name("show").description("Show information about a Confluence page").argument("id", "Page ID").option("-v, --verbose", "Verbose output").option("-b, --body-format <format>", "Include page body (storage or atlas_doc_format)").option("--body-only", "Output only the body content value (requires --body-format)").action(async (id, options) => {
|
|
2103
|
+
let endpoint = `pages/${id}`;
|
|
2104
|
+
if (options.bodyFormat) {
|
|
2105
|
+
endpoint += `?body-format=${options.bodyFormat}`;
|
|
2106
|
+
}
|
|
2107
|
+
const page = await confluenceApi(endpoint);
|
|
2108
|
+
if (options.bodyOnly) {
|
|
2109
|
+
if (!options.bodyFormat) {
|
|
2110
|
+
console.error("--body-only requires --body-format");
|
|
2111
|
+
process.exit(1);
|
|
2112
|
+
}
|
|
2113
|
+
const body = page.body;
|
|
2114
|
+
const content = options.bodyFormat === "storage" ? body?.storage?.value : body?.atlas_doc_format?.value;
|
|
2115
|
+
if (content) {
|
|
2116
|
+
console.log(content);
|
|
2117
|
+
} else {
|
|
2118
|
+
console.error("No body content returned");
|
|
2119
|
+
process.exit(1);
|
|
2120
|
+
}
|
|
2121
|
+
} else if (options.verbose) {
|
|
2122
|
+
console.log(page);
|
|
2123
|
+
} else {
|
|
2124
|
+
const { host } = await getConfluenceConfig();
|
|
2125
|
+
const url = `https://${host}/wiki/spaces/${page.spaceId}/pages/${page.id}`;
|
|
2126
|
+
const result = { id: page.id, title: page.title, spaceId: page.spaceId, url };
|
|
2127
|
+
if (page.body?.storage?.value) {
|
|
2128
|
+
result.bodyLength = page.body.storage.value.length;
|
|
2129
|
+
}
|
|
2130
|
+
console.log(result);
|
|
2131
|
+
}
|
|
2132
|
+
});
|
|
2133
|
+
return program2;
|
|
2134
|
+
}
|
|
2135
|
+
var git_confluence_page_show_default = create3;
|
|
2136
|
+
if (isMain("git-confluence-page-show")) {
|
|
2137
|
+
await create3().parseAsync(Bun.argv);
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
// bin/git-confluence-page-update.ts
|
|
2141
|
+
var version4 = await getPackageVersion();
|
|
2142
|
+
async function readStdin() {
|
|
2143
|
+
const chunks = [];
|
|
2144
|
+
for await (const chunk of Bun.stdin.stream()) {
|
|
2145
|
+
chunks.push(Buffer.from(chunk));
|
|
2146
|
+
}
|
|
2147
|
+
return Buffer.concat(chunks).toString("utf-8");
|
|
2148
|
+
}
|
|
2149
|
+
function create4() {
|
|
2150
|
+
const program2 = new Command;
|
|
2151
|
+
program2.version(version4).name("update").description("Update a Confluence page").argument("id", "Page ID").option("-t, --title <title>", "New page title (defaults to current title)").option("-f, --file <path>", "Read body content from file (default: stdin)").option("-m, --message <message>", "Version message").option("-v, --verbose", "Verbose output").action(async (id, options) => {
|
|
2152
|
+
const current = await confluenceApi(`pages/${id}`);
|
|
2153
|
+
let content;
|
|
2154
|
+
if (options.file) {
|
|
2155
|
+
const file = Bun.file(options.file);
|
|
2156
|
+
content = await file.text();
|
|
2157
|
+
} else {
|
|
2158
|
+
content = await readStdin();
|
|
2159
|
+
}
|
|
2160
|
+
if (!content.trim()) {
|
|
2161
|
+
console.error("No content provided. Pipe content via stdin or use --file.");
|
|
2162
|
+
process.exit(1);
|
|
2163
|
+
}
|
|
2164
|
+
const title = options.title || current.title;
|
|
2165
|
+
const nextVersion = current.version.number + 1;
|
|
2166
|
+
const body = {
|
|
2167
|
+
id,
|
|
2168
|
+
status: "current",
|
|
2169
|
+
title,
|
|
2170
|
+
body: {
|
|
2171
|
+
representation: "storage",
|
|
2172
|
+
value: content
|
|
2173
|
+
},
|
|
2174
|
+
version: {
|
|
2175
|
+
number: nextVersion,
|
|
2176
|
+
message: options.message || ""
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
const result = await confluenceApiWrite(`pages/${id}`, "PUT", body);
|
|
2180
|
+
if (options.verbose) {
|
|
2181
|
+
console.log(result);
|
|
2182
|
+
} else {
|
|
2183
|
+
console.log(`Updated page ${result.id} "${result.title}" to version ${result.version.number}`);
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2186
|
+
return program2;
|
|
2187
|
+
}
|
|
2188
|
+
var git_confluence_page_update_default = create4;
|
|
2189
|
+
if (isMain("git-confluence-page-update")) {
|
|
2190
|
+
await create4().parseAsync(Bun.argv);
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// bin/git-confluence-page.ts
|
|
2194
|
+
var version5 = await getPackageVersion();
|
|
2195
|
+
function create5() {
|
|
2196
|
+
const program2 = new Command;
|
|
2197
|
+
program2.version(version5).name("page").description("Commands for working with Confluence pages").addCommand(git_confluence_page_search_default()).addCommand(git_confluence_page_show_default()).addCommand(git_confluence_page_update_default()).action(() => program2.help());
|
|
2198
|
+
return program2;
|
|
2199
|
+
}
|
|
2200
|
+
var git_confluence_page_default = create5;
|
|
2201
|
+
if (isMain("git-confluence-page")) {
|
|
2202
|
+
await create5().parseAsync(Bun.argv);
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
// bin/git-confluence-space.ts
|
|
2206
|
+
var version6 = await getPackageVersion();
|
|
2207
|
+
function create6() {
|
|
2208
|
+
const program2 = new Command;
|
|
2209
|
+
program2.version(version6).name("space").description("Commands for working with Confluence spaces").addCommand(git_confluence_space_list_default()).action(() => program2.help());
|
|
2210
|
+
return program2;
|
|
2211
|
+
}
|
|
2212
|
+
var git_confluence_space_default = create6;
|
|
2213
|
+
if (isMain("git-confluence-space")) {
|
|
2214
|
+
await create6().parseAsync(Bun.argv);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// bin/git-confluence-whoami.ts
|
|
2218
|
+
var version7 = await getPackageVersion();
|
|
2219
|
+
function create7() {
|
|
2220
|
+
const program2 = new Command;
|
|
2221
|
+
program2.version(version7).name("whoami").description("Show the current Confluence user").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
2222
|
+
const myself = await confluenceApiV1("user/current");
|
|
2223
|
+
if (options.verbose) {
|
|
2224
|
+
console.log(myself);
|
|
2225
|
+
} else {
|
|
2226
|
+
const { displayName, email, accountId } = myself;
|
|
2227
|
+
console.log({ displayName, email, accountId });
|
|
2228
|
+
}
|
|
2229
|
+
});
|
|
2230
|
+
return program2;
|
|
2231
|
+
}
|
|
2232
|
+
var git_confluence_whoami_default = create7;
|
|
2233
|
+
if (isMain("git-confluence-whoami")) {
|
|
2234
|
+
await create7().parseAsync(Bun.argv);
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
// bin/git-confluence.ts
|
|
2238
|
+
var version8 = await getPackageVersion();
|
|
2239
|
+
function create8() {
|
|
2240
|
+
const program2 = new Command;
|
|
2241
|
+
program2.version(version8).name("confluence").description("Commands for working with Confluence").addCommand(git_confluence_whoami_default()).addCommand(git_confluence_space_default()).addCommand(git_confluence_page_default());
|
|
2242
|
+
return program2;
|
|
2243
|
+
}
|
|
2244
|
+
var git_confluence_default = create8;
|
|
2245
|
+
if (isMain("git-confluence")) {
|
|
2246
|
+
await create8().parseAsync(Bun.argv);
|
|
2247
|
+
}
|
|
2248
|
+
export {
|
|
2249
|
+
git_confluence_default as default,
|
|
2250
|
+
create8 as create
|
|
2251
|
+
};
|