@clerc/plugin-help 1.0.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +16 -21
  2. 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, _getExamples, _notes) {
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._getExamples = _getExamples;
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._getExamples = () => command?.help?.examples;
75
+ this._examples = command?.help?.examples;
76
76
  this._notes = command?.help?.notes;
77
77
  }
78
78
  }
@@ -276,11 +276,10 @@ var HelpRenderer = class {
276
276
  };
277
277
  }
278
278
  renderExamples() {
279
- const examples = this._getExamples();
280
- if (!examples?.length) return;
279
+ if (!this._examples?.length) return;
281
280
  return {
282
281
  title: "Examples",
283
- body: splitTable(examples.map(([command, description]) => {
282
+ body: splitTable(this._examples.map(([command, description]) => {
284
283
  return [
285
284
  command,
286
285
  DELIMITER,
@@ -309,24 +308,12 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
309
308
  ...defaultFormatters,
310
309
  ...formatters
311
310
  };
312
- const generalHelpNotes = [
313
- "If no command is specified, show help for the CLI.",
314
- "If a command is specified, show help for the command.",
315
- flag && "-h is an alias for --help."
316
- ].filter(isTruthy);
317
- const getGeneralHelpExamples = () => [
318
- command && [`$ ${cli._scriptName} help`, "Show help"],
319
- command && [`$ ${cli._scriptName} help <command>`, "Show help for a specific command"],
320
- flag && [`$ ${cli._scriptName} <command> --help`, "Show help for a specific command"]
321
- ].filter(isTruthy);
322
- const effectiveNotes = notes ?? generalHelpNotes;
323
- const getEffectiveExamples = () => examples ?? getGeneralHelpExamples();
324
311
  function printHelp(s) {
325
312
  if (header) console.log(header);
326
313
  console.log(s);
327
314
  if (footer) console.log(footer);
328
315
  }
329
- const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups, getEffectiveExamples, effectiveNotes);
316
+ const renderer = new HelpRenderer(mergedFormatters, cli, cli._globalFlags, () => groups, examples, notes);
330
317
  function tryPrintSubcommandsHelp(commandName) {
331
318
  const subcommandsOutput = renderer.renderAvailableSubcommands(commandName);
332
319
  if (subcommandsOutput) {
@@ -338,8 +325,16 @@ const helpPlugin = ({ command = true, flag = true, showHelpWhenNoCommandSpecifie
338
325
  if (command) cli.command("help", "Show help", {
339
326
  parameters: ["[command...]"],
340
327
  help: {
341
- notes: generalHelpNotes,
342
- examples: getGeneralHelpExamples()
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)
343
338
  }
344
339
  }).on("help", (ctx) => {
345
340
  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.1",
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/core": "1.0.1",
56
- "@clerc/utils": "1.0.1",
57
- "@clerc/parser": "1.0.1"
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": "*"