@clerc/plugin-help 0.10.3 → 0.10.5
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.cjs → index.js} +28 -36
- package/dist/index.mjs +1 -1
- package/package.json +14 -6
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var core = require('@clerc/core');
|
|
6
|
-
var utils = require('@clerc/utils');
|
|
7
|
-
var pc = require('picocolors');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var pc__default = /*#__PURE__*/_interopDefaultLegacy(pc);
|
|
1
|
+
import { definePlugin, resolveRootCommands, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
|
+
import { mustArray, gracefulFlagName, gracefulVersion, generateCommandRecordFromCommandArray } from '@clerc/utils';
|
|
3
|
+
import pc from 'picocolors';
|
|
12
4
|
|
|
13
5
|
function generateNameAndAliasFromCommands(commands) {
|
|
14
6
|
return Object.fromEntries(
|
|
15
|
-
Object.entries(commands).map(([name, command]) => [name, [name, ...command.alias ?
|
|
7
|
+
Object.entries(commands).map(([name, command]) => [name, [name, ...command.alias ? mustArray(command.alias) : []].join(", ")])
|
|
16
8
|
);
|
|
17
9
|
}
|
|
18
10
|
function generateFlagNameAndAliasFromCommand(command) {
|
|
@@ -21,9 +13,9 @@ function generateFlagNameAndAliasFromCommand(command) {
|
|
|
21
13
|
([name, flag]) => {
|
|
22
14
|
const nameAndAlias = [name];
|
|
23
15
|
if (flag.alias) {
|
|
24
|
-
nameAndAlias.push(...
|
|
16
|
+
nameAndAlias.push(...mustArray(flag.alias));
|
|
25
17
|
}
|
|
26
|
-
return [name, nameAndAlias.map(
|
|
18
|
+
return [name, nameAndAlias.map(gracefulFlagName).join(", ")];
|
|
27
19
|
}
|
|
28
20
|
)
|
|
29
21
|
);
|
|
@@ -47,8 +39,8 @@ const defaultOptions = {
|
|
|
47
39
|
examples: [],
|
|
48
40
|
notes: []
|
|
49
41
|
};
|
|
50
|
-
const helpPlugin = (_options) =>
|
|
51
|
-
setup(cli) {
|
|
42
|
+
const helpPlugin = (_options) => definePlugin({
|
|
43
|
+
setup: (cli) => {
|
|
52
44
|
const { command, ...rest } = { ...defaultOptions, ..._options };
|
|
53
45
|
cli.inspector((inspectorCtx, next) => {
|
|
54
46
|
if (command && !inspectorCtx.isSingleCommand) {
|
|
@@ -94,23 +86,23 @@ function showHelp(ctx, { examples, notes }) {
|
|
|
94
86
|
showSubcommandHelp(ctx);
|
|
95
87
|
return;
|
|
96
88
|
}
|
|
97
|
-
cli._name && console.log(`${
|
|
89
|
+
cli._name && console.log(`${pc.green(cli._name)} ${gracefulVersion(cli._version)}`);
|
|
98
90
|
if (cli._description) {
|
|
99
91
|
console.log(cli._description);
|
|
100
92
|
newline();
|
|
101
93
|
}
|
|
102
|
-
console.log(
|
|
94
|
+
console.log(pc.yellow("USAGE:"));
|
|
103
95
|
console.log(` ${cli._name || "<CLI NAME>"} <SUBCOMMAND> [OPTIONS]`);
|
|
104
96
|
newline();
|
|
105
|
-
console.log(
|
|
106
|
-
const commandNameAndAlias = generateNameAndAliasFromCommands(
|
|
97
|
+
console.log(pc.yellow("COMMANDS:"));
|
|
98
|
+
const commandNameAndAlias = generateNameAndAliasFromCommands(generateCommandRecordFromCommandArray(resolveRootCommands(cli._commands)));
|
|
107
99
|
const commandsPadLength = getPadLength(Object.values(commandNameAndAlias));
|
|
108
100
|
for (const [name, nameAndAlias] of Object.entries(commandNameAndAlias)) {
|
|
109
|
-
console.log(` ${
|
|
101
|
+
console.log(` ${pc.green(nameAndAlias.padEnd(commandsPadLength))}${cli._commands[name].description}`);
|
|
110
102
|
}
|
|
111
103
|
if (examples.length > 0) {
|
|
112
104
|
newline();
|
|
113
|
-
console.log(
|
|
105
|
+
console.log(pc.yellow("EXAMPLES:"));
|
|
114
106
|
const examplesPadLength = getPadLength(examples.map((e) => e[0]));
|
|
115
107
|
for (const [exampleCommand, exampleDescription] of examples) {
|
|
116
108
|
console.log(` ${exampleCommand.padEnd(examplesPadLength)}${exampleDescription}`);
|
|
@@ -121,7 +113,7 @@ function showHelp(ctx, { examples, notes }) {
|
|
|
121
113
|
function showCommandExamples(examples) {
|
|
122
114
|
if (examples && examples.length > 0) {
|
|
123
115
|
newline();
|
|
124
|
-
console.log(
|
|
116
|
+
console.log(pc.yellow("EXAMPLES:"));
|
|
125
117
|
const examplesPadLength = getPadLength(examples.map((e) => e[0]));
|
|
126
118
|
for (const [exampleCommand, exampleDescription] of examples) {
|
|
127
119
|
console.log(` ${exampleCommand.padEnd(examplesPadLength)}${exampleDescription}`);
|
|
@@ -131,7 +123,7 @@ function showCommandExamples(examples) {
|
|
|
131
123
|
function showCommandNotes(notes) {
|
|
132
124
|
if (notes && notes.length > 0) {
|
|
133
125
|
newline();
|
|
134
|
-
console.log(
|
|
126
|
+
console.log(pc.yellow("NOTES:"));
|
|
135
127
|
for (const note of notes) {
|
|
136
128
|
console.log(` ${note}`);
|
|
137
129
|
}
|
|
@@ -140,22 +132,22 @@ function showCommandNotes(notes) {
|
|
|
140
132
|
function showSubcommandHelp(ctx) {
|
|
141
133
|
const { cli } = ctx;
|
|
142
134
|
const commandName = ctx.parameters.command;
|
|
143
|
-
const commandToShowHelp =
|
|
135
|
+
const commandToShowHelp = resolveCommand(cli._commands, commandName);
|
|
144
136
|
if (!commandToShowHelp) {
|
|
145
|
-
throw new
|
|
137
|
+
throw new NoSuchCommandError(commandName.join(" "));
|
|
146
138
|
}
|
|
147
|
-
console.log(`${
|
|
139
|
+
console.log(`${pc.green(`${cli._name} ${commandToShowHelp.name}`)} ${gracefulVersion(cli._version)}`);
|
|
148
140
|
commandToShowHelp.description && console.log(commandToShowHelp.description);
|
|
149
141
|
newline();
|
|
150
|
-
console.log(
|
|
142
|
+
console.log(pc.yellow("USAGE:"));
|
|
151
143
|
console.log(` ${cli._name} ${commandToShowHelp.name} [PARAMETERS] [FLAGS]`);
|
|
152
144
|
const flagNameAndAlias = generateFlagNameAndAliasFromCommand(commandToShowHelp);
|
|
153
145
|
if (Object.keys(flagNameAndAlias).length > 0) {
|
|
154
146
|
newline();
|
|
155
|
-
console.log(
|
|
147
|
+
console.log(pc.yellow("FLAGS:"));
|
|
156
148
|
const flagsPadLength = getPadLength(Object.values(flagNameAndAlias));
|
|
157
149
|
for (const [name, nameAndAlias] of Object.entries(flagNameAndAlias)) {
|
|
158
|
-
console.log(` ${
|
|
150
|
+
console.log(` ${pc.green(nameAndAlias.padEnd(flagsPadLength))}${commandToShowHelp.flags[name].description}`);
|
|
159
151
|
}
|
|
160
152
|
}
|
|
161
153
|
showCommandExamples(commandToShowHelp.examples);
|
|
@@ -163,23 +155,23 @@ function showSubcommandHelp(ctx) {
|
|
|
163
155
|
}
|
|
164
156
|
function showSingleCommandHelp(ctx) {
|
|
165
157
|
const { cli } = ctx;
|
|
166
|
-
const singleCommand = cli._commands[
|
|
167
|
-
console.log(`${
|
|
158
|
+
const singleCommand = cli._commands[SingleCommand];
|
|
159
|
+
console.log(`${pc.green(`${cli._name} ${gracefulVersion(cli._version)}`)}`);
|
|
168
160
|
singleCommand.description && console.log(singleCommand.description);
|
|
169
161
|
newline();
|
|
170
|
-
console.log(
|
|
162
|
+
console.log(pc.yellow("USAGE:"));
|
|
171
163
|
console.log(` ${cli._name} [PARAMETERS] [FLAGS]`);
|
|
172
164
|
const flagNameAndAlias = generateFlagNameAndAliasFromCommand(singleCommand);
|
|
173
165
|
if (Object.keys(flagNameAndAlias).length > 0) {
|
|
174
166
|
newline();
|
|
175
|
-
console.log(
|
|
167
|
+
console.log(pc.yellow("FLAGS:"));
|
|
176
168
|
const flagsPadLength = getPadLength(Object.values(flagNameAndAlias));
|
|
177
169
|
for (const [name, nameAndAlias] of Object.entries(flagNameAndAlias)) {
|
|
178
|
-
console.log(` ${
|
|
170
|
+
console.log(` ${pc.green(nameAndAlias.padEnd(flagsPadLength))}${singleCommand.flags[name].description}`);
|
|
179
171
|
}
|
|
180
172
|
}
|
|
181
173
|
showCommandExamples(singleCommand.examples);
|
|
182
174
|
showCommandNotes(singleCommand.notes);
|
|
183
175
|
}
|
|
184
176
|
|
|
185
|
-
|
|
177
|
+
export { helpPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -40,7 +40,7 @@ const defaultOptions = {
|
|
|
40
40
|
notes: []
|
|
41
41
|
};
|
|
42
42
|
const helpPlugin = (_options) => definePlugin({
|
|
43
|
-
setup(cli) {
|
|
43
|
+
setup: (cli) => {
|
|
44
44
|
const { command, ...rest } = { ...defaultOptions, ..._options };
|
|
45
45
|
cli.inspector((inspectorCtx, next) => {
|
|
46
46
|
if (command && !inspectorCtx.isSingleCommand) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin help",
|
|
6
6
|
"keywords": [
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"args",
|
|
13
13
|
"terminal"
|
|
14
14
|
],
|
|
15
|
+
"type": "module",
|
|
15
16
|
"homepage": "https://github.com/so1ve/clerc/tree/main/packages/plugin-help#readme",
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
@@ -26,13 +27,20 @@
|
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
29
|
"types": "./dist/index.d.ts",
|
|
29
|
-
"require": "./dist/index.cjs",
|
|
30
30
|
"import": "./dist/index.mjs"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"main": "dist/index.
|
|
33
|
+
"main": "dist/index.js",
|
|
34
34
|
"module": "dist/index.mjs",
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
"*": [
|
|
39
|
+
"./dist/*",
|
|
40
|
+
"./dist/index.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
36
44
|
"files": [
|
|
37
45
|
"dist"
|
|
38
46
|
],
|
|
@@ -43,11 +51,11 @@
|
|
|
43
51
|
"@clerc/core": "*"
|
|
44
52
|
},
|
|
45
53
|
"dependencies": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
54
|
+
"@clerc/utils": "0.10.5",
|
|
55
|
+
"picocolors": "^1.0.0"
|
|
48
56
|
},
|
|
49
57
|
"devDependencies": {
|
|
50
|
-
"@clerc/core": "0.10.
|
|
58
|
+
"@clerc/core": "0.10.5"
|
|
51
59
|
},
|
|
52
60
|
"scripts": {
|
|
53
61
|
"build": "puild",
|