Skip to content
Closed
Show file tree
Hide file tree
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
54 changes: 46 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,56 @@ export default class Help {

topics(topics: Config.Topic[]): string | undefined {
if (!topics.length) return
let body = renderList(topics.map(c => [
c.name,
c.description && this.render(c.description.split('\n')[0])
]), {

let Topics: Array<string | undefined>[] = []
let Commands: Array<string | undefined>[] = []

topics.map(t => {
let out = [
t.name,
t.description && this.render(t.description.split('\n')[0])
]
if (this.config.commandIDs.includes(t.name)) {
Commands.push(out)
}
let tp = this.config.commandIDs.find(id => {
if (id.match(`${t.name}:`)) return true
return false
})
if (tp) {
Topics.push(out)
}
})

let commandsList = renderList(Commands, {
spacer: '\n',
stripAnsi: this.opts.stripAnsi,
maxWidth: this.opts.maxWidth - 2,
})
return [
bold('COMMANDS'),
indent(body, 2),
].join('\n')

let output = [
[
bold('COMMANDS'),
indent(commandsList, 2),
].join('\n')
]

if (Topics.length) {
let topicsList = renderList(Topics, {
spacer: '\n',
stripAnsi: this.opts.stripAnsi,
maxWidth: this.opts.maxWidth - 2,
})
output.push(
[
bold('TOPICS'),
indent('Run help for each topic below to view its subcommands\n', 2),
indent(topicsList, 2),
].join('\n')
)
}

return output.join('\n\n')
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/commands/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ COMMANDS
help display help for oclif
plugins list installed plugins

TOPICS
Run help for each topic below to view its subcommands

plugins list installed plugins

`)
})
})