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 { 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<void> {
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,