Skip to content

Commit

Permalink
fix: use topics only
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 17, 2018
1 parent 001b486 commit 81c089f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"wrap-ansi": "^3.0.1"
},
"devDependencies": {
"@oclif/config": "^1.3.56",
"@oclif/config": "^1.3.57",
"@oclif/dev-cli": "^1.2.16",
"@oclif/errors": "^1.0.2",
"@oclif/plugin-legacy": "^1.0.4",
Expand Down
42 changes: 18 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,36 @@ export default class Help {
}
}
let topics = this.config.topics
let commands = this.config.commands
commands = commands.filter(c => this.opts.all || !c.hidden)
commands = sortBy(commands, c => c.id)
commands = uniqBy(commands, c => c.id)
topics = sortBy(topics, t => t.name)
topics = uniqBy(topics, t => t.name)
let subject = getHelpSubject()
let command: Config.Command | undefined
let topic: Config.Topic | undefined
if (!subject) {
console.log(this.root())
console.log()
if (!this.opts.all) {
commands = commands.filter(c => !c.id.includes(':'))
topics = topics.filter(t => !t.name.includes(':'))
}
console.log(this.commands([...topics, ...commands]))
console.log(this.topics(topics))
console.log()
} else if (command = this.config.findCommand(subject)) {
const id = command.id
const depth = id.split(':').length
commands = commands.filter(c => c.id.startsWith(id) && c.id.split(':').length === depth + 1)
topics = topics.filter(t => t.name.startsWith(id) && t.name.split(':').length === depth + 1)
const name = command.id
topics = topics.filter(t => t.name.startsWith(name + ':'))
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 (commands.length) {
console.log(this.commands(commands))
if (topics.length) {
console.log(this.topics(topics))
console.log()
}
} else if (topic = this.config.findTopic(subject)) {
const name = topic.name
console.log(this.topic(topic))
commands = commands.filter(c => c.id.startsWith(topic!.name))
if (commands.length) {
console.log(this.commands(commands))
topics = topics.filter(t => t.name.startsWith(name + ':'))
if (topics.length) {
console.log(this.topics(topics))
console.log()
}
} else {
Expand Down Expand Up @@ -114,12 +110,10 @@ export default class Help {
return help.command(command)
}

commands(commands: (Config.Command | Config.Topic)[]): string | undefined {
if (!commands.length) return
commands = uniqBy(commands, id)
commands = sortBy(commands, id)
let body = renderList(commands.map(c => [
id(c),
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])
]), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2})
return [
Expand All @@ -129,6 +123,6 @@ export default class Help {
}
}

function id(c: Config.Command | Config.Topic): string {
return (c as any).id || (c as any).name
}
// function id(c: Config.Command | Config.Topic): string {
// return (c as any).id || (c as any).name
// }
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"@oclif/parser" "^3.2.9"
semver "^5.5.0"

"@oclif/config@^1.3.56":
version "1.3.56"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.3.56.tgz#daa92087dda5fd649d4aeea9cc44aef92b854e7f"
"@oclif/config@^1.3.56", "@oclif/config@^1.3.57":
version "1.3.57"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.3.57.tgz#845ed86c01911860d49853aaab28f76c7f7a5f43"

"@oclif/dev-cli@^1.2.16":
version "1.2.16"
Expand Down Expand Up @@ -73,8 +73,8 @@
"@heroku/linewrap" "^1.0.0"

"@oclif/plugin-help@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-1.1.0.tgz#15c760a1049e13e1f47f0ebac60a3f64bfbfd922"
version "1.1.1"
resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-1.1.1.tgz#29889ca64ef8fa07806fa29805dbdedcb957e796"
dependencies:
"@oclif/command" "^1.3.1"
chalk "^2.3.1"
Expand Down

0 comments on commit 81c089f

Please sign in to comment.