diff --git a/src/command.ts b/src/command.ts index 18ca5c28..9094269b 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; + new(argv: string[], config: Config.IConfig, options?: RunOptions): Instance; + 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) {