From b44e4df8fe7b49322548215a2912f7c43581b227 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Mon, 13 Sep 2021 11:36:50 -0600 Subject: [PATCH 1/3] fix: move ctor for command help class to its own function @W-9708749@ --- src/help/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/help/index.ts b/src/help/index.ts index ba373de98..07eae6d63 100644 --- a/src/help/index.ts +++ b/src/help/index.ts @@ -202,10 +202,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 '' From bac8cf049730931f1a90d4ed554918b93fe2b845 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Mon, 13 Sep 2021 14:46:55 -0600 Subject: [PATCH 2/3] chore: add property to capture original argv --- src/help/index.ts | 10 ++++++++++ src/main.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/help/index.ts b/src/help/index.ts index 07eae6d63..968c7bb9d 100644 --- a/src/help/index.ts +++ b/src/help/index.ts @@ -30,11 +30,21 @@ function getHelpSubject(args: string[], config: Interfaces.Config): string | und } export abstract class HelpBase extends HelpFormatter { + private argvCopy: string[] = [] + constructor(config: Interfaces.Config, opts: Partial = {}) { super(config, opts) if (!config.topicSeparator) config.topicSeparator = ':' // back-support @oclif/config } + public get originalArgv(): string[] { + return this.argvCopy + } + + public set originalArgv(argv: string[]) { + this.argvCopy = argv + } + /** * Show help, used in multi-command CLIs * @param args passed into your command, useful for determining which type of help to display diff --git a/src/main.ts b/src/main.ts index 822febd29..6ffa3bf3c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,6 +30,7 @@ export const versionAddition = (argv: string[], config?: Interfaces.Config): boo } export async function run(argv = process.argv.slice(2), options?: Interfaces.LoadOptions) { + const originalArgv = [...argv] // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path. if ((typeof options === 'string' && options.startsWith('file://')) || options instanceof URL) { options = fileURLToPath(options) @@ -54,6 +55,7 @@ export async function run(argv = process.argv.slice(2), options?: Interfaces.Loa argv = argv.filter(arg => !getHelpFlagAdditions(config).includes(arg)) const Help = await loadHelpClass(config) const help = new Help(config, config.pjson.helpOptions) + help.originalArgv = originalArgv await help.showHelp(argv) return } From e66aef6193a805c8f8343535b1906d6f8399c658 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Tue, 14 Sep 2021 07:11:06 -0600 Subject: [PATCH 3/3] chore: apply review comments --- src/help/index.ts | 12 ++---------- src/main.ts | 3 --- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/help/index.ts b/src/help/index.ts index 968c7bb9d..6e32be751 100644 --- a/src/help/index.ts +++ b/src/help/index.ts @@ -30,21 +30,11 @@ function getHelpSubject(args: string[], config: Interfaces.Config): string | und } export abstract class HelpBase extends HelpFormatter { - private argvCopy: string[] = [] - constructor(config: Interfaces.Config, opts: Partial = {}) { super(config, opts) if (!config.topicSeparator) config.topicSeparator = ':' // back-support @oclif/config } - public get originalArgv(): string[] { - return this.argvCopy - } - - public set originalArgv(argv: string[]) { - this.argvCopy = argv - } - /** * Show help, used in multi-command CLIs * @param args passed into your command, useful for determining which type of help to display @@ -100,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) { diff --git a/src/main.ts b/src/main.ts index 6ffa3bf3c..ba30fe8ec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,6 @@ export const versionAddition = (argv: string[], config?: Interfaces.Config): boo } export async function run(argv = process.argv.slice(2), options?: Interfaces.LoadOptions) { - const originalArgv = [...argv] // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path. if ((typeof options === 'string' && options.startsWith('file://')) || options instanceof URL) { options = fileURLToPath(options) @@ -52,10 +51,8 @@ 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) - help.originalArgv = originalArgv await help.showHelp(argv) return }