@clerc/plugin-help 1.0.0 → 1.0.2
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/dist/index.js +23 -27
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -61,18 +61,18 @@ var HelpRenderer = class {
|
|
|
61
61
|
get _globalFlagGroups() {
|
|
62
62
|
return groupDefinitionsToMap(this._getGroups().globalFlags);
|
|
63
63
|
}
|
|
64
|
-
constructor(_formatters, _cli, _globalFlags, _getGroups,
|
|
64
|
+
constructor(_formatters, _cli, _globalFlags, _getGroups, _examples, _notes) {
|
|
65
65
|
this._formatters = _formatters;
|
|
66
66
|
this._cli = _cli;
|
|
67
67
|
this._globalFlags = _globalFlags;
|
|
68
68
|
this._getGroups = _getGroups;
|
|
69
|
-
this.
|
|
69
|
+
this._examples = _examples;
|
|
70
70
|
this._notes = _notes;
|
|
71
71
|
}
|
|
72
72
|
setCommand(command) {
|
|
73
73
|
if (command) {
|
|
74
74
|
this._command = command;
|
|
75
|
-
this.
|
|
75
|
+
this._examples = command?.help?.examples;
|
|
76
76
|
this._notes = command?.help?.notes;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -97,11 +97,10 @@ var HelpRenderer = class {
|
|
|
97
97
|
return this.renderSections(sections);
|
|
98
98
|
}
|
|
99
99
|
renderHeader() {
|
|
100
|
-
const {
|
|
100
|
+
const { _scriptName, _version, _description } = this._cli;
|
|
101
101
|
const command = this._command;
|
|
102
102
|
const description = command ? command.description : _description;
|
|
103
|
-
const
|
|
104
|
-
const headerLine = command ? `${tint.dim(_name)}${formattedCommandName}` : `${tint.bold(_name)} ${formatVersion(_version)}`;
|
|
103
|
+
const headerLine = `${!command || command.name === "" ? tint.bold(_scriptName) : tint.dim(_scriptName)}${command?.name ? ` ${tint.bold(command.name)}` : ""}${command ? "" : ` ${formatVersion(_version)}`}`;
|
|
105
104
|
const alias = command?.alias ? `Alias${toArray(command.alias).length > 1 ? "es" : ""}: ${toArray(command.alias).map((a) => tint.bold(a)).join(", ")}` : void 0;
|
|
106
105
|
return { body: [`${headerLine}${description ? ` ${DELIMITER} ${description}` : ""}`, alias] };
|
|
107
106
|
}
|
|
@@ -192,7 +191,7 @@ var HelpRenderer = class {
|
|
|
192
191
|
const prefix = `${parentCommandName} `;
|
|
193
192
|
const body = this.buildGroupedCommandsBody(subcommands, prefix);
|
|
194
193
|
if (body.length === 0) return null;
|
|
195
|
-
const sections = [{ body: `${this._cli.
|
|
194
|
+
const sections = [{ body: `${this._cli._scriptName} ${tint.bold(parentCommandName)} not found` }, {
|
|
196
195
|
title: "Available Subcommands",
|
|
197
196
|
body
|
|
198
197
|
}];
|
|
@@ -277,11 +276,10 @@ var HelpRenderer = class {
|
|
|
277
276
|
};
|
|
278
277
|
}
|
|
279
278
|
renderExamples() {
|
|
280
|
-
|
|
281
|
-
if (!examples?.length) return;
|
|
279
|
+
if (!this._examples?.length) return;
|
|
282
280
|
return {
|
|
283
281
|
title: "Examples",
|
|
284
|
-
body: splitTable(
|
|
282
|
+
body: splitTable(this._examples.map(([command, description]) => {
|
|
285
283
|
return [
|
|
286
284
|
command,
|
|
287
285
|
DELIMITER,
|
|
@@ -310,24 +308,12 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
|
|
|
310
308
|
...defaultFormatters,
|
|
311
309
|
...formatters
|
|
312
310
|
};
|
|
313
|
-
const generalHelpNotes = [
|
|
314
|
-
"If no command is specified, show help for the CLI.",
|
|
315
|
-
"If a command is specified, show help for the command.",
|
|
316
|
-
flag && "-h is an alias for --help."
|
|
317
|
-
].filter(isTruthy);
|
|
318
|
-
const getGeneralHelpExamples = () => [
|
|
319
|
-
command && [`$ ${cli._scriptName} help`, "Show help"],
|
|
320
|
-
command && [`$ ${cli._scriptName} help <command>`, "Show help for a specific command"],
|
|
321
|
-
flag && [`$ ${cli._scriptName} <command> --help`, "Show help for a specific command"]
|
|
322
|
-
].filter(isTruthy);
|
|
323
|
-
const effectiveNotes = notes ?? generalHelpNotes;
|
|
324
|
-
const getEffectiveExamples = () => examples ?? getGeneralHelpExamples();
|
|
325
311
|
function printHelp(s) {
|
|
326
312
|
if (header) console.log(header);
|
|
327
313
|
console.log(s);
|
|
328
314
|
if (footer) console.log(footer);
|
|
329
315
|
}
|
|
330
|
-
const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups,
|
|
316
|
+
const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups, examples, notes);
|
|
331
317
|
function tryPrintSubcommandsHelp(commandName) {
|
|
332
318
|
const subcommandsOutput = renderer.renderAvailableSubcommands(commandName);
|
|
333
319
|
if (subcommandsOutput) {
|
|
@@ -339,8 +325,16 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
|
|
|
339
325
|
if (command) cli.command("help", "Show help", {
|
|
340
326
|
parameters: ["[command...]"],
|
|
341
327
|
help: {
|
|
342
|
-
notes:
|
|
343
|
-
|
|
328
|
+
notes: [
|
|
329
|
+
"If no command is specified, show help for the CLI.",
|
|
330
|
+
"If a command is specified, show help for the command.",
|
|
331
|
+
flag && "-h is an alias for --help."
|
|
332
|
+
].filter(isTruthy),
|
|
333
|
+
examples: [
|
|
334
|
+
command && [`$ ${cli._scriptName} help`, "Show help"],
|
|
335
|
+
command && [`$ ${cli._scriptName} help <command>`, "Show help for a specific command"],
|
|
336
|
+
flag && [`$ ${cli._scriptName} <command> --help`, "Show help for a specific command"]
|
|
337
|
+
].filter(isTruthy)
|
|
344
338
|
}
|
|
345
339
|
}).on("help", (ctx) => {
|
|
346
340
|
const commandName = ctx.parameters.command;
|
|
@@ -372,8 +366,10 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
|
|
|
372
366
|
}
|
|
373
367
|
renderer.setCommand(command$1);
|
|
374
368
|
printHelp(renderer.render());
|
|
375
|
-
} else if (showHelpWhenNoCommandSpecified && !ctx.command && ctx.rawParsed.parameters.length === 0)
|
|
376
|
-
|
|
369
|
+
} else if (showHelpWhenNoCommandSpecified && !ctx.command && ctx.rawParsed.parameters.length === 0) {
|
|
370
|
+
console.log("No command specified. Showing help:\n");
|
|
371
|
+
printHelp(renderer.render());
|
|
372
|
+
} else await next();
|
|
377
373
|
}
|
|
378
374
|
});
|
|
379
375
|
} });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc plugin help",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"kons": "^0.7.1",
|
|
55
|
-
"@clerc/
|
|
56
|
-
"@clerc/
|
|
57
|
-
"@clerc/
|
|
55
|
+
"@clerc/core": "1.0.2",
|
|
56
|
+
"@clerc/parser": "1.0.2",
|
|
57
|
+
"@clerc/utils": "1.0.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@clerc/core": "*"
|