@clerc/plugin-help 0.21.0 → 0.22.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 +10 -10
- package/dist/index.mjs +10 -10
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlugin,
|
|
1
|
+
import { definePlugin, Root, resolveCommand, NoSuchCommandError } from '@clerc/core';
|
|
2
2
|
import { toArray, gracefulFlagName } from '@clerc/utils';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import getFuncName from 'get-func-name';
|
|
@@ -56,7 +56,7 @@ const render = (sections) => {
|
|
|
56
56
|
|
|
57
57
|
const DELIMITER = pc.yellow("-");
|
|
58
58
|
const NO_DESCRIPTION = "(No description)";
|
|
59
|
-
const
|
|
59
|
+
const ROOT = "<Root>";
|
|
60
60
|
const NAME = "Name:";
|
|
61
61
|
const VERSION = "Version:";
|
|
62
62
|
const COMMANDS = "Commands:";
|
|
@@ -69,7 +69,7 @@ const NOTES = "Notes:";
|
|
|
69
69
|
const print = (s) => {
|
|
70
70
|
process.stdout.write(s);
|
|
71
71
|
};
|
|
72
|
-
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name :
|
|
72
|
+
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT;
|
|
73
73
|
const generateCliDetail = (sections, cli, subcommand) => {
|
|
74
74
|
const items = [
|
|
75
75
|
{
|
|
@@ -111,12 +111,12 @@ const generateHelp = (ctx, notes, examples) => {
|
|
|
111
111
|
title: USAGE,
|
|
112
112
|
body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
|
|
113
113
|
});
|
|
114
|
-
const commands = [...ctx.
|
|
114
|
+
const commands = [...ctx.hasRoot ? [cli._commands[Root]] : [], ...Object.values(cli._commands)].map((command) => {
|
|
115
115
|
const commandNameWithAlias = [typeof command.name === "symbol" ? "" : command.name, ...toArray(command.alias || [])].sort((a, b) => {
|
|
116
|
-
if (a ===
|
|
116
|
+
if (a === Root) {
|
|
117
117
|
return -1;
|
|
118
118
|
}
|
|
119
|
-
if (b ===
|
|
119
|
+
if (b === Root) {
|
|
120
120
|
return 1;
|
|
121
121
|
}
|
|
122
122
|
return a.length - b.length;
|
|
@@ -150,7 +150,7 @@ const generateSubcommandHelp = (ctx, command) => {
|
|
|
150
150
|
const sections = [];
|
|
151
151
|
generateCliDetail(sections, cli, subcommand);
|
|
152
152
|
const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(" ")) || void 0;
|
|
153
|
-
const commandName = ctx.name ===
|
|
153
|
+
const commandName = ctx.name === Root ? "" : ` ${formatCommandName(subcommand.name)}`;
|
|
154
154
|
const parametersString = parameters ? ` ${parameters}` : "";
|
|
155
155
|
const flagsString = subcommand.flags ? " [flags]" : "";
|
|
156
156
|
sections.push({
|
|
@@ -220,7 +220,7 @@ const helpPlugin = ({
|
|
|
220
220
|
}
|
|
221
221
|
cli.inspector((ctx, next) => {
|
|
222
222
|
const hasHelpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help;
|
|
223
|
-
if (!ctx.
|
|
223
|
+
if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !hasHelpFlag) {
|
|
224
224
|
let str = "No command supplied.\n\n";
|
|
225
225
|
str += generateHelp(ctx, notes, examples);
|
|
226
226
|
str += "\n";
|
|
@@ -228,8 +228,8 @@ const helpPlugin = ({
|
|
|
228
228
|
process.exit(1);
|
|
229
229
|
} else if (hasHelpFlag) {
|
|
230
230
|
if (ctx.raw._.length) {
|
|
231
|
-
if (ctx.called !==
|
|
232
|
-
if (ctx.name ===
|
|
231
|
+
if (ctx.called !== Root) {
|
|
232
|
+
if (ctx.name === Root) {
|
|
233
233
|
print(generateHelp(ctx, notes, examples));
|
|
234
234
|
} else {
|
|
235
235
|
print(generateSubcommandHelp(ctx, ctx.raw._));
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlugin,
|
|
1
|
+
import { definePlugin, Root, resolveCommand, NoSuchCommandError } from '@clerc/core';
|
|
2
2
|
import { toArray, gracefulFlagName } from '@clerc/utils';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import getFuncName from 'get-func-name';
|
|
@@ -56,7 +56,7 @@ const render = (sections) => {
|
|
|
56
56
|
|
|
57
57
|
const DELIMITER = pc.yellow("-");
|
|
58
58
|
const NO_DESCRIPTION = "(No description)";
|
|
59
|
-
const
|
|
59
|
+
const ROOT = "<Root>";
|
|
60
60
|
const NAME = "Name:";
|
|
61
61
|
const VERSION = "Version:";
|
|
62
62
|
const COMMANDS = "Commands:";
|
|
@@ -69,7 +69,7 @@ const NOTES = "Notes:";
|
|
|
69
69
|
const print = (s) => {
|
|
70
70
|
process.stdout.write(s);
|
|
71
71
|
};
|
|
72
|
-
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name :
|
|
72
|
+
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT;
|
|
73
73
|
const generateCliDetail = (sections, cli, subcommand) => {
|
|
74
74
|
const items = [
|
|
75
75
|
{
|
|
@@ -111,12 +111,12 @@ const generateHelp = (ctx, notes, examples) => {
|
|
|
111
111
|
title: USAGE,
|
|
112
112
|
body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
|
|
113
113
|
});
|
|
114
|
-
const commands = [...ctx.
|
|
114
|
+
const commands = [...ctx.hasRoot ? [cli._commands[Root]] : [], ...Object.values(cli._commands)].map((command) => {
|
|
115
115
|
const commandNameWithAlias = [typeof command.name === "symbol" ? "" : command.name, ...toArray(command.alias || [])].sort((a, b) => {
|
|
116
|
-
if (a ===
|
|
116
|
+
if (a === Root) {
|
|
117
117
|
return -1;
|
|
118
118
|
}
|
|
119
|
-
if (b ===
|
|
119
|
+
if (b === Root) {
|
|
120
120
|
return 1;
|
|
121
121
|
}
|
|
122
122
|
return a.length - b.length;
|
|
@@ -150,7 +150,7 @@ const generateSubcommandHelp = (ctx, command) => {
|
|
|
150
150
|
const sections = [];
|
|
151
151
|
generateCliDetail(sections, cli, subcommand);
|
|
152
152
|
const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(" ")) || void 0;
|
|
153
|
-
const commandName = ctx.name ===
|
|
153
|
+
const commandName = ctx.name === Root ? "" : ` ${formatCommandName(subcommand.name)}`;
|
|
154
154
|
const parametersString = parameters ? ` ${parameters}` : "";
|
|
155
155
|
const flagsString = subcommand.flags ? " [flags]" : "";
|
|
156
156
|
sections.push({
|
|
@@ -220,7 +220,7 @@ const helpPlugin = ({
|
|
|
220
220
|
}
|
|
221
221
|
cli.inspector((ctx, next) => {
|
|
222
222
|
const hasHelpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help;
|
|
223
|
-
if (!ctx.
|
|
223
|
+
if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !hasHelpFlag) {
|
|
224
224
|
let str = "No command supplied.\n\n";
|
|
225
225
|
str += generateHelp(ctx, notes, examples);
|
|
226
226
|
str += "\n";
|
|
@@ -228,8 +228,8 @@ const helpPlugin = ({
|
|
|
228
228
|
process.exit(1);
|
|
229
229
|
} else if (hasHelpFlag) {
|
|
230
230
|
if (ctx.raw._.length) {
|
|
231
|
-
if (ctx.called !==
|
|
232
|
-
if (ctx.name ===
|
|
231
|
+
if (ctx.called !== Root) {
|
|
232
|
+
if (ctx.name === Root) {
|
|
233
233
|
print(generateHelp(ctx, notes, examples));
|
|
234
234
|
} else {
|
|
235
235
|
print(generateSubcommandHelp(ctx, ctx.raw._));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin help",
|
|
6
6
|
"keywords": [
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"get-func-name": "^2.0.0",
|
|
55
55
|
"picocolors": "^1.0.0",
|
|
56
|
-
"@clerc/toolkit": "0.
|
|
57
|
-
"@clerc/utils": "0.
|
|
56
|
+
"@clerc/toolkit": "0.22.0",
|
|
57
|
+
"@clerc/utils": "0.22.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@clerc/core": "0.
|
|
60
|
+
"@clerc/core": "0.22.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "puild",
|