Skip to content

Commit

Permalink
fix: Expose command help method (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Willer authored and jdx committed Nov 12, 2018
1 parent 63d4a6c commit 0c0a0d9
Showing 1 changed file with 15 additions and 11 deletions.
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

0 comments on commit 0c0a0d9

Please sign in to comment.