more dynamic interactive source register
This commit is contained in:
		@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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> {
 | 
			
		||||
 
 | 
			
		||||
@@ -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> {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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 { Option, OptionValue } from '../Option';
 | 
			
		||||
import { OptionSource } from './OptionSource';
 | 
			
		||||
import { ArraySubSource } from './Interactive/ArraySubSource';
 | 
			
		||||
import { BooleanSubSource } from './Interactive/BooleanSubSource';
 | 
			
		||||
import { PresetSubSource } from './Interactive/PresetSubSource';
 | 
			
		||||
import { StringSubSource } from './Interactive/StringSubSource';
 | 
			
		||||
import { sources } from './Interactive';
 | 
			
		||||
 | 
			
		||||
export class InteractiveSource extends OptionSource {
 | 
			
		||||
  private _exit_on_interrupt: boolean;
 | 
			
		||||
@@ -29,14 +26,13 @@ export class InteractiveSource extends OptionSource {
 | 
			
		||||
  private async prompt (opt: Option, val:OptionValue): Promise<void> {
 | 
			
		||||
    if (val.filled)
 | 
			
		||||
      return;
 | 
			
		||||
    await new StringSubSource (val, opt)
 | 
			
		||||
      .parse ();
 | 
			
		||||
    await new PresetSubSource (val, opt)
 | 
			
		||||
      .parse ();
 | 
			
		||||
    await new BooleanSubSource (val, opt)
 | 
			
		||||
      .parse ();
 | 
			
		||||
    await new ArraySubSource (val, opt)
 | 
			
		||||
      .parse ();
 | 
			
		||||
 | 
			
		||||
    for (const src of sources) {
 | 
			
		||||
      // eslint-disable-next-line no-await-in-loop
 | 
			
		||||
      if (await new src (val, opt)
 | 
			
		||||
        .parse ())
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async parse (opt: Option, val:OptionValue): Promise<void> {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user