@clerc/plugin-help
Advanced tools
Comparing version 0.22.0 to 0.22.1
@@ -23,5 +23,9 @@ import * as _clerc_core from '@clerc/core'; | ||
examples?: [string, string][]; | ||
/** | ||
* Banner | ||
*/ | ||
banner?: string; | ||
} | ||
declare const helpPlugin: ({ command, showHelpWhenNoCommand, notes, examples, }?: HelpPluginOptions) => _clerc_core.Plugin<Clerc<{}>, Clerc<{}>>; | ||
declare const helpPlugin: ({ command, showHelpWhenNoCommand, notes, examples, banner, }?: HelpPluginOptions) => _clerc_core.Plugin<Clerc<{}>, Clerc<{}>>; | ||
export { HelpPluginOptions, helpPlugin }; |
@@ -1,2 +0,2 @@ | ||
import { definePlugin, Root, resolveCommand, NoSuchCommandError } from '@clerc/core'; | ||
import { definePlugin, Root, withBrackets, resolveCommand, NoSuchCommandError, formatCommandName } from '@clerc/core'; | ||
import { toArray, gracefulFlagName } from '@clerc/utils'; | ||
@@ -59,3 +59,2 @@ import pc from 'picocolors'; | ||
const NO_DESCRIPTION = "(No description)"; | ||
const ROOT = "<Root>"; | ||
const NAME = "Name:"; | ||
@@ -73,3 +72,2 @@ const VERSION = "Version:"; | ||
}; | ||
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT; | ||
const generateCliDetail = (sections, cli, subcommand) => { | ||
@@ -114,3 +112,3 @@ const items = [ | ||
title: USAGE, | ||
body: [pc.magenta(`$ ${cli._name} [command] [flags]`)] | ||
body: [pc.magenta(`$ ${cli._name} ${withBrackets("command", ctx.hasRootOrAlias)} [flags]`)] | ||
}); | ||
@@ -198,5 +196,11 @@ const commands = [...ctx.hasRoot ? [cli._commands[Root]] : [], ...Object.values(cli._commands)].map((command) => { | ||
notes, | ||
examples | ||
examples, | ||
banner | ||
} = {}) => definePlugin({ | ||
setup: (cli) => { | ||
const printHelp = (s) => { | ||
banner && print(`${banner} | ||
`); | ||
print(s); | ||
}; | ||
if (command) { | ||
@@ -219,5 +223,5 @@ cli = cli.command("help", "Show help", { | ||
if (ctx.parameters.command.length) { | ||
print(generateSubcommandHelp(ctx, ctx.parameters.command)); | ||
printHelp(generateSubcommandHelp(ctx, ctx.parameters.command)); | ||
} else { | ||
print(generateHelp(ctx, notes, examples)); | ||
printHelp(generateHelp(ctx, notes, examples)); | ||
} | ||
@@ -227,20 +231,20 @@ }); | ||
cli.inspector((ctx, next) => { | ||
const hasHelpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help; | ||
if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !hasHelpFlag) { | ||
let str = "No command supplied.\n\n"; | ||
const helpFlag = ctx.raw.mergedFlags.h || ctx.raw.mergedFlags.help; | ||
if (!ctx.hasRootOrAlias && !ctx.raw._.length && showHelpWhenNoCommand && !helpFlag) { | ||
let str = "No command given.\n\n"; | ||
str += generateHelp(ctx, notes, examples); | ||
str += "\n"; | ||
print(str); | ||
printHelp(str); | ||
process.exit(1); | ||
} else if (hasHelpFlag) { | ||
} else if (helpFlag) { | ||
if (ctx.raw._.length) { | ||
if (ctx.called !== Root) { | ||
if (ctx.name === Root) { | ||
print(generateHelp(ctx, notes, examples)); | ||
printHelp(generateHelp(ctx, notes, examples)); | ||
} else { | ||
print(generateSubcommandHelp(ctx, ctx.raw._)); | ||
printHelp(generateSubcommandHelp(ctx, ctx.raw._)); | ||
} | ||
} | ||
} else { | ||
print(generateHelp(ctx, notes, examples)); | ||
printHelp(generateHelp(ctx, notes, examples)); | ||
} | ||
@@ -247,0 +251,0 @@ } else { |
{ | ||
"name": "@clerc/plugin-help", | ||
"version": "0.22.0", | ||
"version": "0.22.1", | ||
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)", | ||
@@ -56,7 +56,7 @@ "description": "Clerc plugin help", | ||
"picocolors": "^1.0.0", | ||
"@clerc/toolkit": "0.22.0", | ||
"@clerc/utils": "0.22.0" | ||
"@clerc/toolkit": "0.22.1", | ||
"@clerc/utils": "0.22.1" | ||
}, | ||
"devDependencies": { | ||
"@clerc/core": "0.22.0" | ||
"@clerc/core": "0.22.1" | ||
}, | ||
@@ -63,0 +63,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
18233
526
+ Added@clerc/toolkit@0.22.1(transitive)
+ Added@clerc/utils@0.22.1(transitive)
- Removed@clerc/toolkit@0.22.0(transitive)
- Removed@clerc/utils@0.22.0(transitive)
Updated@clerc/toolkit@0.22.1
Updated@clerc/utils@0.22.1