more dynamic interactive source register

This commit is contained in:
2020-06-16 09:40:12 +02:00
parent f7c03f82f1
commit d477124973
5 changed files with 26 additions and 30 deletions

View File

@ -15,9 +15,12 @@ export abstract class InteractiveSubSource {
this.opt = opt;
}
public async parse ():Promise<void> {
if (this.condition ())
public async parse ():Promise<boolean> {
if (this.condition ()) {
await this.run ();
return true;
}
return false;
}
protected get_message (): string {

View File

@ -4,13 +4,7 @@ import { InteractiveSubSource } from './InteractiveSubSource';
export class PresetSubSource extends InteractiveSubSource {
protected condition ():boolean {
return [
'string',
'file',
'folder',
'path'
].includes (this.val.type_validation.option_type)
&& typeof (this.opt as StringOptionConfig).preset !== 'undefined';
return typeof (this.opt as StringOptionConfig).preset !== 'undefined';
}
protected async run ():Promise<void> {

View File

@ -1,17 +1,9 @@
import { Input } from 'enquirer';
import { StringOptionConfig } from '../../SubConfigs';
import { InteractiveSubSource } from './InteractiveSubSource';
export class StringSubSource extends InteractiveSubSource {
protected condition ():boolean {
return [
'string',
'file',
'folder',
'path',
'number'
].includes (this.val.type_validation.option_type)
&& typeof (this.opt as StringOptionConfig).preset === 'undefined';
return true;
}
protected async run ():Promise<void> {

View File

@ -0,0 +1,11 @@
import { ArraySubSource } from './ArraySubSource';
import { BooleanSubSource } from './BooleanSubSource';
import { PresetSubSource } from './PresetSubSource';
import { StringSubSource } from './StringSubSource';
export const sources = [
ArraySubSource,
BooleanSubSource,
PresetSubSource,
StringSubSource
];