From 8957336f3c35675bb243ac90c49c298fbef23e59 Mon Sep 17 00:00:00 2001 From: RasPhilCo Date: Mon, 3 Aug 2020 10:37:00 -0700 Subject: [PATCH] feat: support src/command/index cmd (#112) --- src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index b2bf1969..87a06d33 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,8 @@ const { bold, } = chalk +const ROOT_INDEX_CMD_ID = '' + export interface HelpOptions { all?: boolean; maxWidth: number; @@ -25,8 +27,8 @@ export interface HelpOptions { function getHelpSubject(args: string[]): string | undefined { for (const arg of args) { if (arg === '--') return - if (arg.startsWith('-')) continue - if (arg === 'help') continue + if (arg === 'help' || arg === '--help' || arg === '-h') continue + if (arg.startsWith('-')) return return arg } } @@ -99,6 +101,8 @@ export default class Help extends HelpBase { public showHelp(argv: string[]) { const subject = getHelpSubject(argv) if (!subject) { + const rootCmd = this.config.findCommand(ROOT_INDEX_CMD_ID) + if (rootCmd) this.showCommandHelp(rootCmd) this.showRootHelp() return } @@ -159,6 +163,7 @@ export default class Help extends HelpBase { } if (rootCommands.length > 0) { + rootCommands = rootCommands.filter(c => c.id) console.log(this.formatCommands(rootCommands)) console.log('') }