@clerc/plugin-help 1.0.0-beta.15 → 1.0.0-beta.16

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
@@ -1,21 +1,24 @@
1
1
  import { Plugin } from "@clerc/core";
2
2
 
3
3
  //#region ../parser/src/types.d.ts
4
- type FlagDefaultValue<T = unknown> = T | ((() => T) & {
4
+ interface FlagDefaultValueFunction<T> {
5
+ (): T;
5
6
  display?: string;
6
- });
7
+ }
8
+ type FlagDefaultValue<T = unknown> = T | FlagDefaultValueFunction<T>;
7
9
  /**
8
10
  * Defines how a string input is converted to the target type T.
9
11
  *
10
12
  * @template T The target type.
11
13
  */
12
- type FlagTypeFunction<T = unknown> = ((value: string) => T) & {
14
+ interface FlagTypeFunction<T = unknown> {
15
+ (value: string): T;
13
16
  /**
14
17
  * Optional display name for the type, useful in help output.
15
18
  * If provided, this will be shown instead of the function name.
16
19
  */
17
20
  display?: string;
18
- };
21
+ }
19
22
  type FlagType<T = unknown> = FlagTypeFunction<T> | readonly [FlagTypeFunction<T>];
20
23
  //#endregion
21
24
  //#region src/types.d.ts
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ var HelpRenderer = class {
69
69
  return [
70
70
  this.renderHeader(),
71
71
  this.renderUsage(),
72
+ this.renderParameters(),
72
73
  this.renderCommands(),
73
74
  this.renderGlobalFlags(),
74
75
  this.renderCommandFlags(),
@@ -83,7 +84,7 @@ var HelpRenderer = class {
83
84
  renderHeader() {
84
85
  const { _name, _version, _description } = this._cli;
85
86
  const command = this._command;
86
- const description = command?.description ?? _description;
87
+ const description = command ? command.description : _description;
87
88
  const formattedCommandName = command?.name ? ` ${yc.cyan(command.name)}` : "";
88
89
  const headerLine = command ? `${yc.green(_name)}${formattedCommandName}` : `${yc.green(_name)} ${yc.yellow(formatVersion(_version))}`;
89
90
  const alias = command?.alias ? `Alias${toArray(command.alias).length > 1 ? "es" : ""}: ${toArray(command.alias).map((a) => yc.cyan(a)).join(", ")}` : void 0;
@@ -95,7 +96,7 @@ var HelpRenderer = class {
95
96
  let usage = `$ ${_scriptName}`;
96
97
  if (command) {
97
98
  if (command.name) usage += ` ${command.name}`;
98
- if (command.parameters) usage += ` ${command.parameters.join(" ")}`;
99
+ if (command.parameters) usage += ` ${command.parameters.map((p) => typeof p === "string" ? p : p.key).join(" ")}`;
99
100
  } else usage += this._cli._commands.has("") ? " [command]" : " <command>";
100
101
  if (command?.flags && !objectIsEmpty(command.flags) || !objectIsEmpty(this._globalFlags)) usage += " [flags]";
101
102
  return {
@@ -103,6 +104,23 @@ var HelpRenderer = class {
103
104
  body: [yc.magenta(usage)]
104
105
  };
105
106
  }
107
+ renderParameters() {
108
+ const command = this._command;
109
+ if (!command?.parameters || command.parameters.length === 0) return;
110
+ return {
111
+ title: "Parameters",
112
+ body: splitTable(command.parameters.map((parameter) => {
113
+ const key = typeof parameter === "string" ? parameter : parameter.key;
114
+ const constraint = typeof parameter === "string" ? void 0 : parameter.constraint;
115
+ const description = typeof parameter === "string" ? void 0 : parameter.description;
116
+ return [
117
+ yc.blue(key),
118
+ constraint?.display ? yc.gray(constraint.display) : void 0,
119
+ description
120
+ ].filter(isTruthy);
121
+ }))
122
+ };
123
+ }
106
124
  getSubcommands(parentCommandName) {
107
125
  const subcommands = /* @__PURE__ */ new Map();
108
126
  if (!parentCommandName) return subcommands;
@@ -132,7 +150,7 @@ var HelpRenderer = class {
132
150
  if (command.__isAlias || command.help?.show === false) continue;
133
151
  const group = command.help?.group;
134
152
  validateGroup(group, this._commandGroups, "command", command.name);
135
- const item = [`${yc.cyan(formatCommandName(command.name.slice(prefix.length)))}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description];
153
+ const item = [`${yc.cyan(formatCommandName(command.name.slice(prefix.length)))}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description].filter(isTruthy);
136
154
  if (command.name === "") rootCommand = item;
137
155
  else if (group && group !== DEFAULT_GROUP_KEY) {
138
156
  const groupItems = groupedCommands.get(group) ?? [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.16",
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.15",
56
- "@clerc/utils": "1.0.0-beta.15",
57
- "@clerc/core": "1.0.0-beta.15"
55
+ "@clerc/core": "1.0.0-beta.16",
56
+ "@clerc/parser": "1.0.0-beta.16",
57
+ "@clerc/utils": "1.0.0-beta.16"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@clerc/core": "*"