path selector
This commit is contained in:
parent
d477124973
commit
f372e1ea17
18
AppTest.js
18
AppTest.js
@ -20,14 +20,16 @@ const {
|
||||
} = require ('./dist/lib/index.js');
|
||||
|
||||
(async () => {
|
||||
const str = await new StringOption ({ name: 'str' })
|
||||
.parse ();
|
||||
const bool = await new BooleanOption ({ name: 'bool' })
|
||||
.parse ();
|
||||
const num = await new NumberOption ({ name: 'num' })
|
||||
.parse ();
|
||||
const arr = await new ArrayOption ({ name: 'arr' })
|
||||
.parse ();
|
||||
/*
|
||||
* const str = await new StringOption ({ name: 'str' })
|
||||
*.parse ();
|
||||
*const bool = await new BooleanOption ({ name: 'bool' })
|
||||
*.parse ();
|
||||
*const num = await new NumberOption ({ name: 'num' })
|
||||
*.parse ();
|
||||
*const arr = await new ArrayOption ({ name: 'arr' })
|
||||
*.parse ();
|
||||
*/
|
||||
const fld = await new FolderOption ({ name: 'fld' })
|
||||
.parse ();
|
||||
|
||||
|
@ -17,7 +17,10 @@ export abstract class InteractiveSubSource {
|
||||
|
||||
public async parse ():Promise<boolean> {
|
||||
if (this.condition ()) {
|
||||
await this.run ();
|
||||
await this.run ()
|
||||
.catch ((e) => {
|
||||
console.log (e);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
25
lib/Sources/Interactive/PathCustomPrompt.ts
Normal file
25
lib/Sources/Interactive/PathCustomPrompt.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Prompt } from 'enquirer';
|
||||
|
||||
export class PathPrompt extends Prompt {
|
||||
private _index = 0;
|
||||
private _value = '';
|
||||
|
||||
public constructor (options:Record<string, unknown> = {}) {
|
||||
super (options);
|
||||
}
|
||||
|
||||
public up (): void {
|
||||
this._index--;
|
||||
this.render ();
|
||||
}
|
||||
|
||||
public down (): void {
|
||||
this._index++;
|
||||
this.render ();
|
||||
}
|
||||
|
||||
public render (): void {
|
||||
this.clear ();
|
||||
this.write (`${this.state.message}: ${this._value}`);
|
||||
}
|
||||
}
|
23
lib/Sources/Interactive/PathSubSource.ts
Normal file
23
lib/Sources/Interactive/PathSubSource.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { InteractiveSubSource } from './InteractiveSubSource';
|
||||
import { PathPrompt } from './PathCustomPrompt';
|
||||
|
||||
export class PathSubSource extends InteractiveSubSource {
|
||||
protected condition ():boolean {
|
||||
return [
|
||||
'path',
|
||||
'file',
|
||||
'folder'
|
||||
].includes (this.val.type_validation.option_type);
|
||||
}
|
||||
|
||||
protected async run (): Promise<void> {
|
||||
await this.val.assign_arg (
|
||||
this.opt,
|
||||
await new PathPrompt ({
|
||||
message: this.get_message (),
|
||||
default: this.opt.default
|
||||
})
|
||||
.run ()
|
||||
);
|
||||
}
|
||||
}
|
@ -2,10 +2,12 @@ import { ArraySubSource } from './ArraySubSource';
|
||||
import { BooleanSubSource } from './BooleanSubSource';
|
||||
import { PresetSubSource } from './PresetSubSource';
|
||||
import { StringSubSource } from './StringSubSource';
|
||||
import { PathSubSource } from './PathSubSource';
|
||||
|
||||
export const sources = [
|
||||
ArraySubSource,
|
||||
BooleanSubSource,
|
||||
PresetSubSource,
|
||||
PathSubSource,
|
||||
StringSubSource
|
||||
];
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./",
|
||||
|
Loading…
x
Reference in New Issue
Block a user