more dynamic interactive source register
This commit is contained in:
parent
f7c03f82f1
commit
d477124973
@ -15,9 +15,12 @@ export abstract class InteractiveSubSource {
|
|||||||
this.opt = opt;
|
this.opt = opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async parse ():Promise<void> {
|
public async parse ():Promise<boolean> {
|
||||||
if (this.condition ())
|
if (this.condition ()) {
|
||||||
await this.run ();
|
await this.run ();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get_message (): string {
|
protected get_message (): string {
|
||||||
|
@ -4,13 +4,7 @@ import { InteractiveSubSource } from './InteractiveSubSource';
|
|||||||
|
|
||||||
export class PresetSubSource extends InteractiveSubSource {
|
export class PresetSubSource extends InteractiveSubSource {
|
||||||
protected condition ():boolean {
|
protected condition ():boolean {
|
||||||
return [
|
return typeof (this.opt as StringOptionConfig).preset !== 'undefined';
|
||||||
'string',
|
|
||||||
'file',
|
|
||||||
'folder',
|
|
||||||
'path'
|
|
||||||
].includes (this.val.type_validation.option_type)
|
|
||||||
&& typeof (this.opt as StringOptionConfig).preset !== 'undefined';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async run ():Promise<void> {
|
protected async run ():Promise<void> {
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
import { Input } from 'enquirer';
|
import { Input } from 'enquirer';
|
||||||
import { StringOptionConfig } from '../../SubConfigs';
|
|
||||||
import { InteractiveSubSource } from './InteractiveSubSource';
|
import { InteractiveSubSource } from './InteractiveSubSource';
|
||||||
|
|
||||||
export class StringSubSource extends InteractiveSubSource {
|
export class StringSubSource extends InteractiveSubSource {
|
||||||
protected condition ():boolean {
|
protected condition ():boolean {
|
||||||
return [
|
return true;
|
||||||
'string',
|
|
||||||
'file',
|
|
||||||
'folder',
|
|
||||||
'path',
|
|
||||||
'number'
|
|
||||||
].includes (this.val.type_validation.option_type)
|
|
||||||
&& typeof (this.opt as StringOptionConfig).preset === 'undefined';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async run ():Promise<void> {
|
protected async run ():Promise<void> {
|
||||||
|
11
lib/Sources/Interactive/index.ts
Normal file
11
lib/Sources/Interactive/index.ts
Normal 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
|
||||||
|
];
|
@ -10,10 +10,7 @@
|
|||||||
import { ErrorCallback } from '../ErrorCallback';
|
import { ErrorCallback } from '../ErrorCallback';
|
||||||
import { Option, OptionValue } from '../Option';
|
import { Option, OptionValue } from '../Option';
|
||||||
import { OptionSource } from './OptionSource';
|
import { OptionSource } from './OptionSource';
|
||||||
import { ArraySubSource } from './Interactive/ArraySubSource';
|
import { sources } from './Interactive';
|
||||||
import { BooleanSubSource } from './Interactive/BooleanSubSource';
|
|
||||||
import { PresetSubSource } from './Interactive/PresetSubSource';
|
|
||||||
import { StringSubSource } from './Interactive/StringSubSource';
|
|
||||||
|
|
||||||
export class InteractiveSource extends OptionSource {
|
export class InteractiveSource extends OptionSource {
|
||||||
private _exit_on_interrupt: boolean;
|
private _exit_on_interrupt: boolean;
|
||||||
@ -29,14 +26,13 @@ export class InteractiveSource extends OptionSource {
|
|||||||
private async prompt (opt: Option, val:OptionValue): Promise<void> {
|
private async prompt (opt: Option, val:OptionValue): Promise<void> {
|
||||||
if (val.filled)
|
if (val.filled)
|
||||||
return;
|
return;
|
||||||
await new StringSubSource (val, opt)
|
|
||||||
.parse ();
|
for (const src of sources) {
|
||||||
await new PresetSubSource (val, opt)
|
// eslint-disable-next-line no-await-in-loop
|
||||||
.parse ();
|
if (await new src (val, opt)
|
||||||
await new BooleanSubSource (val, opt)
|
.parse ())
|
||||||
.parse ();
|
break;
|
||||||
await new ArraySubSource (val, opt)
|
}
|
||||||
.parse ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async parse (opt: Option, val:OptionValue): Promise<void> {
|
public async parse (opt: Option, val:OptionValue): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user