console-app/lib/InteractiveOptions.ts

57 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-05-05 11:56:36 +02:00
import { Persistent } from '@scode/modelling';
enum OptionType {
string = 'string',
number = 'number',
boolean = 'boolean'
}
interface Option {
name: string;
type: OptionType;
required?: boolean;
default: unknown;
2020-05-05 12:17:48 +02:00
alias: string;
env: string;
}
interface OptionProcess extends Option {
filled: boolean;
2020-05-05 11:56:36 +02:00
}
export class InteractiveOptions extends Persistent {
2020-05-05 12:17:48 +02:00
protected options: Array<OptionProcess>;
2020-05-05 11:56:36 +02:00
public constructor (options: Array<Option>) {
super ();
2020-05-05 12:17:48 +02:00
this.options = options
.map ((v) => ({ filled: false, ...v } as OptionProcess));
for (const option of this.options) {
2020-05-05 11:56:36 +02:00
if (typeof option.default !== option.type) {
throw new Error (
`default does not match option type on ${option.name}`
);
}
this.properties[option.name] = option.type;
}
}
2020-05-05 12:17:48 +02:00
public async parse (): Promise<void> {
this.get_env_options ();
this.get_args_options ();
await this.get_interactive_options ();
}
private get_env_options (): void {
}
private get_args_options (): void {
}
private async get_interactive_options (): Promise<void> {
}
2020-05-05 11:56:36 +02:00
}