32 lines
653 B
TypeScript
32 lines
653 B
TypeScript
import { OptionValue, Option } from '../../Option';
|
|
|
|
export abstract class InteractiveSubSource {
|
|
protected val: OptionValue;
|
|
protected opt: Option;
|
|
|
|
protected abstract condition():boolean;
|
|
protected abstract async run():Promise<void>;
|
|
|
|
public constructor (
|
|
val:OptionValue,
|
|
opt:Option
|
|
) {
|
|
this.val = val;
|
|
this.opt = opt;
|
|
}
|
|
|
|
public async parse ():Promise<boolean> {
|
|
if (this.condition ()) {
|
|
await this.run ();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected get_message (): string {
|
|
return typeof this.opt.message === 'undefined'
|
|
? `input ${this.opt.name}`
|
|
: this.opt.message;
|
|
}
|
|
}
|