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

feat: move console.log to single class method #400

Merged
merged 1 commit into from Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 25 additions & 21 deletions src/help/index.ts
Expand Up @@ -136,24 +136,24 @@ export class Help extends HelpBase {
const plugin = this.config.plugins.find(p => p.name === command.pluginName)

const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state
if (state) console.log(`This command is in ${state}.\n`)
if (state) this.log(`This command is in ${state}.\n`)

const summary = this.summary(command)
if (summary) {
console.log(summary + '\n')
this.log(summary + '\n')
}

console.log(this.formatCommand(command))
console.log('')
this.log(this.formatCommand(command))
this.log('')

if (subTopics.length > 0) {
console.log(this.formatTopics(subTopics))
console.log('')
this.log(this.formatTopics(subTopics))
this.log('')
}

if (subCommands.length > 0) {
console.log(this.formatCommands(subCommands))
console.log('')
this.log(this.formatCommands(subCommands))
this.log('')
}
}

Expand All @@ -162,24 +162,24 @@ export class Help extends HelpBase {
let rootCommands = this.sortedCommands

const state = this.config.pjson?.oclif?.state
if (state) console.log(`${this.config.bin} is in ${state}.\n`)
console.log(this.formatRoot())
console.log('')
if (state) this.log(`${this.config.bin} is in ${state}.\n`)
this.log(this.formatRoot())
this.log('')

if (!this.opts.all) {
rootTopics = rootTopics.filter(t => !t.name.includes(':'))
rootCommands = rootCommands.filter(c => !c.id.includes(':'))
}

if (rootTopics.length > 0) {
console.log(this.formatTopics(rootTopics))
console.log('')
this.log(this.formatTopics(rootTopics))
this.log('')
}

if (rootCommands.length > 0) {
rootCommands = rootCommands.filter(c => c.id)
console.log(this.formatCommands(rootCommands))
console.log('')
this.log(this.formatCommands(rootCommands))
this.log('')
}
}

Expand All @@ -191,18 +191,18 @@ export class Help extends HelpBase {
const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1)

const state = this.config.pjson?.oclif?.state
if (state) console.log(`This topic is in ${state}.\n`)
if (state) this.log(`This topic is in ${state}.\n`)

console.log(this.formatTopic(topic))
this.log(this.formatTopic(topic))

if (subTopics.length > 0) {
console.log(this.formatTopics(subTopics))
console.log('')
this.log(this.formatTopics(subTopics))
this.log('')
}

if (commands.length > 0) {
console.log(this.formatCommands(commands))
console.log('')
this.log(this.formatCommands(commands))
this.log('')
}
}

Expand Down Expand Up @@ -297,4 +297,8 @@ export class Help extends HelpBase {
protected command(command: Interfaces.Command) {
return this.formatCommand(command)
}

protected log(...args: string[]) {
console.log(...args)
}
}