quick impl one-of

This commit is contained in:
altalk23 2024-06-20 14:48:19 +03:00
parent 0a6a5e6206
commit 3f674e522d
2 changed files with 21 additions and 0 deletions

View file

@ -101,6 +101,11 @@ namespace geode {
*/
std::optional<std::string> filter;
/**
* A list of options the user can choose from
*/
std::optional<std::vector<std::string>> options;
static Result<StringSetting> parse(JsonMaybeObject& obj);
};

View file

@ -75,6 +75,7 @@ Result<StringSetting> StringSetting::parse(JsonMaybeObject& obj) {
parseCommon(sett, obj);
obj.has("match").into(sett.match);
obj.has("filter").into(sett.filter);
obj.has("one-of").into(sett.options);
return Ok(sett);
}
@ -376,6 +377,21 @@ IMPL_TO_VALID(String) {
};
}
}
else if (m_definition.options) {
if (std::find(
m_definition.options.value().begin(),
m_definition.options.value().end(),
value
) == m_definition.options.value().end()) {
return {
m_definition.defaultValue,
fmt::format(
"Value must be one of {}",
fmt::join(m_definition.options.value(), ", ")
)
};
}
}
return { value, std::nullopt };
}