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

Expose command help method #33

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Changes from all 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
26 changes: 15 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,7 @@ export default class Help {
console.log(this.topics(topics))
console.log()
} else if (command = this.config.findCommand(subject)) {
const name = command.id
const depth = name.split(':').length
topics = topics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1)
let title = command.description && this.render(command.description).split('\n')[0]
if (title) console.log(title + '\n')
console.log(this.command(command))
console.log()
if (topics.length) {
console.log(this.topics(topics))
console.log()
}
this.showCommandHelp(command, topics)
} else if (topic = this.config.findTopic(subject)) {
const name = topic.name
const depth = name.split(':').length
Expand All @@ -84,6 +74,20 @@ export default class Help {
}
}

showCommandHelp(command: Config.Command, topics: Config.Topic[]) {
const name = command.id
const depth = name.split(':').length
topics = topics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1)
let title = command.description && this.render(command.description).split('\n')[0]
if (title) console.log(title + '\n')
console.log(this.command(command))
console.log()
if (topics.length) {
console.log(this.topics(topics))
console.log()
}
}

root(): string {
const help = new RootHelp(this.config, this.opts)
return help.root()
Expand Down