prompt will have to be self made, or extending more basic levels of enquirer

This commit is contained in:
Timo Hocker 2020-06-18 13:58:38 +02:00
parent f372e1ea17
commit 62ae2990a6
5 changed files with 33 additions and 26 deletions

View File

@ -33,7 +33,7 @@ const {
const fld = await new FolderOption ({ name: 'fld' }) const fld = await new FolderOption ({ name: 'fld' })
.parse (); .parse ();
const data = { str, bool, num, arr, fld }; const data = { /* str, bool, num, arr,*/ fld };
console.log (data); console.log (data);
}) (); }) ();

2
Jenkinsfile vendored
View File

@ -5,7 +5,7 @@ pipeline {
VERSION = VersionNumber([ VERSION = VersionNumber([
versionNumberString: versionNumberString:
'${BUILDS_ALL_TIME}', '${BUILDS_ALL_TIME}',
versionPrefix: '2.0.', versionPrefix: '2.1.',
worstResultForIncrement: 'SUCCESS' worstResultForIncrement: 'SUCCESS'
]) ])
} }

View File

@ -17,10 +17,7 @@ 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;

View File

@ -1,25 +1,34 @@
import { Prompt } from 'enquirer'; /* eslint-disable no-sync */
import { dirname, join, sep, basename } from 'path';
import fs from 'fs-extra';
export class PathPrompt extends Prompt { function read_dir (dir:string, exclude_files:boolean):string[] {
private _index = 0; const contents = fs.readdirSync (dir);
private _value = ''; contents.unshift ('..');
if (exclude_files) {
public constructor (options:Record<string, unknown> = {}) { return contents.filter ((c) => {
super (options); const full_path = join (dir, c);
try {
return fs.statSync (full_path)
.isDirectory ();
} }
catch {
public up (): void { return false;
this._index--;
this.render ();
} }
});
public down (): void {
this._index++;
this.render ();
} }
return contents;
}
public render (): void { interface PathPromptOptions {
this.clear (); starting_dir?: string;
this.write (`${this.state.message}: ${this._value}`); folders_only?: boolean;
}
export class PathPrompt {
private _options: PathPromptOptions;
public constructor (options:PathPromptOptions) {
this._options = options;
} }
} }

View File

@ -15,7 +15,8 @@ export class PathSubSource extends InteractiveSubSource {
this.opt, this.opt,
await new PathPrompt ({ await new PathPrompt ({
message: this.get_message (), message: this.get_message (),
default: this.opt.default default: this.opt.default,
folder_only: this.val.type_validation.option_type === 'folder'
}) })
.run () .run ()
); );