Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Add isRunByDefault option to command.run() #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
args?: Parser.args.Input;
new(argv: string[], config: Config.IConfig): Instance;
run(argv?: string[], config?: Config.LoadOptions): PromiseLike<any>;
new(argv: string[], config: Config.IConfig, options?: RunOptions): Instance;
run(argv?: string[], config?: Config.LoadOptions, options?: RunOptions): PromiseLike<any>;
}

export interface Instance {
_run(argv: string[]): Promise<any>;
_run(argv: string[], options?: RunOptions): Promise<any>;
}

export interface Plugin extends Command {
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export interface IConfig {
readonly topics: Topic[];
readonly commandIDs: string[];

runCommand(id: string, argv?: string[]): Promise<void>;
runCommand(id: string, argv?: string[], options?: Command.RunOptions): Promise<void>;
runHook<T extends Hooks, K extends Extract<keyof T, string>>(event: K, opts: T[K]): Promise<void>;
findCommand(id: string, opts: {must: true}): Command.Plugin;
findCommand(id: string, opts?: {must: boolean}): Command.Plugin | undefined;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down