From d7081f9ae5d40e2f12896996f45419f9c9757dce Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 5 May 2020 15:15:24 +0200 Subject: [PATCH] fix optiontype --- lib/InteractiveOptions.ts | 45 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/InteractiveOptions.ts b/lib/InteractiveOptions.ts index bfa918c..41e343d 100644 --- a/lib/InteractiveOptions.ts +++ b/lib/InteractiveOptions.ts @@ -14,14 +14,13 @@ import fs from 'fs-extra'; import yargs, { Options } from 'yargs'; import { Confirm, Input } from 'enquirer'; -enum OptionType { - string = 'string', - number = 'number', - boolean = 'boolean', - file = 'file', - folder = 'folder', - path = 'path' -} +type OptionType = + 'string' + | 'number' + | 'boolean' + | 'file' + | 'folder' + | 'path'; interface Option { name: string; @@ -63,12 +62,12 @@ export class InteractiveOptions extends Persistent { } private async assign_arg (opt: OptionProcess, value: unknown): Promise { - if (opt.type === OptionType.string) { + if (opt.type === 'string') { opt.value = String (value); opt.filled = true; return; } - if (opt.type === OptionType.number) { + if (opt.type === 'number') { if (![ 'string', 'number' @@ -83,7 +82,7 @@ export class InteractiveOptions extends Persistent { } return; } - if (opt.type === OptionType.boolean) { + if (opt.type === 'boolean') { if (![ 'string', 'boolean', @@ -104,19 +103,19 @@ export class InteractiveOptions extends Persistent { return; } if ( - opt.type === OptionType.path - || opt.type === OptionType.file - || opt.type === OptionType.folder + opt.type === 'path' + || opt.type === 'file' + || opt.type === 'folder' ) { if (typeof value !== 'string' || !await fs.pathExists (value)) return; - if (opt.type === OptionType.path) { + if (opt.type === 'path') { opt.value = value; opt.filled = true; return; } const stat = await fs.stat (value); - if (stat.isDirectory () === (opt.type === OptionType.folder)) { + if (stat.isDirectory () === (opt.type === 'folder')) { opt.value = value; opt.filled = true; } @@ -147,7 +146,7 @@ export class InteractiveOptions extends Persistent { yargs_config[opt.name] = { alias: opt.alias, default: opt.default, - type: opt.type === OptionType.boolean ? 'boolean' : 'string', + type: opt.type === 'boolean' ? 'boolean' : 'string', describe: opt.description }; } @@ -164,11 +163,11 @@ export class InteractiveOptions extends Persistent { if (opt.filled) return; if ( - opt.type === OptionType.string - || opt.type === OptionType.file - || opt.type === OptionType.folder - || opt.type === OptionType.path - || opt.type === OptionType.number + opt.type === 'string' + || opt.type === 'file' + || opt.type === 'folder' + || opt.type === 'path' + || opt.type === 'number' ) { const value = await new Input ({ message: opt.message, @@ -179,7 +178,7 @@ export class InteractiveOptions extends Persistent { return; } if ( - opt.type === OptionType.boolean + opt.type === 'boolean' ) { const value = await new Confirm ({ message: opt.message,