@clerc/plugin-help 1.0.0-beta.20 → 1.0.0-beta.21
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 +10 -9
- 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, _getExamples, _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._getExamples = _getExamples;
|
|
70
70
|
this._notes = _notes;
|
|
71
71
|
}
|
|
72
72
|
setCommand(command) {
|
|
73
73
|
if (command) {
|
|
74
74
|
this._command = command;
|
|
75
|
-
this.
|
|
75
|
+
this._getExamples = () => command?.help?.examples;
|
|
76
76
|
this._notes = command?.help?.notes;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -267,10 +267,11 @@ var HelpRenderer = class {
|
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
renderExamples() {
|
|
270
|
-
|
|
270
|
+
const examples = this._getExamples();
|
|
271
|
+
if (!examples?.length) return;
|
|
271
272
|
return {
|
|
272
273
|
title: "Examples",
|
|
273
|
-
body: splitTable(
|
|
274
|
+
body: splitTable(examples.map(([command, description]) => {
|
|
274
275
|
return [
|
|
275
276
|
command,
|
|
276
277
|
DELIMITER,
|
|
@@ -304,18 +305,18 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
|
|
|
304
305
|
"If a command is specified, show help for the command.",
|
|
305
306
|
flag && "-h is an alias for --help."
|
|
306
307
|
].filter(isTruthy);
|
|
307
|
-
const
|
|
308
|
+
const getGeneralHelpExamples = () => [
|
|
308
309
|
command && [`$ ${cli._scriptName} help`, "Show help"],
|
|
309
310
|
command && [`$ ${cli._scriptName} help <command>`, "Show help for a specific command"],
|
|
310
311
|
flag && [`$ ${cli._scriptName} <command> --help`, "Show help for a specific command"]
|
|
311
312
|
].filter(isTruthy);
|
|
312
313
|
const effectiveNotes = notes ?? generalHelpNotes;
|
|
313
|
-
const
|
|
314
|
+
const getEffectiveExamples = () => examples ?? getGeneralHelpExamples();
|
|
314
315
|
function printHelp(s) {
|
|
315
316
|
if (banner) console.log(banner);
|
|
316
317
|
console.log(s);
|
|
317
318
|
}
|
|
318
|
-
const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups,
|
|
319
|
+
const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups, getEffectiveExamples, effectiveNotes);
|
|
319
320
|
function tryPrintSubcommandsHelp(commandName) {
|
|
320
321
|
const subcommandsOutput = renderer.renderAvailableSubcommands(commandName);
|
|
321
322
|
if (subcommandsOutput) {
|
|
@@ -328,7 +329,7 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
|
|
|
328
329
|
parameters: ["[command...]"],
|
|
329
330
|
help: {
|
|
330
331
|
notes: generalHelpNotes,
|
|
331
|
-
examples:
|
|
332
|
+
examples: getGeneralHelpExamples()
|
|
332
333
|
}
|
|
333
334
|
}).on("help", (ctx) => {
|
|
334
335
|
const commandName = ctx.parameters.command;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.21",
|
|
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/parser": "1.0.0-beta.
|
|
56
|
-
"@clerc/
|
|
57
|
-
"@clerc/
|
|
55
|
+
"@clerc/parser": "1.0.0-beta.21",
|
|
56
|
+
"@clerc/utils": "1.0.0-beta.21",
|
|
57
|
+
"@clerc/core": "1.0.0-beta.21"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@clerc/core": "*"
|