default parsers for some built-in types
This commit is contained in:
parent
19fef0ed6c
commit
bdd73dd6a9
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user