@clerc/plugin-help 0.17.0 → 0.17.1
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 +13 -13
- package/dist/index.mjs +13 -13
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
2
|
import { mustArray, gracefulFlagName } from '@clerc/utils';
|
|
3
|
-
import
|
|
3
|
+
import pc from 'picocolors';
|
|
4
4
|
import { Table } from '@clerc/toolkit';
|
|
5
5
|
|
|
6
6
|
const table = (...items) => {
|
|
@@ -36,9 +36,9 @@ const render = (sections) => {
|
|
|
36
36
|
const formattedBody = section.body.map((line) => indent + line);
|
|
37
37
|
formattedBody.unshift("");
|
|
38
38
|
const body = formattedBody.join("\n");
|
|
39
|
-
rendered.push(table([
|
|
39
|
+
rendered.push(table([pc.bold(section.title)], [body]).toString());
|
|
40
40
|
} else if (section.type === "inline") {
|
|
41
|
-
const formattedBody = section.items.map((item) => [
|
|
41
|
+
const formattedBody = section.items.map((item) => [pc.bold(item.title), item.body]);
|
|
42
42
|
const tableGenerated = table(...formattedBody);
|
|
43
43
|
rendered.push(tableGenerated.toString());
|
|
44
44
|
}
|
|
@@ -47,23 +47,23 @@ const render = (sections) => {
|
|
|
47
47
|
return rendered.join("\n");
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const DELIMITER =
|
|
50
|
+
const DELIMITER = pc.yellow("-");
|
|
51
51
|
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : "<Single Command>";
|
|
52
52
|
const generateCliDetail = (sections, cli, subcommand) => {
|
|
53
53
|
const items = [
|
|
54
54
|
{
|
|
55
55
|
title: "Name:",
|
|
56
|
-
body:
|
|
56
|
+
body: pc.red(cli._name)
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
title: "Version:",
|
|
60
|
-
body:
|
|
60
|
+
body: pc.yellow(cli._version)
|
|
61
61
|
}
|
|
62
62
|
];
|
|
63
63
|
if (subcommand) {
|
|
64
64
|
items.push({
|
|
65
65
|
title: "Subcommand:",
|
|
66
|
-
body:
|
|
66
|
+
body: pc.green(formatCommandName(subcommand.name))
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
sections.push({
|
|
@@ -89,12 +89,12 @@ const showHelp = (ctx, notes, examples) => {
|
|
|
89
89
|
if (ctx.isSingleCommand) {
|
|
90
90
|
sections.push({
|
|
91
91
|
title: "Usage:",
|
|
92
|
-
body: [
|
|
92
|
+
body: [pc.magenta(`$ ${cli._name} [flags]`)]
|
|
93
93
|
});
|
|
94
94
|
} else {
|
|
95
95
|
sections.push({
|
|
96
96
|
title: "Usage:",
|
|
97
|
-
body: [
|
|
97
|
+
body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
if (!ctx.isSingleCommand) {
|
|
@@ -102,7 +102,7 @@ const showHelp = (ctx, notes, examples) => {
|
|
|
102
102
|
title: "Commands:",
|
|
103
103
|
body: table(...Object.values(cli._commands).map((command) => {
|
|
104
104
|
const commandNameWithAlias = [command.name, ...mustArray(command.alias || [])].join(", ");
|
|
105
|
-
return [
|
|
105
|
+
return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
|
|
106
106
|
})).toString().split("\n")
|
|
107
107
|
});
|
|
108
108
|
}
|
|
@@ -129,7 +129,7 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
129
129
|
const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(" ")) || void 0;
|
|
130
130
|
sections.push({
|
|
131
131
|
title: "Usage:",
|
|
132
|
-
body: [
|
|
132
|
+
body: [pc.magenta(`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`)]
|
|
133
133
|
});
|
|
134
134
|
if (subcommand.flags) {
|
|
135
135
|
sections.push({
|
|
@@ -139,13 +139,13 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
139
139
|
if (flag.alias) {
|
|
140
140
|
flagNameWithAlias.push(gracefulFlagName(flag.alias));
|
|
141
141
|
}
|
|
142
|
-
const items = [
|
|
142
|
+
const items = [pc.blue(flagNameWithAlias.join(", "))];
|
|
143
143
|
if (flag.description) {
|
|
144
144
|
items.push(DELIMITER, flag.description);
|
|
145
145
|
}
|
|
146
146
|
if (flag.type) {
|
|
147
147
|
const type = Array.isArray(flag.type) ? `Array<${flag.type[0].name}>` : flag.type.name;
|
|
148
|
-
items.push(
|
|
148
|
+
items.push(pc.gray(`(${type})`));
|
|
149
149
|
}
|
|
150
150
|
return table(items).toString();
|
|
151
151
|
})
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
2
|
import { mustArray, gracefulFlagName } from '@clerc/utils';
|
|
3
|
-
import
|
|
3
|
+
import pc from 'picocolors';
|
|
4
4
|
import { Table } from '@clerc/toolkit';
|
|
5
5
|
|
|
6
6
|
const table = (...items) => {
|
|
@@ -36,9 +36,9 @@ const render = (sections) => {
|
|
|
36
36
|
const formattedBody = section.body.map((line) => indent + line);
|
|
37
37
|
formattedBody.unshift("");
|
|
38
38
|
const body = formattedBody.join("\n");
|
|
39
|
-
rendered.push(table([
|
|
39
|
+
rendered.push(table([pc.bold(section.title)], [body]).toString());
|
|
40
40
|
} else if (section.type === "inline") {
|
|
41
|
-
const formattedBody = section.items.map((item) => [
|
|
41
|
+
const formattedBody = section.items.map((item) => [pc.bold(item.title), item.body]);
|
|
42
42
|
const tableGenerated = table(...formattedBody);
|
|
43
43
|
rendered.push(tableGenerated.toString());
|
|
44
44
|
}
|
|
@@ -47,23 +47,23 @@ const render = (sections) => {
|
|
|
47
47
|
return rendered.join("\n");
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const DELIMITER =
|
|
50
|
+
const DELIMITER = pc.yellow("-");
|
|
51
51
|
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : "<Single Command>";
|
|
52
52
|
const generateCliDetail = (sections, cli, subcommand) => {
|
|
53
53
|
const items = [
|
|
54
54
|
{
|
|
55
55
|
title: "Name:",
|
|
56
|
-
body:
|
|
56
|
+
body: pc.red(cli._name)
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
title: "Version:",
|
|
60
|
-
body:
|
|
60
|
+
body: pc.yellow(cli._version)
|
|
61
61
|
}
|
|
62
62
|
];
|
|
63
63
|
if (subcommand) {
|
|
64
64
|
items.push({
|
|
65
65
|
title: "Subcommand:",
|
|
66
|
-
body:
|
|
66
|
+
body: pc.green(formatCommandName(subcommand.name))
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
sections.push({
|
|
@@ -89,12 +89,12 @@ const showHelp = (ctx, notes, examples) => {
|
|
|
89
89
|
if (ctx.isSingleCommand) {
|
|
90
90
|
sections.push({
|
|
91
91
|
title: "Usage:",
|
|
92
|
-
body: [
|
|
92
|
+
body: [pc.magenta(`$ ${cli._name} [flags]`)]
|
|
93
93
|
});
|
|
94
94
|
} else {
|
|
95
95
|
sections.push({
|
|
96
96
|
title: "Usage:",
|
|
97
|
-
body: [
|
|
97
|
+
body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
if (!ctx.isSingleCommand) {
|
|
@@ -102,7 +102,7 @@ const showHelp = (ctx, notes, examples) => {
|
|
|
102
102
|
title: "Commands:",
|
|
103
103
|
body: table(...Object.values(cli._commands).map((command) => {
|
|
104
104
|
const commandNameWithAlias = [command.name, ...mustArray(command.alias || [])].join(", ");
|
|
105
|
-
return [
|
|
105
|
+
return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
|
|
106
106
|
})).toString().split("\n")
|
|
107
107
|
});
|
|
108
108
|
}
|
|
@@ -129,7 +129,7 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
129
129
|
const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(" ")) || void 0;
|
|
130
130
|
sections.push({
|
|
131
131
|
title: "Usage:",
|
|
132
|
-
body: [
|
|
132
|
+
body: [pc.magenta(`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`)]
|
|
133
133
|
});
|
|
134
134
|
if (subcommand.flags) {
|
|
135
135
|
sections.push({
|
|
@@ -139,13 +139,13 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
139
139
|
if (flag.alias) {
|
|
140
140
|
flagNameWithAlias.push(gracefulFlagName(flag.alias));
|
|
141
141
|
}
|
|
142
|
-
const items = [
|
|
142
|
+
const items = [pc.blue(flagNameWithAlias.join(", "))];
|
|
143
143
|
if (flag.description) {
|
|
144
144
|
items.push(DELIMITER, flag.description);
|
|
145
145
|
}
|
|
146
146
|
if (flag.type) {
|
|
147
147
|
const type = Array.isArray(flag.type) ? `Array<${flag.type[0].name}>` : flag.type.name;
|
|
148
|
-
items.push(
|
|
148
|
+
items.push(pc.gray(`(${type})`));
|
|
149
149
|
}
|
|
150
150
|
return table(items).toString();
|
|
151
151
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin help",
|
|
6
6
|
"keywords": [
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"@clerc/core": "*"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"
|
|
55
|
-
"@clerc/toolkit": "0.17.
|
|
56
|
-
"@clerc/utils": "0.17.
|
|
54
|
+
"picocolors": "^1.0.0",
|
|
55
|
+
"@clerc/toolkit": "0.17.1",
|
|
56
|
+
"@clerc/utils": "0.17.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@clerc/core": "0.17.
|
|
59
|
+
"@clerc/core": "0.17.1"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "puild",
|