Skip to content

Commit

Permalink
fix: move ctor for command help class to its own function (#244)
Browse files Browse the repository at this point in the history
* fix: move ctor for command help class to its own function

@W-9708749@

* chore: add property to capture original argv

* chore: apply review comments
  • Loading branch information
peternhale authored Sep 14, 2021
1 parent 8a40cc1 commit 26f2445
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/help/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class Help extends HelpBase {
}

public async showHelp(argv: string[]) {
argv = argv.filter(arg => !getHelpFlagAdditions(this.config).includes(arg))

if (this.config.topicSeparator !== ':') argv = standardizeIDFromArgv(argv, this.config)
const subject = getHelpSubject(argv, this.config)
if (!subject) {
Expand Down Expand Up @@ -202,10 +204,14 @@ export class Help extends HelpBase {
command.id = command.id.replace(/:/g, this.config.topicSeparator)
command.aliases = command.aliases && command.aliases.map(a => a.replace(/:/g, this.config.topicSeparator))
}
const help = new this.CommandHelpClass(command, this.config, this.opts)
const help = this.getCommandHelpClass(command)
return help.generate()
}

protected getCommandHelpClass(command: Interfaces.Command) {
return new this.CommandHelpClass(command, this.config, this.opts)
}

protected formatCommands(commands: Interfaces.Command[]): string {
if (commands.length === 0) return ''

Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function run(argv = process.argv.slice(2), options?: Interfaces.Loa

// display help version if applicable
if (helpAddition(argv, config)) {
argv = argv.filter(arg => !getHelpFlagAdditions(config).includes(arg))
const Help = await loadHelpClass(config)
const help = new Help(config, config.pjson.helpOptions)
await help.showHelp(argv)
Expand Down

0 comments on commit 26f2445

Please sign in to comment.