allow preset for string types

This commit is contained in:
Timo Hocker 2020-05-18 12:34:44 +02:00
parent cee181caeb
commit 0307cb7916
2 changed files with 17 additions and 6 deletions

View File

@ -17,6 +17,7 @@ interface Option {
env?: string;
description?: string;
message?: string;
preset?: unknown[];
}
interface OptionProcess extends Option {

View File

@ -7,7 +7,7 @@
/* eslint-disable no-console */
/* eslint-disable no-process-exit */
import { Confirm, Input, List } from 'enquirer';
import { Confirm, Input, List, AutoComplete } from 'enquirer';
import { OptionProcess, Option } from '../Option';
import { OptionSource } from './OptionSource';
@ -29,12 +29,22 @@ export class InteractiveSource extends OptionSource {
|| opt.type === 'path'
|| opt.type === 'number'
) {
if (typeof opt.preset === 'undefined') {
value = await new Input ({
message: this.get_message (opt),
default: opt.default
})
.run ();
}
else {
value = await new AutoComplete ({
message: this.get_message (opt),
default: opt.default,
choices: opt.preset
})
.run ();
}
}
if (
opt.type === 'boolean'
) {