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") {
for (key, value) in vars.iter() {
let key = key.to_owned();
match value.clone() {
Value::Boolean(bool) => output.insert(key, bool.into()),
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
};
if let Some(value) = util::convert(value) {
output.insert(key, value);
}
}
}
// pull target values
for (key, value) in target.iter() {
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 };
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)
}
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
}
}