@clerc/plugin-help 0.17.3 → 0.19.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/dist/index.js +8 -4
- package/dist/index.mjs +8 -4
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
|
-
import {
|
|
2
|
+
import { toArray, gracefulFlagName, kebabCase } from '@clerc/utils';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
|
+
import getFuncName from 'get-func-name';
|
|
4
5
|
import { Table } from '@clerc/toolkit';
|
|
5
6
|
|
|
6
7
|
const table = (...items) => {
|
|
@@ -30,6 +31,9 @@ const table = (...items) => {
|
|
|
30
31
|
const splitTable = (...items) => {
|
|
31
32
|
return table(...items).toString().split("\n");
|
|
32
33
|
};
|
|
34
|
+
const stringifyType = (type) => {
|
|
35
|
+
return Array.isArray(type) ? `Array<${getFuncName(type[0])}>` : getFuncName(type);
|
|
36
|
+
};
|
|
33
37
|
|
|
34
38
|
const render = (sections) => {
|
|
35
39
|
const rendered = [];
|
|
@@ -104,7 +108,7 @@ const showHelp = (ctx, notes, examples) => {
|
|
|
104
108
|
sections.push({
|
|
105
109
|
title: "Commands:",
|
|
106
110
|
body: splitTable(...Object.values(cli._commands).map((command) => {
|
|
107
|
-
const commandNameWithAlias = [command.name, ...
|
|
111
|
+
const commandNameWithAlias = [command.name, ...toArray(command.alias || [])].join(", ");
|
|
108
112
|
return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
|
|
109
113
|
}))
|
|
110
114
|
});
|
|
@@ -143,12 +147,12 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
143
147
|
if (flag.alias) {
|
|
144
148
|
flagNameWithAlias.push(gracefulFlagName(flag.alias));
|
|
145
149
|
}
|
|
146
|
-
const items = [pc.blue(flagNameWithAlias.join(", "))];
|
|
150
|
+
const items = [pc.blue(flagNameWithAlias.map(kebabCase).join(", "))];
|
|
147
151
|
if (flag.description) {
|
|
148
152
|
items.push(DELIMITER, flag.description);
|
|
149
153
|
}
|
|
150
154
|
if (flag.type) {
|
|
151
|
-
const type =
|
|
155
|
+
const type = stringifyType(flag.type);
|
|
152
156
|
items.push(pc.gray(`(${type})`));
|
|
153
157
|
}
|
|
154
158
|
return items;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
|
-
import {
|
|
2
|
+
import { toArray, gracefulFlagName, kebabCase } from '@clerc/utils';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
|
+
import getFuncName from 'get-func-name';
|
|
4
5
|
import { Table } from '@clerc/toolkit';
|
|
5
6
|
|
|
6
7
|
const table = (...items) => {
|
|
@@ -30,6 +31,9 @@ const table = (...items) => {
|
|
|
30
31
|
const splitTable = (...items) => {
|
|
31
32
|
return table(...items).toString().split("\n");
|
|
32
33
|
};
|
|
34
|
+
const stringifyType = (type) => {
|
|
35
|
+
return Array.isArray(type) ? `Array<${getFuncName(type[0])}>` : getFuncName(type);
|
|
36
|
+
};
|
|
33
37
|
|
|
34
38
|
const render = (sections) => {
|
|
35
39
|
const rendered = [];
|
|
@@ -104,7 +108,7 @@ const showHelp = (ctx, notes, examples) => {
|
|
|
104
108
|
sections.push({
|
|
105
109
|
title: "Commands:",
|
|
106
110
|
body: splitTable(...Object.values(cli._commands).map((command) => {
|
|
107
|
-
const commandNameWithAlias = [command.name, ...
|
|
111
|
+
const commandNameWithAlias = [command.name, ...toArray(command.alias || [])].join(", ");
|
|
108
112
|
return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
|
|
109
113
|
}))
|
|
110
114
|
});
|
|
@@ -143,12 +147,12 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
143
147
|
if (flag.alias) {
|
|
144
148
|
flagNameWithAlias.push(gracefulFlagName(flag.alias));
|
|
145
149
|
}
|
|
146
|
-
const items = [pc.blue(flagNameWithAlias.join(", "))];
|
|
150
|
+
const items = [pc.blue(flagNameWithAlias.map(kebabCase).join(", "))];
|
|
147
151
|
if (flag.description) {
|
|
148
152
|
items.push(DELIMITER, flag.description);
|
|
149
153
|
}
|
|
150
154
|
if (flag.type) {
|
|
151
|
-
const type =
|
|
155
|
+
const type = stringifyType(flag.type);
|
|
152
156
|
items.push(pc.gray(`(${type})`));
|
|
153
157
|
}
|
|
154
158
|
return items;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin help",
|
|
6
6
|
"keywords": [
|
|
@@ -51,12 +51,13 @@
|
|
|
51
51
|
"@clerc/core": "*"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
+
"get-func-name": "^2.0.0",
|
|
54
55
|
"picocolors": "^1.0.0",
|
|
55
|
-
"@clerc/toolkit": "0.
|
|
56
|
-
"@clerc/utils": "0.
|
|
56
|
+
"@clerc/toolkit": "0.19.0",
|
|
57
|
+
"@clerc/utils": "0.19.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"@clerc/core": "0.
|
|
60
|
+
"@clerc/core": "0.19.0"
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|
|
62
63
|
"build": "puild",
|