Timo Hocker
d9de76b188
All checks were successful
continuous-integration/drone/push Build is passing
39 lines
883 B
TypeScript
39 lines
883 B
TypeScript
/*
|
|
* Copyright (C) Sapphirecode - All Rights Reserved
|
|
* This file is part of console-app which is released under MIT.
|
|
* See file 'LICENSE' for full license details.
|
|
* Created by Timo Hocker <timo@scode.ovh>, October 2020
|
|
*/
|
|
|
|
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;
|
|
}
|
|
}
|