split interactive source
This commit is contained in:
		
							
								
								
									
										19
									
								
								lib/Sources/Interactive/ArraySubSource.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								lib/Sources/Interactive/ArraySubSource.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| import { List } from 'enquirer'; | ||||
| import { InteractiveSubSource } from './InteractiveSubSource'; | ||||
|  | ||||
| export class ArraySubSource extends InteractiveSubSource { | ||||
|   protected condition ():boolean { | ||||
|     return this.val.type_validation.option_type === 'array'; | ||||
|   } | ||||
|  | ||||
|   protected async run ():Promise<void> { | ||||
|     await this.val.assign_arg ( | ||||
|       this.opt, | ||||
|       await new List ({ | ||||
|         message: this.get_message (), | ||||
|         default: this.opt.default | ||||
|       }) | ||||
|         .run () | ||||
|     ); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										19
									
								
								lib/Sources/Interactive/BooleanSubSource.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								lib/Sources/Interactive/BooleanSubSource.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| import { Confirm } from 'enquirer'; | ||||
| import { InteractiveSubSource } from './InteractiveSubSource'; | ||||
|  | ||||
| export class BooleanSubSource extends InteractiveSubSource { | ||||
|   protected condition ():boolean { | ||||
|     return this.val.type_validation.option_type === 'boolean'; | ||||
|   } | ||||
|  | ||||
|   protected async run ():Promise<void> { | ||||
|     await this.val.assign_arg ( | ||||
|       this.opt, | ||||
|       await new Confirm ({ | ||||
|         message: this.get_message (), | ||||
|         default: this.opt.default | ||||
|       }) | ||||
|         .run () | ||||
|     ); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										28
									
								
								lib/Sources/Interactive/InteractiveSubSource.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								lib/Sources/Interactive/InteractiveSubSource.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| 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<void> { | ||||
|     if (this.condition ()) | ||||
|       await this.run (); | ||||
|   } | ||||
|  | ||||
|   protected get_message (): string { | ||||
|     return typeof this.opt.message === 'undefined' | ||||
|       ? `input ${this.opt.name}` | ||||
|       : this.opt.message; | ||||
|   } | ||||
| } | ||||
							
								
								
									
										28
									
								
								lib/Sources/Interactive/PresetSubSource.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								lib/Sources/Interactive/PresetSubSource.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| import { AutoComplete } from 'enquirer'; | ||||
| import { StringOptionConfig } from '../../SubConfigs'; | ||||
| 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'; | ||||
|   } | ||||
|  | ||||
|   protected async run ():Promise<void> { | ||||
|     await this.val.assign_arg ( | ||||
|       this.opt, | ||||
|       await new AutoComplete ({ | ||||
|         message: this.get_message (), | ||||
|         default: this.opt.default, | ||||
|         choices: (this.opt as StringOptionConfig).preset, | ||||
|         limit:   10 | ||||
|       }) | ||||
|         .run () | ||||
|     ); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										27
									
								
								lib/Sources/Interactive/StringSubSource.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								lib/Sources/Interactive/StringSubSource.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| 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'; | ||||
|   } | ||||
|  | ||||
|   protected async run ():Promise<void> { | ||||
|     await this.val.assign_arg ( | ||||
|       this.opt, | ||||
|       await new Input ({ | ||||
|         message: this.get_message (), | ||||
|         default: this.opt.default | ||||
|       }) | ||||
|         .run () | ||||
|     ); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user