@clerc/plugin-help 1.0.0-beta.20 → 1.0.0-beta.22

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.d.ts CHANGED
@@ -19,11 +19,11 @@ interface TypeFunction<T = unknown> {
19
19
  */
20
20
  display?: string;
21
21
  }
22
- type FlagType<T = unknown> = TypeFunction<T> | readonly [TypeFunction<T>];
22
+ type TypeValue<T = unknown> = TypeFunction<T> | readonly [TypeFunction<T>];
23
23
  //#endregion
24
24
  //#region src/types.d.ts
25
25
  interface Formatters {
26
- formatFlagType: (type: FlagType) => string;
26
+ formatTypeValue: (type: TypeValue) => string;
27
27
  formatFlagDefault: <T>(value: FlagDefaultValue<T>) => string;
28
28
  }
29
29
  /**
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ const objectIsEmpty = (obj) => Object.keys(obj).length === 0;
13
13
 
14
14
  //#endregion
15
15
  //#region src/utils.ts
16
- function formatFlagType(type) {
16
+ function formatTypeValue(type) {
17
17
  if (typeof type === "function") return type.display ?? type.name;
18
18
  const innerType = type[0];
19
19
  return `Array<${innerType.displayName ?? innerType.name}>`;
@@ -30,7 +30,7 @@ function formatCommandName(name) {
30
30
  //#endregion
31
31
  //#region src/formatters.ts
32
32
  const defaultFormatters = {
33
- formatFlagType,
33
+ formatTypeValue,
34
34
  formatFlagDefault
35
35
  };
36
36
 
@@ -39,7 +39,7 @@ const defaultFormatters = {
39
39
  const DEFAULT_GROUP_KEY = "default";
40
40
  const table = (items) => textTable(items, { stringLength: stringWidth });
41
41
  const splitTable = (items) => table(items).split("\n");
42
- const DELIMITER = yc.yellow("-");
42
+ const DELIMITER = "-";
43
43
  const INDENT = " ".repeat(2);
44
44
  const withIndent = (str) => `${INDENT}${str}`;
45
45
  function groupDefinitionsToMap(definitions) {
@@ -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, _examples, _notes) {
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._examples = _examples;
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._examples = command?.help?.examples;
75
+ this._getExamples = () => command?.help?.examples;
76
76
  this._notes = command?.help?.notes;
77
77
  }
78
78
  }
@@ -80,7 +80,7 @@ var HelpRenderer = class {
80
80
  return sections.filter(isTruthy).map((section) => {
81
81
  const body = Array.isArray(section.body) ? section.body.filter((s) => s !== void 0).join("\n") : section.body;
82
82
  if (!section.title) return body;
83
- return `${yc.bold(section.title)}\n${body.split("\n").map(withIndent).join("\n")}`;
83
+ return `${yc.underline(yc.bold(section.title))}\n${body.split("\n").map(withIndent).join("\n")}`;
84
84
  }).join("\n\n");
85
85
  }
86
86
  render() {
@@ -100,9 +100,9 @@ var HelpRenderer = class {
100
100
  const { _name, _version, _description } = this._cli;
101
101
  const command = this._command;
102
102
  const description = command ? command.description : _description;
103
- const formattedCommandName = command?.name ? ` ${yc.cyan(command.name)}` : "";
104
- const headerLine = command ? `${yc.green(_name)}${formattedCommandName}` : `${yc.green(_name)} ${yc.yellow(formatVersion(_version))}`;
105
- const alias = command?.alias ? `Alias${toArray(command.alias).length > 1 ? "es" : ""}: ${toArray(command.alias).map((a) => yc.cyan(a)).join(", ")}` : void 0;
103
+ const formattedCommandName = command?.name ? ` ${yc.bold(command.name)}` : "";
104
+ const headerLine = command ? `${yc.dim(_name)}${formattedCommandName}` : `${yc.bold(_name)} ${formatVersion(_version)}`;
105
+ const alias = command?.alias ? `Alias${toArray(command.alias).length > 1 ? "es" : ""}: ${toArray(command.alias).map((a) => yc.bold(a)).join(", ")}` : void 0;
106
106
  return { body: [`${headerLine}${description ? ` ${DELIMITER} ${description}` : ""}`, alias] };
107
107
  }
108
108
  renderUsage() {
@@ -112,11 +112,11 @@ var HelpRenderer = class {
112
112
  if (command) {
113
113
  if (command.name) usage += ` ${command.name}`;
114
114
  if (command.parameters) usage += ` ${command.parameters.map((p) => typeof p === "string" ? p : p.key).join(" ")}`;
115
- } else usage += this._cli._commands.has("") ? " [command]" : " <command>";
115
+ } else if (this._cli._commands.size > 0 && !(this._cli._commands.has("") && this._cli._commands.size === 1)) usage += this._cli._commands.has("") ? " [command]" : " <command>";
116
116
  if (command?.flags && !objectIsEmpty(command.flags) || !objectIsEmpty(this._globalFlags)) usage += " [flags]";
117
117
  return {
118
118
  title: "Usage",
119
- body: [yc.magenta(usage)]
119
+ body: [usage]
120
120
  };
121
121
  }
122
122
  renderParameters() {
@@ -129,8 +129,8 @@ var HelpRenderer = class {
129
129
  const type = typeof parameter === "string" ? void 0 : parameter.type;
130
130
  const description = typeof parameter === "string" ? void 0 : parameter.description;
131
131
  return [
132
- yc.blue(key),
133
- type?.display ? yc.gray(type.display) : void 0,
132
+ yc.bold(key),
133
+ type ? this._formatters.formatTypeValue(type) : "string",
134
134
  description
135
135
  ].filter(isTruthy);
136
136
  }))
@@ -154,7 +154,7 @@ var HelpRenderer = class {
154
154
  if (command.__isAlias || command.help?.show === false) continue;
155
155
  const group = command.help?.group;
156
156
  validateGroup(group, this._commandGroups, "command", command.name);
157
- const item = [`${yc.cyan(formatCommandName(command.name.slice(prefix.length)))}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description].filter(isTruthy);
157
+ const item = [`${yc.bold(formatCommandName(command.name.slice(prefix.length)))}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description].filter(isTruthy);
158
158
  if (command.name === "") rootCommand = item;
159
159
  else if (group && group !== DEFAULT_GROUP_KEY) {
160
160
  const groupItems = groupedCommands.get(group) ?? [];
@@ -183,7 +183,7 @@ var HelpRenderer = class {
183
183
  const prefix = `${parentCommandName} `;
184
184
  const body = this.buildGroupedCommandsBody(subcommands, prefix);
185
185
  if (body.length === 0) return "";
186
- const sections = [{ body: `${yc.green(this._cli._name)} ${yc.cyan(parentCommandName)} not found` }, {
186
+ const sections = [{ body: `${this._cli._name} ${yc.bold(parentCommandName)} not found` }, {
187
187
  title: "Available Subcommands",
188
188
  body
189
189
  }];
@@ -211,12 +211,12 @@ var HelpRenderer = class {
211
211
  flag = normalizeFlagValue(flag);
212
212
  const flagName = formatFlagName(name);
213
213
  const aliases = (Array.isArray(flag.alias) ? flag.alias : flag.alias ? [flag.alias] : []).map(formatFlagName).join(", ");
214
- const type = this._formatters.formatFlagType(flag.type);
214
+ const type = this._formatters.formatTypeValue(flag.type);
215
215
  return [
216
- yc.blue([flagName, aliases].filter(Boolean).join(", ")),
217
- yc.gray(type),
216
+ yc.bold([flagName, aliases].filter(Boolean).join(", ")),
217
+ yc.dim(type),
218
218
  flag.description,
219
- flag.default !== void 0 && yc.gray(`[default: ${this._formatters.formatFlagDefault(flag.default)}]`)
219
+ flag.default !== void 0 && yc.dim(`[default: ${yc.bold(this._formatters.formatFlagDefault(flag.default))}]`)
220
220
  ].filter(isTruthy);
221
221
  }
222
222
  renderGroupedFlags(flags, groupMap, itemType) {
@@ -267,10 +267,11 @@ var HelpRenderer = class {
267
267
  };
268
268
  }
269
269
  renderExamples() {
270
- if (!this._examples?.length) return;
270
+ const examples = this._getExamples();
271
+ if (!examples?.length) return;
271
272
  return {
272
273
  title: "Examples",
273
- body: splitTable(this._examples.map(([command, description]) => {
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 generalHelpExamples = [
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 effectiveExamples = examples ?? generalHelpExamples;
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, effectiveExamples, effectiveNotes);
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: generalHelpExamples
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.20",
3
+ "version": "1.0.0-beta.22",
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.20",
56
- "@clerc/core": "1.0.0-beta.20",
57
- "@clerc/utils": "1.0.0-beta.20"
55
+ "@clerc/core": "1.0.0-beta.22",
56
+ "@clerc/utils": "1.0.0-beta.22",
57
+ "@clerc/parser": "1.0.0-beta.22"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@clerc/core": "*"