starting to split options by type
This commit is contained in:
0
lib/Options/ArrayOption.ts
Normal file
0
lib/Options/ArrayOption.ts
Normal file
45
lib/Options/BaseOption.ts
Normal file
45
lib/Options/BaseOption.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { OptionSource } from '../Sources/OptionSource';
|
||||
import { Option } from '../Option';
|
||||
import { EnvSource } from '../Sources/EnvSource';
|
||||
import { ErrorCallback } from '../ErrorCallback';
|
||||
import { ArgSource } from '../Sources/ArgSource';
|
||||
import { ConfigSource } from '../Sources/ConfigSource';
|
||||
import { TypeValidation } from '../TypeValidation/TypeValidation';
|
||||
|
||||
export abstract class BaseOption<T> {
|
||||
protected readonly sources: OptionSource[] = [];
|
||||
private _config: Option;
|
||||
|
||||
public constructor (
|
||||
config: Option,
|
||||
error_callback?: ErrorCallback,
|
||||
exit_on_interrupt = true
|
||||
) {
|
||||
this._config = config;
|
||||
|
||||
const sources = config.sources || {};
|
||||
if (typeof sources.configs !== 'undefined')
|
||||
this.sources.push (new ConfigSource (sources.configs, error_callback));
|
||||
|
||||
if (sources.env !== false)
|
||||
this.sources.push (new EnvSource (error_callback));
|
||||
|
||||
if (sources.console !== false)
|
||||
this.sources.push (new ArgSource (error_callback));
|
||||
|
||||
if (sources.interactive !== false) {
|
||||
this.sources.push (new InteractiveSource (
|
||||
exit_on_interrupt,
|
||||
error_callback
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract get validation(): TypeValidation;
|
||||
|
||||
public async parse(): Promise<T> {
|
||||
for (let source of this.sources) {
|
||||
source.parse(this._config);
|
||||
}
|
||||
};
|
||||
}
|
0
lib/Options/BooleanOption.ts
Normal file
0
lib/Options/BooleanOption.ts
Normal file
0
lib/Options/FileOption.ts
Normal file
0
lib/Options/FileOption.ts
Normal file
0
lib/Options/FolderOption.ts
Normal file
0
lib/Options/FolderOption.ts
Normal file
0
lib/Options/NumberOption.ts
Normal file
0
lib/Options/NumberOption.ts
Normal file
0
lib/Options/PathOption.ts
Normal file
0
lib/Options/PathOption.ts
Normal file
14
lib/Options/StringOption.ts
Normal file
14
lib/Options/StringOption.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Option } from '../Option';
|
||||
import { BaseOption } from './BaseOption';
|
||||
|
||||
export class StringOption extends BaseOption<string> {
|
||||
private _config: Option;
|
||||
|
||||
public constructor (config: Option) {
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
public async parse (): Promise<string> {
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user