From 0e3b914f27de100f42a0830e062d2e4d0ab1b011 Mon Sep 17 00:00:00 2001 From: Ross Adamson Date: Sat, 14 Mar 2020 14:41:56 -0600 Subject: [PATCH 1/2] Add isBeingRunByDefault option to Command.run() https://github.com/oclif/oclif/issues/277 --- src/command.ts | 8 ++++++-- src/config.ts | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/command.ts b/src/command.ts index 18ca5c28..da074827 100644 --- a/src/command.ts +++ b/src/command.ts @@ -64,16 +64,20 @@ export namespace Command { examples?: string[]; } + export type RunOptions = { + isBeingRunByDefault?: boolean + } + export interface Class extends Base { plugin?: Config.IPlugin; flags?: Parser.flags.Input; args?: Parser.args.Input; new(argv: string[], config: Config.IConfig): Instance; - run(argv?: string[], config?: Config.LoadOptions): PromiseLike; + run(argv?: string[], config?: Config.LoadOptions, options?: RunOptions): PromiseLike; } export interface Instance { - _run(argv: string[]): Promise; + _run(argv: string[], options?: RunOptions): Promise; } export interface Plugin extends Command { diff --git a/src/config.ts b/src/config.ts index 5fb2f836..0153f14d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -111,7 +111,7 @@ export interface IConfig { readonly topics: Topic[]; readonly commandIDs: string[]; - runCommand(id: string, argv?: string[]): Promise; + runCommand(id: string, argv?: string[], options?: Command.RunOptions): Promise; runHook>(event: K, opts: T[K]): Promise; findCommand(id: string, opts: {must: true}): Command.Plugin; findCommand(id: string, opts?: {must: boolean}): Command.Plugin | undefined; @@ -334,7 +334,7 @@ export class Config implements IConfig { debug('%s hook done', event) } - async runCommand(id: string, argv: string[] = []) { + async runCommand(id: string, argv: string[] = [], options?: Command.RunOptions) { debug('runCommand %s %o', id, argv) const c = this.findCommand(id) if (!c) { @@ -343,7 +343,7 @@ export class Config implements IConfig { } const command = c.load() await this.runHook('prerun', {Command: command, argv}) - await command.run(argv, this) + await command.run(argv, this, options) } scopedEnvVar(k: string) { From 744d0a2c616700ebd23fe8c5e1dd004b159480fe Mon Sep 17 00:00:00 2001 From: Ross Adamson Date: Mon, 16 Mar 2020 06:28:39 -0600 Subject: [PATCH 2/2] fixup! Add isBeingRunByDefault option to Command.run() https://github.com/oclif/oclif/issues/277 --- src/command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command.ts b/src/command.ts index da074827..9094269b 100644 --- a/src/command.ts +++ b/src/command.ts @@ -72,7 +72,7 @@ export namespace Command { plugin?: Config.IPlugin; flags?: Parser.flags.Input; args?: Parser.args.Input; - new(argv: string[], config: Config.IConfig): Instance; + new(argv: string[], config: Config.IConfig, options?: RunOptions): Instance; run(argv?: string[], config?: Config.LoadOptions, options?: RunOptions): PromiseLike; }