Skip to content

Commit

Permalink
feat: support src/command/index cmd (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored Aug 3, 2020
1 parent a90e317 commit 8957336
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const {
bold,
} = chalk

const ROOT_INDEX_CMD_ID = ''

export interface HelpOptions {
all?: boolean;
maxWidth: number;
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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('')
}
Expand Down

0 comments on commit 8957336

Please sign in to comment.