command-parser/src/classes/CommandOption.ts

78 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-07-28 21:06:11 +02:00
import ICommandOption, { Choice, CommandOptionDefinition, DependsOnMode, OptionType, ParseResult } from "../interfaces/CommandOption";
class CommandOption implements ICommandOption {
name: string;
aliases: string[];
options: ICommandOption[];
type: OptionType;
minimum?: number;
maximum?: number;
flag: boolean;
valueOptional: boolean;
defaultValue: boolean | number | string | null;
valueAsAlias: boolean;
choices: Choice[];
dependsOn: string[];
dependsOnMode: DependsOnMode;
required: boolean;
rawValue?: string[];
value?: unknown;
aliased = false;
constructor(def: CommandOptionDefinition|ICommandOption) {
this.name = def.name;
this.aliases = def.aliases || [];
this.options = def.options || [];
this.choices = def.choices || [];
this.type = def.type || OptionType.STRING;
this.flag = def.flag || false;
this.valueOptional = def.valueOptional || false;
this.defaultValue = def.defaultValue ?? null;
this.valueAsAlias = def.valueAsAlias || false;
this.dependsOn = def.dependsOn || [];
this.dependsOnMode = def.dependsOnMode || 'AND';
this.required = def.required || false;
}
clone(rawValue?: string[]): ICommandOption {
const opt = new CommandOption(this);
opt.rawValue = rawValue;
return opt;
}
parse(): ParseResult {
return { error: false, removed: [] };
}
get plural(): boolean {
return this.type.toString().endsWith('S');
}
}
export { CommandOption };
export default CommandOption;