@clerc/plugin-help 0.13.1 → 0.14.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.d.ts CHANGED
@@ -7,6 +7,11 @@ interface HelpPluginOptions {
7
7
  * @default true
8
8
  */
9
9
  command?: boolean;
10
+ /**
11
+ * Whether to show help when no command is specified.
12
+ * @default true
13
+ */
14
+ showHelpWhenNoCommand?: boolean;
10
15
  /**
11
16
  * Global notes.
12
17
  */
@@ -16,6 +21,6 @@ interface HelpPluginOptions {
16
21
  */
17
22
  examples?: [string, string][];
18
23
  }
19
- declare const helpPlugin: ({ command, notes, examples, }?: HelpPluginOptions) => _clerc_core.Plugin<Clerc<{}>, Clerc<{}>>;
24
+ declare const helpPlugin: ({ command, showHelpWhenNoCommand, notes, examples, }?: HelpPluginOptions) => _clerc_core.Plugin<Clerc<{}>, Clerc<{}>>;
20
25
 
21
26
  export { HelpPluginOptions, helpPlugin };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
2
- import { gracefulFlagName } from '@clerc/utils';
2
+ import { mustArray, gracefulFlagName } from '@clerc/utils';
3
3
  import pc from 'picocolors';
4
4
  import { Table } from '@clerc/toolkit';
5
5
 
@@ -52,17 +52,17 @@ const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeo
52
52
  const generateCliDetail = (sections, cli, subcommand) => {
53
53
  const items = [
54
54
  {
55
- title: pc.gray("Name:"),
55
+ title: "Name:",
56
56
  body: pc.red(cli._name)
57
57
  },
58
58
  {
59
- title: pc.gray("Version:"),
59
+ title: "Version:",
60
60
  body: pc.yellow(cli._version)
61
61
  }
62
62
  ];
63
63
  if (subcommand) {
64
64
  items.push({
65
- title: pc.gray("Subcommand:"),
65
+ title: "Subcommand:",
66
66
  body: pc.green(formatCommandName(subcommand.name))
67
67
  });
68
68
  }
@@ -89,19 +89,20 @@ const showHelp = (ctx, notes, examples) => {
89
89
  if (ctx.isSingleCommand) {
90
90
  sections.push({
91
91
  title: "Usage:",
92
- body: [`$ ${cli._name} [flags]`]
92
+ body: [pc.magenta(`$ ${cli._name} [flags]`)]
93
93
  });
94
94
  } else {
95
95
  sections.push({
96
96
  title: "Usage:",
97
- body: [`$ ${cli._name} [command] [flags]`]
97
+ body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
98
98
  });
99
99
  }
100
100
  if (!ctx.isSingleCommand) {
101
101
  sections.push({
102
102
  title: "Commands:",
103
103
  body: table(...Object.values(cli._commands).map((command) => {
104
- return [pc.cyan(command.name), DELIMITER, command.description];
104
+ const commandNameWithAlias = [command.name, ...mustArray(command.alias || [])].join(", ");
105
+ return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
105
106
  })).toString().split("\n")
106
107
  });
107
108
  }
@@ -163,6 +164,7 @@ const showSubcommandHelp = (ctx, command) => {
163
164
  };
164
165
  const helpPlugin = ({
165
166
  command = true,
167
+ showHelpWhenNoCommand = true,
166
168
  notes,
167
169
  examples
168
170
  } = {}) => definePlugin({
@@ -191,7 +193,9 @@ const helpPlugin = ({
191
193
  });
192
194
  }
193
195
  cli.inspector((ctx, next) => {
194
- if (ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help) {
196
+ if (!ctx.isSingleCommand && !ctx.raw._.length && showHelpWhenNoCommand) {
197
+ showHelp(ctx, notes, examples);
198
+ } else if (ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help) {
195
199
  if (ctx.raw._.length) {
196
200
  showSubcommandHelp(ctx, ctx.raw._);
197
201
  } else {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { definePlugin, resolveCommand, NoSuchCommandError, SingleCommand } from '@clerc/core';
2
- import { gracefulFlagName } from '@clerc/utils';
2
+ import { mustArray, gracefulFlagName } from '@clerc/utils';
3
3
  import pc from 'picocolors';
4
4
  import { Table } from '@clerc/toolkit';
5
5
 
@@ -52,17 +52,17 @@ const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeo
52
52
  const generateCliDetail = (sections, cli, subcommand) => {
53
53
  const items = [
54
54
  {
55
- title: pc.gray("Name:"),
55
+ title: "Name:",
56
56
  body: pc.red(cli._name)
57
57
  },
58
58
  {
59
- title: pc.gray("Version:"),
59
+ title: "Version:",
60
60
  body: pc.yellow(cli._version)
61
61
  }
62
62
  ];
63
63
  if (subcommand) {
64
64
  items.push({
65
- title: pc.gray("Subcommand:"),
65
+ title: "Subcommand:",
66
66
  body: pc.green(formatCommandName(subcommand.name))
67
67
  });
68
68
  }
@@ -89,19 +89,20 @@ const showHelp = (ctx, notes, examples) => {
89
89
  if (ctx.isSingleCommand) {
90
90
  sections.push({
91
91
  title: "Usage:",
92
- body: [`$ ${cli._name} [flags]`]
92
+ body: [pc.magenta(`$ ${cli._name} [flags]`)]
93
93
  });
94
94
  } else {
95
95
  sections.push({
96
96
  title: "Usage:",
97
- body: [`$ ${cli._name} [command] [flags]`]
97
+ body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
98
98
  });
99
99
  }
100
100
  if (!ctx.isSingleCommand) {
101
101
  sections.push({
102
102
  title: "Commands:",
103
103
  body: table(...Object.values(cli._commands).map((command) => {
104
- return [pc.cyan(command.name), DELIMITER, command.description];
104
+ const commandNameWithAlias = [command.name, ...mustArray(command.alias || [])].join(", ");
105
+ return [pc.cyan(commandNameWithAlias), DELIMITER, command.description];
105
106
  })).toString().split("\n")
106
107
  });
107
108
  }
@@ -163,6 +164,7 @@ const showSubcommandHelp = (ctx, command) => {
163
164
  };
164
165
  const helpPlugin = ({
165
166
  command = true,
167
+ showHelpWhenNoCommand = true,
166
168
  notes,
167
169
  examples
168
170
  } = {}) => definePlugin({
@@ -191,7 +193,9 @@ const helpPlugin = ({
191
193
  });
192
194
  }
193
195
  cli.inspector((ctx, next) => {
194
- if (ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help) {
196
+ if (!ctx.isSingleCommand && !ctx.raw._.length && showHelpWhenNoCommand) {
197
+ showHelp(ctx, notes, examples);
198
+ } else if (ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help) {
195
199
  if (ctx.raw._.length) {
196
200
  showSubcommandHelp(ctx, ctx.raw._);
197
201
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "0.13.1",
3
+ "version": "0.14.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.13.1",
56
- "@clerc/utils": "0.13.1"
55
+ "@clerc/toolkit": "0.14.0",
56
+ "@clerc/utils": "0.14.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@clerc/core": "0.13.1"
59
+ "@clerc/core": "0.14.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "puild",