29 lines
607 B
TypeScript
29 lines
607 B
TypeScript
import { Persistent } from '@scode/modelling';
|
|
|
|
enum OptionType {
|
|
string = 'string',
|
|
number = 'number',
|
|
boolean = 'boolean'
|
|
}
|
|
|
|
interface Option {
|
|
name: string;
|
|
type: OptionType;
|
|
required?: boolean;
|
|
default: unknown;
|
|
}
|
|
|
|
export class InteractiveOptions extends Persistent {
|
|
public constructor (options: Array<Option>) {
|
|
super ();
|
|
for (const option of 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;
|
|
}
|
|
}
|
|
}
|