default parsers for some built-in types

This commit is contained in:
Erik 2023-02-12 14:51:45 +02:00
parent 19fef0ed6c
commit bdd73dd6a9
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -115,6 +115,32 @@ class CommandOption implements ICommandOption {
return { value: this.rawValue.join(' '), removed: this.rawValue };
}
protected INTEGER() {
if (!this.rawValue) return { error: true };
const integer = parseInt(this.rawValue[0]);
if(isNaN(integer)) return { error: true };
if (this.minimum !== undefined && integer < this.minimum) return { error: true };
if (this.maximum !== undefined && integer > this.maximum) return { error: true };
return { value: integer, removed: [this.rawValue[0]] };
}
protected FLOAT() {
if (!this.rawValue) return { error: true };
const float = parseFloat(this.rawValue[0]);
if(isNaN(float)) return { error: true };
if (this.minimum !== undefined && float < this.minimum) return { error: true };
if (this.maximum !== undefined && float > this.maximum) return { error: true };
return { value: (float), removed: [this.rawValue[0]] };
}
protected BOOLEAN() {
if (!this.rawValue) return { error: true };
const boolean = this.resolver?.resolveBoolean(this.rawValue[0]) || null;
if (boolean === null && this.valueOptional) return { value: this.defaultValue, removed: [] };
else if(boolean === null) return { error: true };
return { value: boolean, removed: [this.rawValue[0]] };
}
}
export { CommandOption };