variables in target sections now behave as expected

This commit is contained in:
Valerie Wolfe 2024-07-08 14:12:56 -04:00
parent f873367a51
commit cdc0c02e37
2 changed files with 17 additions and 8 deletions

View file

@ -64,20 +64,18 @@ impl Config {
if let Some(Value::Table(vars)) = self.inner.get("vars") { if let Some(Value::Table(vars)) = self.inner.get("vars") {
for (key, value) in vars.iter() { for (key, value) in vars.iter() {
let key = key.to_owned(); let key = key.to_owned();
match value.clone() { if let Some(value) = util::convert(value) {
Value::Boolean(bool) => output.insert(key, bool.into()), output.insert(key, value);
Value::Float(float) => output.insert(key, float.into()), }
Value::Integer(int) => output.insert(key, int.into()),
Value::String(string) => output.insert(key, string.into()),
_ => None
};
} }
} }
// pull target values // pull target values
for (key, value) in target.iter() { for (key, value) in target.iter() {
if key.to_uppercase() == *key { if key.to_uppercase() == *key {
output.insert(key.to_owned(), value.as_str().unwrap().into()); if let Some(value) = util::convert(value) {
output.insert(key.to_owned(), value);
}
} }
} }

View file

@ -1,4 +1,5 @@
use upon::Value as ContextValue;
use toml::{ value::Array, Value }; use toml::{ value::Array, Value };
pub fn matches(array: Array, to_match: String) -> Option<Value> { pub fn matches(array: Array, to_match: String) -> Option<Value> {
@ -12,3 +13,13 @@ pub fn matches(array: Array, to_match: String) -> Option<Value> {
}).map(|value| value.to_owned()).nth(0) }).map(|value| value.to_owned()).nth(0)
} }
pub fn convert(value: &Value) -> Option<ContextValue> {
match value.clone() {
Value::Boolean(bool) => Some(bool.into()),
Value::Float(float) => Some(float.into()),
Value::Integer(int) => Some(int.into()),
Value::String(string) => Some(string.into()),
_ => None
}
}