complete remodelling

This commit is contained in:
2020-06-09 21:03:10 +02:00
parent 742d77d29f
commit 021f55833d
17 changed files with 110 additions and 122 deletions

View File

@ -1,7 +1,7 @@
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { BaseOption } from './BaseOption';
export class ArrayOption extends BaseOption {
export class ArrayOption extends BaseOption<(string|number|boolean)[]> {
protected get validation ():TypeValidation {
return new TypeValidation ('array');
}

View File

@ -5,6 +5,7 @@ import { ErrorCallback } from '../ErrorCallback';
import { ArgSource } from '../Sources/ArgSource';
import { ConfigSource } from '../Sources/ConfigSource';
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { InteractiveSource } from '../Sources/InteractiveSource';
export abstract class BaseOption<T> {
protected readonly sources: OptionSource[] = [];
@ -44,8 +45,8 @@ export abstract class BaseOption<T> {
// eslint-disable-next-line no-await-in-loop
await source.parse (this._config, val);
if (!val.assinged)
return this._config.default;
return val.value;
if (!val.filled)
return this._config.default as T;
return val.value as T;
}
}

View File

@ -1,7 +1,7 @@
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { BaseOption } from './BaseOption';
export class BooleanOption extends BaseOption {
export class BooleanOption extends BaseOption<boolean> {
protected get validation ():TypeValidation {
return new TypeValidation ('boolean');
}

View File

@ -1,4 +1,5 @@
import { PathType } from '../TypeValidation/PathType';
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { StringOption } from './StringOption';
export class FileOption extends StringOption {

View File

@ -1,8 +1,9 @@
import { PathType } from '../TypeValidation/PathType';
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { StringOption } from './StringOption';
export class FolderOption extends StringOption {
protected get validation ():TypeValidation {
protected get validation (): TypeValidation {
return new PathType ('folder');
}
}

View File

@ -1,7 +1,7 @@
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { BaseOption } from './BaseOption';
export class NumberOption extends BaseOption {
export class NumberOption extends BaseOption<number> {
protected get validation ():TypeValidation {
return new TypeValidation ('number');
}

View File

@ -1,8 +1,9 @@
import { PathType } from '../TypeValidation/PathType';
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { StringOption } from './StringOption';
export class PathOption extends StringOption {
protected get validation ():TypeValidation {
protected get validation (): TypeValidation {
return new PathType ('path');
}
}

View File

@ -1,12 +1,8 @@
import { TypeValidation } from '../TypeValidation/TypeValidation';
import { Option } from '../Option';
import { StringOptionConfig } from '../SubConfigs';
import { BaseOption } from './BaseOption';
interface StringOptionConfig extends Option {
preset?: string[]
}
export class StringOption extends BaseOption {
export class StringOption extends BaseOption<string> {
protected get validation ():TypeValidation {
return new TypeValidation ('string');
}