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');
|
} = require ('./dist/lib/index.js');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const str = await new StringOption ({ name: 'str' })
|
/*
|
||||||
.parse ();
|
* const str = await new StringOption ({ name: 'str' })
|
||||||
const bool = await new BooleanOption ({ name: 'bool' })
|
*.parse ();
|
||||||
.parse ();
|
*const bool = await new BooleanOption ({ name: 'bool' })
|
||||||
const num = await new NumberOption ({ name: 'num' })
|
*.parse ();
|
||||||
.parse ();
|
*const num = await new NumberOption ({ name: 'num' })
|
||||||
const arr = await new ArrayOption ({ name: 'arr' })
|
*.parse ();
|
||||||
.parse ();
|
*const arr = await new ArrayOption ({ name: 'arr' })
|
||||||
|
*.parse ();
|
||||||
|
*/
|
||||||
const fld = await new FolderOption ({ name: 'fld' })
|
const fld = await new FolderOption ({ name: 'fld' })
|
||||||
.parse ();
|
.parse ();
|
||||||
|
|
||||||
|
@ -17,7 +17,10 @@ export abstract class InteractiveSubSource {
|
|||||||
|
|
||||||
public async parse ():Promise<boolean> {
|
public async parse ():Promise<boolean> {
|
||||||
if (this.condition ()) {
|
if (this.condition ()) {
|
||||||
await this.run ();
|
await this.run ()
|
||||||
|
.catch ((e) => {
|
||||||
|
console.log (e);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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 { BooleanSubSource } from './BooleanSubSource';
|
||||||
import { PresetSubSource } from './PresetSubSource';
|
import { PresetSubSource } from './PresetSubSource';
|
||||||
import { StringSubSource } from './StringSubSource';
|
import { StringSubSource } from './StringSubSource';
|
||||||
|
import { PathSubSource } from './PathSubSource';
|
||||||
|
|
||||||
export const sources = [
|
export const sources = [
|
||||||
ArraySubSource,
|
ArraySubSource,
|
||||||
BooleanSubSource,
|
BooleanSubSource,
|
||||||
PresetSubSource,
|
PresetSubSource,
|
||||||
|
PathSubSource,
|
||||||
StringSubSource
|
StringSubSource
|
||||||
];
|
];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"rootDir": "./",
|
"rootDir": "./",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user