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

fix: move ctor for command help class to its own function #244

Merged
merged 3 commits into from
Sep 14, 2021
Merged
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
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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the stripping of help flags to showHelp from main.ts.

Other function call via showHelp expect the help flags to be removed.


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)
Comment on lines -205 to +207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a whole new method for this if this is the only place it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RodEsp This function will be overridden in the custom help class to allow the determination of short help.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main.ts should not have any knowledge of what showHelp expects in argv, just pass the whole thing as is.

const Help = await loadHelpClass(config)
const help = new Help(config, config.pjson.helpOptions)
peternhale marked this conversation as resolved.
Show resolved Hide resolved
await help.showHelp(argv)
Expand Down