fix optiontype

This commit is contained in:
Timo Hocker 2020-05-05 15:15:24 +02:00
parent 54febbd49b
commit d7081f9ae5

View File

@ -14,14 +14,13 @@ import fs from 'fs-extra';
import yargs, { Options } from 'yargs'; import yargs, { Options } from 'yargs';
import { Confirm, Input } from 'enquirer'; import { Confirm, Input } from 'enquirer';
enum OptionType { type OptionType =
string = 'string', 'string'
number = 'number', | 'number'
boolean = 'boolean', | 'boolean'
file = 'file', | 'file'
folder = 'folder', | 'folder'
path = 'path' | 'path';
}
interface Option { interface Option {
name: string; name: string;
@ -63,12 +62,12 @@ export class InteractiveOptions extends Persistent {
} }
private async assign_arg (opt: OptionProcess, value: unknown): Promise<void> { private async assign_arg (opt: OptionProcess, value: unknown): Promise<void> {
if (opt.type === OptionType.string) { if (opt.type === 'string') {
opt.value = String (value); opt.value = String (value);
opt.filled = true; opt.filled = true;
return; return;
} }
if (opt.type === OptionType.number) { if (opt.type === 'number') {
if (![ if (![
'string', 'string',
'number' 'number'
@ -83,7 +82,7 @@ export class InteractiveOptions extends Persistent {
} }
return; return;
} }
if (opt.type === OptionType.boolean) { if (opt.type === 'boolean') {
if (![ if (![
'string', 'string',
'boolean', 'boolean',
@ -104,19 +103,19 @@ export class InteractiveOptions extends Persistent {
return; return;
} }
if ( if (
opt.type === OptionType.path opt.type === 'path'
|| opt.type === OptionType.file || opt.type === 'file'
|| opt.type === OptionType.folder || opt.type === 'folder'
) { ) {
if (typeof value !== 'string' || !await fs.pathExists (value)) if (typeof value !== 'string' || !await fs.pathExists (value))
return; return;
if (opt.type === OptionType.path) { if (opt.type === 'path') {
opt.value = value; opt.value = value;
opt.filled = true; opt.filled = true;
return; return;
} }
const stat = await fs.stat (value); const stat = await fs.stat (value);
if (stat.isDirectory () === (opt.type === OptionType.folder)) { if (stat.isDirectory () === (opt.type === 'folder')) {
opt.value = value; opt.value = value;
opt.filled = true; opt.filled = true;
} }
@ -147,7 +146,7 @@ export class InteractiveOptions extends Persistent {
yargs_config[opt.name] = { yargs_config[opt.name] = {
alias: opt.alias, alias: opt.alias,
default: opt.default, default: opt.default,
type: opt.type === OptionType.boolean ? 'boolean' : 'string', type: opt.type === 'boolean' ? 'boolean' : 'string',
describe: opt.description describe: opt.description
}; };
} }
@ -164,11 +163,11 @@ export class InteractiveOptions extends Persistent {
if (opt.filled) if (opt.filled)
return; return;
if ( if (
opt.type === OptionType.string opt.type === 'string'
|| opt.type === OptionType.file || opt.type === 'file'
|| opt.type === OptionType.folder || opt.type === 'folder'
|| opt.type === OptionType.path || opt.type === 'path'
|| opt.type === OptionType.number || opt.type === 'number'
) { ) {
const value = await new Input ({ const value = await new Input ({
message: opt.message, message: opt.message,
@ -179,7 +178,7 @@ export class InteractiveOptions extends Persistent {
return; return;
} }
if ( if (
opt.type === OptionType.boolean opt.type === 'boolean'
) { ) {
const value = await new Confirm ({ const value = await new Confirm ({
message: opt.message, message: opt.message,