@bemoje/cli 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +475 -0
- package/lib/index.cjs +61 -0
- package/lib/index.d.cts +6 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +8 -0
- package/lib/lib/Command.cjs +450 -0
- package/lib/lib/Command.d.cts +1 -0
- package/lib/lib/Command.d.ts +1 -0
- package/lib/lib/Command.js +443 -0
- package/lib/lib/Help.cjs +552 -0
- package/lib/lib/Help.d.cts +1 -0
- package/lib/lib/Help.d.ts +1 -0
- package/lib/lib/Help.js +545 -0
- package/lib/lib/helpers/findCommand.cjs +14 -0
- package/lib/lib/helpers/findCommand.d.cts +8 -0
- package/lib/lib/helpers/findCommand.d.ts +8 -0
- package/lib/lib/helpers/findCommand.js +11 -0
- package/lib/lib/helpers/findOption.cjs +16 -0
- package/lib/lib/helpers/findOption.d.cts +8 -0
- package/lib/lib/helpers/findOption.d.ts +8 -0
- package/lib/lib/helpers/findOption.js +14 -0
- package/lib/lib/helpers/getCommandAncestors.cjs +12 -0
- package/lib/lib/helpers/getCommandAncestors.d.cts +8 -0
- package/lib/lib/helpers/getCommandAncestors.d.ts +8 -0
- package/lib/lib/helpers/getCommandAncestors.js +9 -0
- package/lib/lib/helpers/getCommandAndAncestors.cjs +15 -0
- package/lib/lib/helpers/getCommandAndAncestors.d.cts +8 -0
- package/lib/lib/helpers/getCommandAndAncestors.d.ts +8 -0
- package/lib/lib/helpers/getCommandAndAncestors.js +13 -0
- package/lib/lib/helpers/parseOptionFlags.cjs +28 -0
- package/lib/lib/helpers/parseOptionFlags.d.cts +13 -0
- package/lib/lib/helpers/parseOptionFlags.d.ts +13 -0
- package/lib/lib/helpers/parseOptionFlags.js +26 -0
- package/lib/lib/types.cjs +2 -0
- package/lib/lib/types.d.cts +1 -0
- package/lib/lib/types.d.ts +1 -0
- package/lib/lib/types.js +1 -0
- package/package.json +144 -24
- package/index.d.ts +0 -711
- package/index.mjs +0 -1537
package/lib/lib/Help.cjs
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var C = require('ansi-colors');
|
|
4
|
+
var decorators = require('@mono/decorators');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var C__default = /*#__PURE__*/_interopDefault(C);
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
13
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
16
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
17
|
+
}
|
|
18
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
19
|
+
function _ts_metadata(k, v) {
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
|
+
}
|
|
22
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
23
|
+
class Help {
|
|
24
|
+
static {
|
|
25
|
+
__name(this, "Help");
|
|
26
|
+
}
|
|
27
|
+
cmd;
|
|
28
|
+
/** output helpWidth, long lines are wrapped to fit */
|
|
29
|
+
helpWidth = process.stdout.isTTY ? process.stdout.columns : 80;
|
|
30
|
+
minWidthToWrap = 40;
|
|
31
|
+
sortSubcommands = true;
|
|
32
|
+
sortOptions = true;
|
|
33
|
+
usageDisplayOptionsAs = "[opts]";
|
|
34
|
+
usageDisplaySubcommandAs = "[cmd]";
|
|
35
|
+
constructor(cmd) {
|
|
36
|
+
this.cmd = cmd;
|
|
37
|
+
Object.defineProperty(this, "cmd", {
|
|
38
|
+
enumerable: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
43
|
+
*/
|
|
44
|
+
visibleCommands() {
|
|
45
|
+
const res = Object.values(this.cmd.commands).filter((c) => {
|
|
46
|
+
return !c.hidden;
|
|
47
|
+
});
|
|
48
|
+
if (this.sortSubcommands) {
|
|
49
|
+
res.sort((a, b) => {
|
|
50
|
+
return a.name.localeCompare(b.name);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compare options for sort.
|
|
57
|
+
*/
|
|
58
|
+
compareOptions(a, b) {
|
|
59
|
+
const getSortKey = /* @__PURE__ */ __name((option) => {
|
|
60
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
61
|
+
}, "getSortKey");
|
|
62
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
66
|
+
*/
|
|
67
|
+
visibleOptions() {
|
|
68
|
+
const res = this.cmd.options.filter((option) => {
|
|
69
|
+
return !option.hidden;
|
|
70
|
+
});
|
|
71
|
+
if (this.sortOptions) {
|
|
72
|
+
res.sort(this.compareOptions);
|
|
73
|
+
}
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get an array of the arguments if any have a description.
|
|
78
|
+
*/
|
|
79
|
+
visibleArguments() {
|
|
80
|
+
return this.cmd.arguments.slice();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the command term to show in the list of subcommands.
|
|
84
|
+
*/
|
|
85
|
+
subcommandTerm(sub) {
|
|
86
|
+
const args = sub.arguments.map((arg) => {
|
|
87
|
+
return arg.usage;
|
|
88
|
+
}).join(" ");
|
|
89
|
+
return (sub.aliases[0] ? `${sub.aliases[0].padEnd(this.longestSubcommandAliasLength(), " ")} | ` : "") + sub.name + (sub.options.length ? ` ${this.usageDisplayOptionsAs}` : "") + (args ? ` ${args}` : "");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the option term to show in the list of options.
|
|
93
|
+
*/
|
|
94
|
+
optionTerm(option) {
|
|
95
|
+
return option.flags;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the argument term to show in the list of arguments.
|
|
99
|
+
*/
|
|
100
|
+
argumentTerm(argument) {
|
|
101
|
+
return argument.usage;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the longest subcommand primary alias length.
|
|
105
|
+
*/
|
|
106
|
+
longestSubcommandAliasLength() {
|
|
107
|
+
return Math.max(0, ...this.visibleCommands().map((c) => {
|
|
108
|
+
return c.aliases[0]?.length || 0;
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the longest subcommand term length.
|
|
113
|
+
*/
|
|
114
|
+
longestSubcommandTermLength() {
|
|
115
|
+
return this.visibleCommands().reduce((max, command) => {
|
|
116
|
+
return Math.max(max, this.displayWidth(this.styleSubcommandTerm(this.subcommandTerm(command))));
|
|
117
|
+
}, 0);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the longest option term length.
|
|
121
|
+
*/
|
|
122
|
+
longestOptionTermLength() {
|
|
123
|
+
return this.visibleOptions().reduce((max, option) => {
|
|
124
|
+
return Math.max(max, this.displayWidth(this.styleOptionTerm(this.optionTerm(option))));
|
|
125
|
+
}, 0);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the longest argument term length.
|
|
129
|
+
*/
|
|
130
|
+
longestArgumentTermLength() {
|
|
131
|
+
return this.visibleArguments().reduce((max, argument) => {
|
|
132
|
+
return Math.max(max, this.displayWidth(this.styleArgumentTerm(this.argumentTerm(argument))));
|
|
133
|
+
}, 0);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
137
|
+
*/
|
|
138
|
+
commandUsage() {
|
|
139
|
+
let path = "";
|
|
140
|
+
for (let ancestor = this.cmd.parent; ancestor; ancestor = ancestor.parent) {
|
|
141
|
+
path = `${ancestor.name} ${path}`;
|
|
142
|
+
}
|
|
143
|
+
return `${path + this.cmd.name} ${[
|
|
144
|
+
...Object.keys(this.cmd.commands).length ? [
|
|
145
|
+
this.usageDisplaySubcommandAs
|
|
146
|
+
] : [],
|
|
147
|
+
...this.cmd.options.length ? [
|
|
148
|
+
this.usageDisplayOptionsAs
|
|
149
|
+
] : [],
|
|
150
|
+
...this.cmd.arguments.map((arg) => {
|
|
151
|
+
return arg.required ? arg.variadic ? `<${arg.name}...>` : `<${arg.name}>` : arg.variadic ? `[${arg.name}...]` : `[${arg.name}]`;
|
|
152
|
+
})
|
|
153
|
+
].join(" ")}`.trim();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get the description for the command.
|
|
157
|
+
*/
|
|
158
|
+
commandDescription() {
|
|
159
|
+
let res = "";
|
|
160
|
+
if (this.cmd.aliases.length) {
|
|
161
|
+
res += `Aliases: ${this.cmd.aliases.join(", ")}`;
|
|
162
|
+
res += "\n\n";
|
|
163
|
+
}
|
|
164
|
+
res += this.cmd.description;
|
|
165
|
+
return res;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
169
|
+
* (Fallback to description for backwards compatibility.)
|
|
170
|
+
*/
|
|
171
|
+
subcommandDescription(sub) {
|
|
172
|
+
return sub.summary || (sub.description?.includes("\n") ? sub.description.trim().split("\n")[0] : sub.description.trim());
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get the option description to show in the list of options.
|
|
176
|
+
*/
|
|
177
|
+
optionDescription(option) {
|
|
178
|
+
const extraInfo = [];
|
|
179
|
+
if (option.choices) {
|
|
180
|
+
const choices = option.choices.length > 5 ? option.choices.slice(0, 5).concat([
|
|
181
|
+
"..."
|
|
182
|
+
]) : option.choices;
|
|
183
|
+
extraInfo.push(
|
|
184
|
+
// use stringify to match the display of the default value
|
|
185
|
+
`choices: ${choices.join(", ")}`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (option.defaultValue && !(Array.isArray(option.defaultValue) && option.defaultValue.length === 0)) {
|
|
189
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue).replaceAll('"', "")}`);
|
|
190
|
+
}
|
|
191
|
+
if (option.env !== void 0) {
|
|
192
|
+
extraInfo.push(`env: ${option.env}`);
|
|
193
|
+
}
|
|
194
|
+
if (extraInfo.length > 0) {
|
|
195
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
196
|
+
if (option.description) {
|
|
197
|
+
return `${option.description} ${extraDescription}`;
|
|
198
|
+
}
|
|
199
|
+
return extraDescription;
|
|
200
|
+
}
|
|
201
|
+
return option.description ?? "";
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get the argument description to show in the list of arguments.
|
|
205
|
+
*/
|
|
206
|
+
argumentDescription(argument) {
|
|
207
|
+
const extraInfo = [];
|
|
208
|
+
if (argument.choices) {
|
|
209
|
+
const choices = argument.choices.length > 5 ? argument.choices.slice(0, 5).concat([
|
|
210
|
+
"..."
|
|
211
|
+
]) : argument.choices;
|
|
212
|
+
extraInfo.push(
|
|
213
|
+
// use stringify to match the display of the default value
|
|
214
|
+
`choices: ${choices.join(", ")}`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (argument.defaultValue && !(Array.isArray(argument.defaultValue) && argument.defaultValue.length === 0)) {
|
|
218
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue).replaceAll('"', "")}`);
|
|
219
|
+
}
|
|
220
|
+
if (extraInfo.length > 0) {
|
|
221
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
222
|
+
if (argument.description) {
|
|
223
|
+
return `${argument.description} ${extraDescription}`;
|
|
224
|
+
}
|
|
225
|
+
return extraDescription;
|
|
226
|
+
}
|
|
227
|
+
return argument.description ?? "";
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
231
|
+
*/
|
|
232
|
+
formatItemList(heading, items) {
|
|
233
|
+
if (items.length === 0) {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
return [
|
|
237
|
+
this.styleTitle(heading),
|
|
238
|
+
...items,
|
|
239
|
+
""
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Group items by their help group heading.
|
|
244
|
+
*/
|
|
245
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
246
|
+
const result = /* @__PURE__ */ new Map();
|
|
247
|
+
unsortedItems.forEach((item) => {
|
|
248
|
+
const group = getGroup(item);
|
|
249
|
+
if (!result.has(group)) {
|
|
250
|
+
result.set(group, []);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
visibleItems.forEach((item) => {
|
|
254
|
+
const group = getGroup(item);
|
|
255
|
+
if (!result.has(group)) {
|
|
256
|
+
result.set(group, []);
|
|
257
|
+
}
|
|
258
|
+
result.get(group).push(item);
|
|
259
|
+
});
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
264
|
+
*/
|
|
265
|
+
displayWidth(str) {
|
|
266
|
+
const sgrPattern = /\u001b\[\d*(;\d*)*m/g;
|
|
267
|
+
return str.replaceAll(sgrPattern, "").length;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
271
|
+
*/
|
|
272
|
+
styleTitle(str) {
|
|
273
|
+
return C__default.default.yellow(str);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
|
|
277
|
+
*/
|
|
278
|
+
styleUsage(str) {
|
|
279
|
+
return str.split(" ").map((word, index, arr) => {
|
|
280
|
+
if (word === this.usageDisplaySubcommandAs) {
|
|
281
|
+
return C__default.default.green(word);
|
|
282
|
+
}
|
|
283
|
+
if (word === this.usageDisplayOptionsAs) {
|
|
284
|
+
return C__default.default.blue(word);
|
|
285
|
+
}
|
|
286
|
+
if (word[0] === "<") {
|
|
287
|
+
return C__default.default.red(word);
|
|
288
|
+
}
|
|
289
|
+
if (word[0] === "[") {
|
|
290
|
+
return C__default.default.cyan(word);
|
|
291
|
+
}
|
|
292
|
+
if (arr[index + 1]?.startsWith("[")) {
|
|
293
|
+
return C__default.default.magenta(word);
|
|
294
|
+
}
|
|
295
|
+
return this.styleCommandText(word);
|
|
296
|
+
}).join(" ");
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Style command descriptions for display in help output.
|
|
300
|
+
*/
|
|
301
|
+
styleCommandDescription(str) {
|
|
302
|
+
return this.styleDescriptionText(str);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Style option descriptions for display in help output.
|
|
306
|
+
*/
|
|
307
|
+
styleOptionDescription(str) {
|
|
308
|
+
return C__default.default.gray(this.styleDescriptionText(str));
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Style subcommand descriptions for display in help output.
|
|
312
|
+
*/
|
|
313
|
+
styleSubcommandDescription(str) {
|
|
314
|
+
return this.styleDescriptionText(str);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Style argument descriptions for display in help output.
|
|
318
|
+
*/
|
|
319
|
+
styleArgumentDescription(str) {
|
|
320
|
+
return C__default.default.gray(this.styleDescriptionText(str));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Base style used by descriptions. Override in subclass to apply custom formatting.
|
|
324
|
+
*/
|
|
325
|
+
styleDescriptionText(str) {
|
|
326
|
+
return C__default.default.gray(str);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Style option terms (flags) for display in help output.
|
|
330
|
+
*/
|
|
331
|
+
styleOptionTerm(str) {
|
|
332
|
+
return this.styleOptionText(str);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
|
|
336
|
+
*/
|
|
337
|
+
styleSubcommandTerm(str) {
|
|
338
|
+
const res = str.split(" ").map((word) => {
|
|
339
|
+
if (word === this.usageDisplayOptionsAs) {
|
|
340
|
+
return C__default.default.dim(word);
|
|
341
|
+
}
|
|
342
|
+
if (word[0] === "[" || word[0] === "<") {
|
|
343
|
+
return C__default.default.dim(word);
|
|
344
|
+
}
|
|
345
|
+
return this.styleSubcommandText(word);
|
|
346
|
+
}).join(" ");
|
|
347
|
+
const split = res.split("|");
|
|
348
|
+
if (split.length === 1) {
|
|
349
|
+
return res;
|
|
350
|
+
}
|
|
351
|
+
split[0] = C__default.default.green(split[0]);
|
|
352
|
+
return split.join("|");
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Style argument terms for display in help output.
|
|
356
|
+
*/
|
|
357
|
+
styleArgumentTerm(str) {
|
|
358
|
+
return this.styleArgumentText(str);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Base style used in terms and usage for options. Override in subclass to apply custom formatting.
|
|
362
|
+
*/
|
|
363
|
+
styleOptionText(str) {
|
|
364
|
+
return str;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Base style used in terms and usage for arguments. Override in subclass to apply custom formatting.
|
|
368
|
+
*/
|
|
369
|
+
styleArgumentText(str) {
|
|
370
|
+
return str;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Base style used in terms and usage for subcommands. Override in subclass to apply custom formatting.
|
|
374
|
+
*/
|
|
375
|
+
styleSubcommandText(str) {
|
|
376
|
+
return str;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Base style used in terms and usage for commands. Override in subclass to apply custom formatting.
|
|
380
|
+
*/
|
|
381
|
+
styleCommandText(str) {
|
|
382
|
+
return str;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Calculate the pad width from the maximum term length.
|
|
386
|
+
*/
|
|
387
|
+
padWidth() {
|
|
388
|
+
return Math.max(this.longestOptionTermLength(), this.longestSubcommandTermLength(), this.longestArgumentTermLength());
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
392
|
+
*/
|
|
393
|
+
preformatted(str) {
|
|
394
|
+
return /\n[^\S\n\r]/.test(str);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
398
|
+
*
|
|
399
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
400
|
+
* TTT DDD DDDD
|
|
401
|
+
* DD DDD
|
|
402
|
+
*/
|
|
403
|
+
formatItem(term, termWidth, description) {
|
|
404
|
+
const itemIndent = 2;
|
|
405
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
406
|
+
if (!description) {
|
|
407
|
+
return itemIndentStr + term;
|
|
408
|
+
}
|
|
409
|
+
const paddedTerm = term.padEnd(termWidth + term.length - this.displayWidth(term));
|
|
410
|
+
const spacerWidth = 2;
|
|
411
|
+
const helpWidth = this.helpWidth;
|
|
412
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
413
|
+
let formattedDescription;
|
|
414
|
+
if (remainingWidth < this.minWidthToWrap || this.preformatted(description)) {
|
|
415
|
+
formattedDescription = description;
|
|
416
|
+
} else {
|
|
417
|
+
const wrappedDescription = this.boxWrap(description, remainingWidth);
|
|
418
|
+
formattedDescription = wrappedDescription.replaceAll("\n", `
|
|
419
|
+
${" ".repeat(termWidth + spacerWidth)}`);
|
|
420
|
+
}
|
|
421
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replaceAll("\n", `
|
|
422
|
+
${itemIndentStr}`);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
426
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
427
|
+
*/
|
|
428
|
+
boxWrap(str, width) {
|
|
429
|
+
if (width < this.minWidthToWrap) {
|
|
430
|
+
return str;
|
|
431
|
+
}
|
|
432
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
433
|
+
const chunkPattern = /\s*\S+/g;
|
|
434
|
+
const wrappedLines = [];
|
|
435
|
+
rawLines.forEach((line) => {
|
|
436
|
+
const chunks = line.match(chunkPattern);
|
|
437
|
+
if (chunks === null) {
|
|
438
|
+
wrappedLines.push("");
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
let sumChunks = [
|
|
442
|
+
chunks.shift()
|
|
443
|
+
];
|
|
444
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
445
|
+
chunks.forEach((chunk) => {
|
|
446
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
447
|
+
if (sumWidth + visibleWidth <= width) {
|
|
448
|
+
sumChunks.push(chunk);
|
|
449
|
+
sumWidth += visibleWidth;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
wrappedLines.push(sumChunks.join(""));
|
|
453
|
+
const nextChunk = chunk.trimStart();
|
|
454
|
+
sumChunks = [
|
|
455
|
+
nextChunk
|
|
456
|
+
];
|
|
457
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
458
|
+
});
|
|
459
|
+
wrappedLines.push(sumChunks.join(""));
|
|
460
|
+
});
|
|
461
|
+
return wrappedLines.join("\n");
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Generate the built-in help text.
|
|
465
|
+
*/
|
|
466
|
+
render() {
|
|
467
|
+
let output = [
|
|
468
|
+
`${this.styleTitle("Usage:")} ${this.styleUsage(this.commandUsage())}`,
|
|
469
|
+
""
|
|
470
|
+
];
|
|
471
|
+
const des = this.commandDescription();
|
|
472
|
+
if (des.length > 0) {
|
|
473
|
+
output = output.concat([
|
|
474
|
+
this.boxWrap(this.styleCommandDescription(des), this.helpWidth),
|
|
475
|
+
""
|
|
476
|
+
]);
|
|
477
|
+
}
|
|
478
|
+
const argumentList = this.visibleArguments().map((argument) => {
|
|
479
|
+
return this.formatItem(this.styleArgumentTerm(this.argumentTerm(argument)), this.padWidth(), this.styleArgumentDescription(this.argumentDescription(argument)));
|
|
480
|
+
});
|
|
481
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList));
|
|
482
|
+
const optionGroups = this.groupItems(this.cmd.options, this.visibleOptions(), (option) => {
|
|
483
|
+
return option.group ?? "Options:";
|
|
484
|
+
});
|
|
485
|
+
optionGroups.forEach((options, group) => {
|
|
486
|
+
const optionList = options.map((option) => {
|
|
487
|
+
return this.formatItem(this.styleOptionTerm(this.optionTerm(option)), this.padWidth(), this.styleOptionDescription(this.optionDescription(option)));
|
|
488
|
+
});
|
|
489
|
+
output = output.concat(this.formatItemList(group, optionList));
|
|
490
|
+
});
|
|
491
|
+
const commandGroups = this.groupItems(Object.values(this.cmd.commands), this.visibleCommands(), (sub) => {
|
|
492
|
+
return sub.group || "Commands:";
|
|
493
|
+
});
|
|
494
|
+
commandGroups.forEach((commands, group) => {
|
|
495
|
+
const commandList = commands.map((sub) => {
|
|
496
|
+
return this.formatItem(this.styleSubcommandTerm(this.subcommandTerm(sub)), this.padWidth(), this.styleSubcommandDescription(this.subcommandDescription(sub)));
|
|
497
|
+
});
|
|
498
|
+
output = output.concat(this.formatItemList(group, commandList));
|
|
499
|
+
});
|
|
500
|
+
return output.join("\n");
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
_ts_decorate([
|
|
504
|
+
decorators.lazyProp,
|
|
505
|
+
_ts_metadata("design:type", Function),
|
|
506
|
+
_ts_metadata("design:paramtypes", []),
|
|
507
|
+
_ts_metadata("design:returntype", Array)
|
|
508
|
+
], Help.prototype, "visibleCommands", null);
|
|
509
|
+
_ts_decorate([
|
|
510
|
+
decorators.lazyProp,
|
|
511
|
+
_ts_metadata("design:type", Function),
|
|
512
|
+
_ts_metadata("design:paramtypes", []),
|
|
513
|
+
_ts_metadata("design:returntype", Array)
|
|
514
|
+
], Help.prototype, "visibleOptions", null);
|
|
515
|
+
_ts_decorate([
|
|
516
|
+
decorators.lazyProp,
|
|
517
|
+
_ts_metadata("design:type", Function),
|
|
518
|
+
_ts_metadata("design:paramtypes", []),
|
|
519
|
+
_ts_metadata("design:returntype", Array)
|
|
520
|
+
], Help.prototype, "visibleArguments", null);
|
|
521
|
+
_ts_decorate([
|
|
522
|
+
decorators.lazyProp,
|
|
523
|
+
_ts_metadata("design:type", Function),
|
|
524
|
+
_ts_metadata("design:paramtypes", []),
|
|
525
|
+
_ts_metadata("design:returntype", Number)
|
|
526
|
+
], Help.prototype, "longestSubcommandAliasLength", null);
|
|
527
|
+
_ts_decorate([
|
|
528
|
+
decorators.lazyProp,
|
|
529
|
+
_ts_metadata("design:type", Function),
|
|
530
|
+
_ts_metadata("design:paramtypes", []),
|
|
531
|
+
_ts_metadata("design:returntype", Number)
|
|
532
|
+
], Help.prototype, "longestSubcommandTermLength", null);
|
|
533
|
+
_ts_decorate([
|
|
534
|
+
decorators.lazyProp,
|
|
535
|
+
_ts_metadata("design:type", Function),
|
|
536
|
+
_ts_metadata("design:paramtypes", []),
|
|
537
|
+
_ts_metadata("design:returntype", Number)
|
|
538
|
+
], Help.prototype, "longestOptionTermLength", null);
|
|
539
|
+
_ts_decorate([
|
|
540
|
+
decorators.lazyProp,
|
|
541
|
+
_ts_metadata("design:type", Function),
|
|
542
|
+
_ts_metadata("design:paramtypes", []),
|
|
543
|
+
_ts_metadata("design:returntype", Number)
|
|
544
|
+
], Help.prototype, "longestArgumentTermLength", null);
|
|
545
|
+
_ts_decorate([
|
|
546
|
+
decorators.lazyProp,
|
|
547
|
+
_ts_metadata("design:type", Function),
|
|
548
|
+
_ts_metadata("design:paramtypes", []),
|
|
549
|
+
_ts_metadata("design:returntype", Number)
|
|
550
|
+
], Help.prototype, "padWidth", null);
|
|
551
|
+
|
|
552
|
+
exports.Help = Help;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { H as Help } from '../Command--Ojy3KHE.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { H as Help } from '../Command--Ojy3KHE.js';
|