Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support src/command/index cmd #112

Merged
merged 6 commits into from
Aug 3, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 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 @@ -98,6 +100,13 @@ export default class Help extends HelpBase {

public showHelp(argv: string[]) {
const subject = getHelpSubject(argv)
const rootCmd = this.config.findCommand(ROOT_INDEX_CMD_ID)
if (!subject && rootCmd) {
RasPhilCo marked this conversation as resolved.
Show resolved Hide resolved
this.showCommandHelp(rootCmd)
this.showRootHelp()
return
}

if (!subject) {
this.showRootHelp()
return
Expand Down Expand Up @@ -159,6 +168,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