diff --git a/Cargo.lock b/Cargo.lock index 50b91a7..f969d88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -420,7 +420,7 @@ dependencies = [ [[package]] name = "tpl" -version = "0.1.1" +version = "0.2.0" dependencies = [ "gtmpl", "gtmpl_value", diff --git a/Cargo.toml b/Cargo.toml index 0b695e8..ace3e55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tpl" -version = "0.1.1" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index e083d4b..ec1e814 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,11 @@ impl TemplateObject { format!("Error parsing set option {}={}", key, value) })?; for seg in key.rsplit(".").map(str::trim) { + let mut seg = seg.to_string(); + while seg.ends_with("[]") { + seg = seg.chars().take(seg.len() - 2).collect(); + stage = vec![stage].into(); + } let mut map = HashMap::new(); map.insert(seg.to_string(), stage); stage = map.into(); @@ -72,12 +77,19 @@ impl Merge for HashMap { } } +impl Merge for Vec { + fn merge(&mut self, other: Self) { + self.extend(other) + } +} + impl Merge for Value { fn merge(&mut self, other: Self) { use Value::*; match (self, other) { (Object(a), Object(b)) => a.merge(b), (Map(a), Map(b)) => a.merge(b), + (Array(a), Array(b)) => a.merge(b), (_, Nil) => (), (a, b) => *a = b, }