@clerc/plugin-help 0.22.0 → 0.22.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.d.ts CHANGED
@@ -20,7 +20,11 @@ interface HelpPluginOptions {
20
20
  * Global examples.
21
21
  */
22
22
  examples?: [string, string][];
23
+ /**
24
+ * Banner
25
+ */
26
+ banner?: string;
23
27
  }
24
- declare const helpPlugin: ({ command, showHelpWhenNoCommand, notes, examples, }?: HelpPluginOptions) => _clerc_core.Plugin<Clerc<{}>, Clerc<{}>>;
28
+ declare const helpPlugin: ({ command, showHelpWhenNoCommand, notes, examples, banner, }?: HelpPluginOptions) => _clerc_core.Plugin<Clerc<{}>, Clerc<{}>>;
25
29
 
26
30
  export { HelpPluginOptions, helpPlugin };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { definePlugin, Root, resolveCommand, NoSuchCommandError } from '@clerc/core';
1
+ import { definePlugin, Root, withBrackets, resolveCommand, NoSuchCommandError, formatCommandName } 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,6 @@ const render = (sections) => {
56
56
 
57
57
  const DELIMITER = pc.yellow("-");
58
58
  const NO_DESCRIPTION = "(No description)";
59
- const ROOT = "<Root>";
60
59
  const NAME = "Name:";
61
60
  const VERSION = "Version:";
62
61
  const COMMANDS = "Commands:";
@@ -69,7 +68,6 @@ const NOTES = "Notes:";
69
68
  const print = (s) => {
70
69
  process.stdout.write(s);
71
70
  };
72
- const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT;
73
71
  const generateCliDetail = (sections, cli, subcommand) => {
74
72
  const items = [
75
73
  {
@@ -109,7 +107,7 @@ const generateHelp = (ctx, notes, examples) => {
109
107
  generateCliDetail(sections, cli);
110
108
  sections.push({
111
109
  title: USAGE,
112
- body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
110
+ body: [pc.magenta(`$ ${cli._name} ${withBrackets("command", ctx.hasRootOrAlias)} [flags]`)]
113
111
  });
114
112
  const commands = [...ctx.hasRoot ? [cli._commands[Root]] : [], ...Object.values(cli._commands)].map((command) => {
115
113
  const commandNameWithAlias = [typeof command.name === "symbol" ? "" : command.name, ...toArray(command.alias || [])].sort((a, b) => {
@@ -192,9 +190,15 @@ const helpPlugin = ({
192
190
  command = true,
193
191
  showHelpWhenNoCommand = true,
194
192
  notes,
195
- examples
193
+ examples,
194
+ banner
196
195
  } = {}) => definePlugin({
197
196
  setup: (cli) => {
197
+ const printHelp = (s) => {
198
+ banner && print(`${banner}
199
+ `);
200
+ print(s);
201
+ };
198
202
  if (command) {
199
203
  cli = cli.command("help", "Show help", {
200
204
  parameters: [
@@ -212,31 +216,31 @@ const helpPlugin = ({
212
216
  ]
213
217
  }).on("help", (ctx) => {
214
218
  if (ctx.parameters.command.length) {
215
- print(generateSubcommandHelp(ctx, ctx.parameters.command));
219
+ printHelp(generateSubcommandHelp(ctx, ctx.parameters.command));
216
220
  } else {
217
- print(generateHelp(ctx, notes, examples));
221
+ printHelp(generateHelp(ctx, notes, examples));
218
222
  }
219
223
  });
220
224
  }
221
225
  cli.inspector((ctx, next) => {
222
- const hasHelpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help;
223
- if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !hasHelpFlag) {
224
- let str = "No command supplied.\n\n";
226
+ const helpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help;
227
+ if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !helpFlag) {
228
+ let str = "No command given.\n\n";
225
229
  str += generateHelp(ctx, notes, examples);
226
230
  str += "\n";
227
- print(str);
231
+ printHelp(str);
228
232
  process.exit(1);
229
- } else if (hasHelpFlag) {
233
+ } else if (helpFlag) {
230
234
  if (ctx.raw._.length) {
231
235
  if (ctx.called !== Root) {
232
236
  if (ctx.name === Root) {
233
- print(generateHelp(ctx, notes, examples));
237
+ printHelp(generateHelp(ctx, notes, examples));
234
238
  } else {
235
- print(generateSubcommandHelp(ctx, ctx.raw._));
239
+ printHelp(generateSubcommandHelp(ctx, ctx.raw._));
236
240
  }
237
241
  }
238
242
  } else {
239
- print(generateHelp(ctx, notes, examples));
243
+ printHelp(generateHelp(ctx, notes, examples));
240
244
  }
241
245
  } else {
242
246
  next();
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { definePlugin, Root, resolveCommand, NoSuchCommandError } from '@clerc/core';
1
+ import { definePlugin, Root, withBrackets, resolveCommand, NoSuchCommandError, formatCommandName } 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,6 @@ const render = (sections) => {
56
56
 
57
57
  const DELIMITER = pc.yellow("-");
58
58
  const NO_DESCRIPTION = "(No description)";
59
- const ROOT = "<Root>";
60
59
  const NAME = "Name:";
61
60
  const VERSION = "Version:";
62
61
  const COMMANDS = "Commands:";
@@ -69,7 +68,6 @@ const NOTES = "Notes:";
69
68
  const print = (s) => {
70
69
  process.stdout.write(s);
71
70
  };
72
- const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT;
73
71
  const generateCliDetail = (sections, cli, subcommand) => {
74
72
  const items = [
75
73
  {
@@ -109,7 +107,7 @@ const generateHelp = (ctx, notes, examples) => {
109
107
  generateCliDetail(sections, cli);
110
108
  sections.push({
111
109
  title: USAGE,
112
- body: [pc.magenta(`$ ${cli._name} [command] [flags]`)]
110
+ body: [pc.magenta(`$ ${cli._name} ${withBrackets("command", ctx.hasRootOrAlias)} [flags]`)]
113
111
  });
114
112
  const commands = [...ctx.hasRoot ? [cli._commands[Root]] : [], ...Object.values(cli._commands)].map((command) => {
115
113
  const commandNameWithAlias = [typeof command.name === "symbol" ? "" : command.name, ...toArray(command.alias || [])].sort((a, b) => {
@@ -192,9 +190,15 @@ const helpPlugin = ({
192
190
  command = true,
193
191
  showHelpWhenNoCommand = true,
194
192
  notes,
195
- examples
193
+ examples,
194
+ banner
196
195
  } = {}) => definePlugin({
197
196
  setup: (cli) => {
197
+ const printHelp = (s) => {
198
+ banner && print(`${banner}
199
+ `);
200
+ print(s);
201
+ };
198
202
  if (command) {
199
203
  cli = cli.command("help", "Show help", {
200
204
  parameters: [
@@ -212,31 +216,31 @@ const helpPlugin = ({
212
216
  ]
213
217
  }).on("help", (ctx) => {
214
218
  if (ctx.parameters.command.length) {
215
- print(generateSubcommandHelp(ctx, ctx.parameters.command));
219
+ printHelp(generateSubcommandHelp(ctx, ctx.parameters.command));
216
220
  } else {
217
- print(generateHelp(ctx, notes, examples));
221
+ printHelp(generateHelp(ctx, notes, examples));
218
222
  }
219
223
  });
220
224
  }
221
225
  cli.inspector((ctx, next) => {
222
- const hasHelpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help;
223
- if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !hasHelpFlag) {
224
- let str = "No command supplied.\n\n";
226
+ const helpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help;
227
+ if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !helpFlag) {
228
+ let str = "No command given.\n\n";
225
229
  str += generateHelp(ctx, notes, examples);
226
230
  str += "\n";
227
- print(str);
231
+ printHelp(str);
228
232
  process.exit(1);
229
- } else if (hasHelpFlag) {
233
+ } else if (helpFlag) {
230
234
  if (ctx.raw._.length) {
231
235
  if (ctx.called !== Root) {
232
236
  if (ctx.name === Root) {
233
- print(generateHelp(ctx, notes, examples));
237
+ printHelp(generateHelp(ctx, notes, examples));
234
238
  } else {
235
- print(generateSubcommandHelp(ctx, ctx.raw._));
239
+ printHelp(generateSubcommandHelp(ctx, ctx.raw._));
236
240
  }
237
241
  }
238
242
  } else {
239
- print(generateHelp(ctx, notes, examples));
243
+ printHelp(generateHelp(ctx, notes, examples));
240
244
  }
241
245
  } else {
242
246
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
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.22.0",
57
- "@clerc/utils": "0.22.0"
56
+ "@clerc/toolkit": "0.22.1",
57
+ "@clerc/utils": "0.22.1"
58
58
  },
59
59
  "devDependencies": {
60
- "@clerc/core": "0.22.0"
60
+ "@clerc/core": "0.22.1"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "puild",