@clerc/plugin-help 0.12.5 → 0.13.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 -5
- package/dist/index.mjs +10 -5
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlugin, resolveCommand, NoSuchCommandError } from '@clerc/core';
|
|
1
|
+
import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
2
|
import { gracefulFlagName } from '@clerc/utils';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import { Table } from '@clerc/toolkit';
|
|
@@ -48,6 +48,7 @@ const render = (sections) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const DELIMITER = pc.yellow("-");
|
|
51
|
+
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : "<Single Command>";
|
|
51
52
|
const generateCliDetail = (sections, cli, subcommand) => {
|
|
52
53
|
const items = [
|
|
53
54
|
{
|
|
@@ -62,7 +63,7 @@ const generateCliDetail = (sections, cli, subcommand) => {
|
|
|
62
63
|
if (subcommand) {
|
|
63
64
|
items.push({
|
|
64
65
|
title: pc.gray("Subcommand:"),
|
|
65
|
-
body: pc.green(subcommand.name)
|
|
66
|
+
body: pc.green(formatCommandName(subcommand.name))
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
sections.push({
|
|
@@ -120,14 +121,14 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
120
121
|
const { cli } = ctx;
|
|
121
122
|
const subcommand = resolveCommand(cli._commands, command);
|
|
122
123
|
if (!subcommand) {
|
|
123
|
-
throw new NoSuchCommandError(command
|
|
124
|
+
throw new NoSuchCommandError(formatCommandName(command));
|
|
124
125
|
}
|
|
125
126
|
const sections = [];
|
|
126
127
|
generateCliDetail(sections, cli, subcommand);
|
|
127
128
|
const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(", ")) || "";
|
|
128
129
|
sections.push({
|
|
129
130
|
title: "Usage:",
|
|
130
|
-
body: [`$ ${cli._name} ${subcommand.name}${parameters ? ` ${parameters}` : ""} [flags]`]
|
|
131
|
+
body: [`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`]
|
|
131
132
|
});
|
|
132
133
|
if (subcommand.flags) {
|
|
133
134
|
sections.push({
|
|
@@ -194,7 +195,11 @@ const helpPlugin = ({
|
|
|
194
195
|
if (ctx.raw._.length) {
|
|
195
196
|
showSubcommandHelp(ctx, ctx.raw._);
|
|
196
197
|
} else {
|
|
197
|
-
|
|
198
|
+
if (!ctx.isSingleCommand) {
|
|
199
|
+
showHelp(ctx, notes, examples);
|
|
200
|
+
} else {
|
|
201
|
+
showSubcommandHelp(ctx, SingleCommand);
|
|
202
|
+
}
|
|
198
203
|
}
|
|
199
204
|
} else {
|
|
200
205
|
next();
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlugin, resolveCommand, NoSuchCommandError } from '@clerc/core';
|
|
1
|
+
import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
|
|
2
2
|
import { gracefulFlagName } from '@clerc/utils';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import { Table } from '@clerc/toolkit';
|
|
@@ -48,6 +48,7 @@ const render = (sections) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const DELIMITER = pc.yellow("-");
|
|
51
|
+
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : "<Single Command>";
|
|
51
52
|
const generateCliDetail = (sections, cli, subcommand) => {
|
|
52
53
|
const items = [
|
|
53
54
|
{
|
|
@@ -62,7 +63,7 @@ const generateCliDetail = (sections, cli, subcommand) => {
|
|
|
62
63
|
if (subcommand) {
|
|
63
64
|
items.push({
|
|
64
65
|
title: pc.gray("Subcommand:"),
|
|
65
|
-
body: pc.green(subcommand.name)
|
|
66
|
+
body: pc.green(formatCommandName(subcommand.name))
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
sections.push({
|
|
@@ -120,14 +121,14 @@ const showSubcommandHelp = (ctx, command) => {
|
|
|
120
121
|
const { cli } = ctx;
|
|
121
122
|
const subcommand = resolveCommand(cli._commands, command);
|
|
122
123
|
if (!subcommand) {
|
|
123
|
-
throw new NoSuchCommandError(command
|
|
124
|
+
throw new NoSuchCommandError(formatCommandName(command));
|
|
124
125
|
}
|
|
125
126
|
const sections = [];
|
|
126
127
|
generateCliDetail(sections, cli, subcommand);
|
|
127
128
|
const parameters = ((_a = subcommand.parameters) == null ? void 0 : _a.join(", ")) || "";
|
|
128
129
|
sections.push({
|
|
129
130
|
title: "Usage:",
|
|
130
|
-
body: [`$ ${cli._name} ${subcommand.name}${parameters ? ` ${parameters}` : ""} [flags]`]
|
|
131
|
+
body: [`$ ${cli._name}${ctx.isSingleCommand ? "" : ` ${formatCommandName(subcommand.name)}`}${parameters ? ` ${parameters}` : ""} [flags]`]
|
|
131
132
|
});
|
|
132
133
|
if (subcommand.flags) {
|
|
133
134
|
sections.push({
|
|
@@ -194,7 +195,11 @@ const helpPlugin = ({
|
|
|
194
195
|
if (ctx.raw._.length) {
|
|
195
196
|
showSubcommandHelp(ctx, ctx.raw._);
|
|
196
197
|
} else {
|
|
197
|
-
|
|
198
|
+
if (!ctx.isSingleCommand) {
|
|
199
|
+
showHelp(ctx, notes, examples);
|
|
200
|
+
} else {
|
|
201
|
+
showSubcommandHelp(ctx, SingleCommand);
|
|
202
|
+
}
|
|
198
203
|
}
|
|
199
204
|
} else {
|
|
200
205
|
next();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin help",
|
|
6
6
|
"keywords": [
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"picocolors": "^1.0.0",
|
|
55
|
-
"@clerc/toolkit": "0.
|
|
56
|
-
"@clerc/utils": "0.
|
|
55
|
+
"@clerc/toolkit": "0.13.0",
|
|
56
|
+
"@clerc/utils": "0.13.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@clerc/core": "0.
|
|
59
|
+
"@clerc/core": "0.13.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "puild",
|