diff --git a/package.json b/package.json index 26084814..32c29466 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index e6698855..ae9fab4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,10 +44,8 @@ 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 @@ -55,29 +53,27 @@ export default class Help { 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 { @@ -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 [ @@ -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 +// } diff --git a/yarn.lock b/yarn.lock index ab412e9b..f582c7c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"