mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 21:44:48 +02:00
Really don't get it
This commit is contained in:
@@ -16,6 +16,7 @@ module.exports = class ArgumentUnionType extends ArgumentType {
|
|||||||
async validate(val, msg, arg) {
|
async validate(val, msg, arg) {
|
||||||
let results = this.types.map(type => !type.isEmpty(val, msg, arg) && type.validate(val, msg, arg));
|
let results = this.types.map(type => !type.isEmpty(val, msg, arg) && type.validate(val, msg, arg));
|
||||||
results = await Promise.all(results);
|
results = await Promise.all(results);
|
||||||
|
console.log(results);
|
||||||
if (results.some(valid => valid && typeof valid !== 'string')) return true;
|
if (results.some(valid => valid && typeof valid !== 'string')) return true;
|
||||||
const errors = results.filter(valid => typeof valid === 'string');
|
const errors = results.filter(valid => typeof valid === 'string');
|
||||||
if (errors.length > 0) return errors.join('\n');
|
if (errors.length > 0) return errors.join('\n');
|
||||||
@@ -25,9 +26,9 @@ module.exports = class ArgumentUnionType extends ArgumentType {
|
|||||||
async parse(val, msg, arg) {
|
async parse(val, msg, arg) {
|
||||||
let results = this.types.map(type => !type.isEmpty(val, msg, arg) && type.validate(val, msg, arg));
|
let results = this.types.map(type => !type.isEmpty(val, msg, arg) && type.validate(val, msg, arg));
|
||||||
results = await Promise.all(results);
|
results = await Promise.all(results);
|
||||||
|
console.log(results);
|
||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
if (results[i] && typeof results[i] !== 'string') return this.types[i].parse(val, msg, arg);
|
if (results[i] && typeof results[i] !== 'string') return this.types[i].parse(val, msg, arg);
|
||||||
console.log(results[i], typeof results[i]);
|
|
||||||
}
|
}
|
||||||
throw new Error(`Couldn't parse value "${val}" with union type ${this.id}.`);
|
throw new Error(`Couldn't parse value "${val}" with union type ${this.id}.`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user