@clerc/plugin-help 1.0.0-beta.29 → 1.0.0-beta.30

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 +14 -6
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DOUBLE_DASH, NoSuchCommandError, definePlugin, normalizeFlagValue, resolveCommand } from "@clerc/core";
1
+ import { DOUBLE_DASH, NoSuchCommandError, definePlugin, normalizeFlagValue, normalizeParameterValue, resolveCommand } from "@clerc/core";
2
2
  import stringWidth from "string-width";
3
3
  import textTable from "text-table";
4
4
  import * as yc from "yoctocolors";
@@ -111,7 +111,18 @@ var HelpRenderer = class {
111
111
  let usage = `$ ${_scriptName}`;
112
112
  if (command) {
113
113
  if (command.name) usage += ` ${command.name}`;
114
- if (command.parameters) usage += ` ${command.parameters.map((p) => typeof p === "string" ? p : p.key).join(" ")}`;
114
+ if (command.parameters) {
115
+ const doubleDashIndex = command.parameters.indexOf(DOUBLE_DASH);
116
+ const hasRequiredAfterDoubleDash = doubleDashIndex !== -1 && command.parameters.slice(doubleDashIndex + 1).some((p) => {
117
+ return (typeof p === "string" ? p : p.key).startsWith("<");
118
+ });
119
+ const items = command.parameters.map((p) => {
120
+ let key = typeof p === "string" ? p : p.key;
121
+ if (key === DOUBLE_DASH) key = hasRequiredAfterDoubleDash ? DOUBLE_DASH : `[${DOUBLE_DASH}]`;
122
+ return key;
123
+ });
124
+ usage += ` ${items.join(" ")}`;
125
+ }
115
126
  } else if (this._cli._commands.size > 0 && !(this._cli._commands.has("") && this._cli._commands.size === 1)) usage += this._cli._commands.has("") ? ` ${yc.dim("[command]")}` : ` ${yc.dim("<command>")}`;
116
127
  if (command?.flags && !objectIsEmpty(command.flags) || !objectIsEmpty(this._globalFlags)) usage += ` ${yc.dim("[flags]")}`;
117
128
  return {
@@ -124,11 +135,8 @@ var HelpRenderer = class {
124
135
  if (!command?.parameters || command.parameters.length === 0) return;
125
136
  return {
126
137
  title: "Parameters",
127
- body: splitTable(command.parameters.filter((p) => p !== DOUBLE_DASH).map((parameter) => {
128
- const key = typeof parameter === "string" ? parameter : parameter.key;
129
- const type = typeof parameter === "string" ? void 0 : parameter.type;
138
+ body: splitTable(command.parameters.map(normalizeParameterValue).filter((parameter) => parameter.key !== DOUBLE_DASH).map(({ key, type, description }) => {
130
139
  const formattedType = type ? this._formatters.formatTypeValue(type) : "string";
131
- const description = typeof parameter === "string" ? void 0 : parameter.description;
132
140
  return [
133
141
  yc.bold(key),
134
142
  yc.dim(formattedType),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "1.0.0-beta.29",
3
+ "version": "1.0.0-beta.30",
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.29",
56
- "@clerc/core": "1.0.0-beta.29",
57
- "@clerc/utils": "1.0.0-beta.29"
55
+ "@clerc/core": "1.0.0-beta.30",
56
+ "@clerc/utils": "1.0.0-beta.30",
57
+ "@clerc/parser": "1.0.0-beta.30"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@clerc/core": "*"