From 0307cb7916ca076a9b879f06d9fc1451cb390975 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Mon, 18 May 2020 12:34:44 +0200 Subject: [PATCH] allow preset for string types --- lib/Option.ts | 1 + lib/Sources/InteractiveSource.ts | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/Option.ts b/lib/Option.ts index 8193c47..967dc66 100644 --- a/lib/Option.ts +++ b/lib/Option.ts @@ -17,6 +17,7 @@ interface Option { env?: string; description?: string; message?: string; + preset?: unknown[]; } interface OptionProcess extends Option { diff --git a/lib/Sources/InteractiveSource.ts b/lib/Sources/InteractiveSource.ts index 412e282..eabae0b 100644 --- a/lib/Sources/InteractiveSource.ts +++ b/lib/Sources/InteractiveSource.ts @@ -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,11 +29,21 @@ export class InteractiveSource extends OptionSource { || opt.type === 'path' || opt.type === 'number' ) { - value = await new Input ({ - message: this.get_message (opt), - default: opt.default - }) - .run (); + 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'