mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
quick impl one-of
This commit is contained in:
parent
0a6a5e6206
commit
3f674e522d
2 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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 };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue