57 lines
1.1 KiB
TypeScript
57 lines
1.1 KiB
TypeScript
import { Persistent } from '@scode/modelling';
|
|
|
|
enum OptionType {
|
|
string = 'string',
|
|
number = 'number',
|
|
boolean = 'boolean'
|
|
}
|
|
|
|
interface Option {
|
|
name: string;
|
|
type: OptionType;
|
|
required?: boolean;
|
|
default: unknown;
|
|
alias: string;
|
|
env: string;
|
|
}
|
|
|
|
interface OptionProcess extends Option {
|
|
filled: boolean;
|
|
}
|
|
|
|
export class InteractiveOptions extends Persistent {
|
|
protected options: Array<OptionProcess>;
|
|
|
|
public constructor (options: Array<Option>) {
|
|
super ();
|
|
this.options = options
|
|
.map ((v) => ({ filled: false, ...v } as OptionProcess));
|
|
for (const option of this.options) {
|
|
if (typeof option.default !== option.type) {
|
|
throw new Error (
|
|
`default does not match option type on ${option.name}`
|
|
);
|
|
}
|
|
this.properties[option.name] = option.type;
|
|
}
|
|
}
|
|
|
|
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> {
|
|
|
|
}
|
|
}
|