@clerc/plugin-help 1.0.0-beta.11 → 1.0.0-beta.12

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 +13 -12
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -18,6 +18,10 @@ function formatFlagType(type) {
18
18
  const innerType = type[0];
19
19
  return `Array<${innerType.displayName ?? innerType.name}>`;
20
20
  }
21
+ function formatCommandName(name) {
22
+ if (name === "") return "(root)";
23
+ return name;
24
+ }
21
25
 
22
26
  //#endregion
23
27
  //#region src/formatters.ts
@@ -97,18 +101,24 @@ var HelpRenderer = class {
97
101
  if (this._command || commands.size === 0) return;
98
102
  const groupedCommands = /* @__PURE__ */ new Map();
99
103
  const defaultCommands = [];
104
+ let rootCommand = [];
100
105
  for (const command of commands.values()) {
101
106
  if (command.__isAlias || command.help?.show === false) continue;
102
107
  const group = command.help?.group;
103
108
  validateGroup(group, this._commandGroups, "command", command.name);
104
- const item = [`${yc.cyan(command.name)}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description];
105
- if (group && group !== DEFAULT_GROUP_KEY) {
109
+ const item = [`${yc.cyan(formatCommandName(command.name))}${command.alias ? ` (${toArray(command.alias).join(", ")})` : ""}`, command.description];
110
+ if (command.name === "") rootCommand = item;
111
+ else if (group && group !== DEFAULT_GROUP_KEY) {
106
112
  const groupItems = groupedCommands.get(group) ?? [];
107
113
  groupItems.push(item);
108
114
  groupedCommands.set(group, groupItems);
109
115
  } else defaultCommands.push(item);
110
116
  }
111
117
  const body = [];
118
+ const defaultGroup = [];
119
+ if (rootCommand.length > 0) defaultGroup.push(rootCommand);
120
+ if (defaultCommands.length > 0) defaultGroup.push(...defaultCommands);
121
+ if (defaultGroup.length > 0) body.push(...splitTable(defaultGroup));
112
122
  for (const [key, name] of this._commandGroups) {
113
123
  const items = groupedCommands.get(key);
114
124
  if (items && items.length > 0) {
@@ -117,11 +127,6 @@ var HelpRenderer = class {
117
127
  body.push(...splitTable(items).map(withIndent));
118
128
  }
119
129
  }
120
- if (defaultCommands.length > 0) if (body.length > 0) {
121
- body.push("");
122
- body.push(`${yc.dim("Other")}`);
123
- body.push(...splitTable(defaultCommands).map(withIndent));
124
- } else body.push(...splitTable(defaultCommands));
125
130
  return {
126
131
  title: "Commands",
127
132
  body
@@ -152,6 +157,7 @@ var HelpRenderer = class {
152
157
  } else defaultFlags.push(item);
153
158
  }
154
159
  const body = [];
160
+ if (defaultFlags.length > 0) body.push(...splitTable(defaultFlags));
155
161
  for (const [key, name] of groupMap) {
156
162
  const items = groupedFlags.get(key);
157
163
  if (items && items.length > 0) {
@@ -160,11 +166,6 @@ var HelpRenderer = class {
160
166
  body.push(...splitTable(items).map(withIndent));
161
167
  }
162
168
  }
163
- if (defaultFlags.length > 0) if (body.length > 0) {
164
- body.push("");
165
- body.push(`${yc.dim("Other")}`);
166
- body.push(...splitTable(defaultFlags).map(withIndent));
167
- } else body.push(...splitTable(defaultFlags));
168
169
  return body;
169
170
  }
170
171
  renderCommandFlags() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc plugin help",
@@ -51,9 +51,9 @@
51
51
  "yoctocolors": "^2.1.2"
52
52
  },
53
53
  "devDependencies": {
54
- "@clerc/parser": "1.0.0-beta.11",
55
- "@clerc/core": "1.0.0-beta.11",
56
- "@clerc/utils": "1.0.0-beta.11"
54
+ "@clerc/core": "1.0.0-beta.12",
55
+ "@clerc/utils": "1.0.0-beta.12",
56
+ "@clerc/parser": "1.0.0-beta.12"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@clerc/core": "*"