@clerc/plugin-help 1.0.2 → 1.1.0

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/README.md CHANGED
@@ -2,23 +2,9 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@clerc/plugin-help?color=a1b858&label=)](https://www.npmjs.com/package/@clerc/plugin-help)
4
4
 
5
- Clerc plugin to add help command to your cli.
5
+ ## Documenation
6
6
 
7
- ## 📦 Installation
8
-
9
- ```bash
10
- $ npm install @clerc/plugin-help
11
- $ yarn add @clerc/plugin-help
12
- $ pnpm add @clerc/plugin-help
13
- ```
14
-
15
- ## 🚀 Usage
16
-
17
- ```ts
18
- import { helpPlugin } from "@clerc/plugin-help";
19
-
20
- cli.use(helpPlugin());
21
- ```
7
+ Read the [documentation](https://clerc.so1ve.dev/official-plugins/plugin-help.html) for more details.
22
8
 
23
9
  ## 📝 License
24
10
 
@@ -1,35 +1,15 @@
1
1
  import { Plugin } from "@clerc/core";
2
+ import { FlagDefaultValue, TypeValue } from "@clerc/parser";
2
3
 
3
- //#region ../parser/src/types.d.ts
4
- interface FlagDefaultValueFunction<T> {
5
- (): T;
6
- display?: string;
7
- }
8
- type FlagDefaultValue<T = unknown> = T | FlagDefaultValueFunction<T>;
9
- /**
10
- * Defines how a string input is converted to the target type T.
11
- *
12
- * @template T The target type.
13
- */
14
- interface TypeFunction<T = unknown> {
15
- (value: string): T;
16
- /**
17
- * Optional display name for the type, useful in help output.
18
- * If provided, this will be shown instead of the function name.
19
- */
20
- display?: string;
21
- }
22
- type TypeValue<T = unknown> = TypeFunction<T> | readonly [TypeFunction<T>];
23
- //#endregion
24
4
  //#region src/types.d.ts
25
5
  interface Formatters {
26
6
  formatTypeValue: (type: TypeValue) => string;
27
7
  formatFlagDefault: <T>(value: FlagDefaultValue<T>) => string;
28
8
  }
29
9
  /**
30
- * A group definition as a tuple of [key, displayName].
31
- * The key is used in help options to assign items to groups.
32
- * The displayName is shown in the help output.
10
+ * A group definition as a tuple of [key, displayName]. The key is used in help
11
+ * options to assign items to groups. The displayName is shown in the help
12
+ * output.
33
13
  */
34
14
  type GroupDefinition = [key: string, name: string];
35
15
  /**
@@ -37,18 +17,15 @@ type GroupDefinition = [key: string, name: string];
37
17
  */
38
18
  interface GroupsOptions {
39
19
  /**
40
- * Groups for commands.
41
- * Each group is defined as `[key, name]`.
20
+ * Groups for commands. Each group is defined as `[key, name]`.
42
21
  */
43
22
  commands?: GroupDefinition[];
44
23
  /**
45
- * Groups for command-specific flags.
46
- * Each group is defined as `[key, name]`.
24
+ * Groups for command-specific flags. Each group is defined as `[key, name]`.
47
25
  */
48
26
  flags?: GroupDefinition[];
49
27
  /**
50
- * Groups for global flags.
51
- * Each group is defined as `[key, name]`.
28
+ * Groups for global flags. Each group is defined as `[key, name]`.
52
29
  */
53
30
  globalFlags?: GroupDefinition[];
54
31
  }
@@ -59,8 +36,8 @@ declare const defaultFormatters: Formatters;
59
36
  //#region src/index.d.ts
60
37
  interface HelpOptions {
61
38
  /**
62
- * The group this item belongs to.
63
- * The group must be defined in the `groups` option of `helpPlugin()`.
39
+ * The group this item belongs to. The group must be defined in the `groups`
40
+ * option of `helpPlugin()`.
64
41
  */
65
42
  group?: string;
66
43
  }
@@ -76,8 +53,8 @@ interface CommandHelpOptions extends HelpOptions {
76
53
  */
77
54
  notes?: string[];
78
55
  /**
79
- * Examples to show in the help output.
80
- * Each example is a tuple of `[command, description]`.
56
+ * Examples to show in the help output. Each example is a tuple of `[command,
57
+ * description]`.
81
58
  */
82
59
  examples?: [string, string][];
83
60
  }
@@ -119,8 +96,8 @@ interface HelpPluginOptions {
119
96
  */
120
97
  notes?: string[];
121
98
  /**
122
- * Examples to show in the help output.
123
- * Each example is a tuple of `[command, description]`.
99
+ * Examples to show in the help output. Each example is a tuple of `[command,
100
+ * description]`.
124
101
  */
125
102
  examples?: [string, string][];
126
103
  /**
@@ -136,10 +113,10 @@ interface HelpPluginOptions {
136
113
  */
137
114
  formatters?: Partial<Formatters>;
138
115
  /**
139
- * Group definitions for commands and flags.
140
- * Groups allow organizing commands and flags into logical sections in help output.
141
- * Each group is defined as `[key, name]` where `key` is the identifier used in help options
142
- * and `name` is the display name shown in help output.
116
+ * Group definitions for commands and flags. Groups allow organizing commands
117
+ * and flags into logical sections in help output. Each group is defined as
118
+ * `[key, name]` where `key` is the identifier used in help options and `name`
119
+ * is the display name shown in help output.
143
120
  */
144
121
  groups?: GroupsOptions;
145
122
  }
@@ -1,17 +1,9 @@
1
1
  import { DOUBLE_DASH, NoSuchCommandError, definePlugin, normalizeFlagValue, normalizeParameterValue, resolveCommand } from "@clerc/core";
2
+ import { formatFlagName, formatVersion, isTruthy, objectIsEmpty, toArray } from "@clerc/utils";
2
3
  import * as tint from "@uttr/tint";
3
4
  import stringWidth from "string-width";
4
5
  import textTable from "text-table";
5
6
 
6
- //#region ../utils/src/index.ts
7
- const toArray = (a) => Array.isArray(a) ? a : [a];
8
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
9
- const formatFlagName = (n) => n.length <= 1 ? `-${n}` : `--${kebabCase(n)}`;
10
- const formatVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`;
11
- const isTruthy = Boolean;
12
- const objectIsEmpty = (obj) => Object.keys(obj).length === 0;
13
-
14
- //#endregion
15
7
  //#region src/utils.ts
16
8
  function formatTypeValue(type) {
17
9
  if (typeof type === "function") return type.display ?? type.name;
@@ -122,7 +114,7 @@ var HelpRenderer = class {
122
114
  });
123
115
  usage += ` ${items.join(" ")}`;
124
116
  }
125
- } else if (this._cli._commands.size > 0 && !(this._cli._commands.has("") && this._cli._commands.size === 1)) usage += this._cli._commands.has("") ? ` ${tint.dim("[command]")}` : ` ${tint.dim("<command>")}`;
117
+ } else if (this._cli._commands.size > 0 && (!this._cli._commands.has("") || this._cli._commands.size !== 1)) usage += this._cli._commands.has("") ? ` ${tint.dim("[command]")}` : ` ${tint.dim("<command>")}`;
126
118
  if (command?.flags && !objectIsEmpty(command.flags) || !objectIsEmpty(this._globalFlags)) usage += ` ${tint.dim("[flags]")}`;
127
119
  return {
128
120
  title: "Usage",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc plugin help",
@@ -25,19 +25,12 @@
25
25
  "license": "MIT",
26
26
  "sideEffects": false,
27
27
  "exports": {
28
- ".": "./dist/index.js"
29
- },
30
- "main": "./dist/index.js",
31
- "module": "./dist/index.js",
32
- "types": "dist/index.d.ts",
33
- "typesVersions": {
34
- "*": {
35
- "*": [
36
- "./dist/*",
37
- "./dist/index.d.ts"
38
- ]
39
- }
28
+ ".": "./dist/index.mjs",
29
+ "./package.json": "./package.json"
40
30
  },
31
+ "main": "./dist/index.mjs",
32
+ "module": "./dist/index.mjs",
33
+ "types": "./dist/index.d.mts",
41
34
  "files": [
42
35
  "dist"
43
36
  ],
@@ -45,16 +38,16 @@
45
38
  "access": "public"
46
39
  },
47
40
  "dependencies": {
48
- "@types/text-table": "^0.2.5",
49
41
  "@uttr/tint": "^0.1.3",
50
42
  "string-width": "^8.1.0",
51
- "text-table": "^0.2.0"
43
+ "text-table": "^0.2.0",
44
+ "@clerc/utils": "1.1.0"
52
45
  },
53
46
  "devDependencies": {
47
+ "@types/text-table": "^0.2.5",
54
48
  "kons": "^0.7.1",
55
- "@clerc/core": "1.0.2",
56
- "@clerc/parser": "1.0.2",
57
- "@clerc/utils": "1.0.2"
49
+ "@clerc/parser": "1.1.0",
50
+ "@clerc/core": "1.1.0"
58
51
  },
59
52
  "peerDependencies": {
60
53
  "@clerc/core": "*"