diff --git a/Cargo.toml b/Cargo.toml index ad49935..7eb41dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oink" -version = "0.2.1" +version = "0.2.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/config.rs b/src/config.rs index 4a15926..5b05e4d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,8 +17,8 @@ use toml::{ use crate::{ error, util }; -pub type Context = BTreeMap; -pub type Table = toml::map::Map; +pub type Context = BTreeMap; +pub type Table = toml::map::Map; /// configuration struct pub struct Config { @@ -59,13 +59,15 @@ impl Config { /// build context from "vars" and "colors" config sections pub fn context(&self, target: &Table) -> Context { let mut output = Context::new(); + let mut def: Vec = Vec::new(); // pull global vars if let Some(Value::Table(vars)) = self.inner.get("vars") { for (key, value) in vars.iter() { let key = key.to_owned(); if let Some(value) = util::convert(value) { - output.insert(key, value); + output.insert(key.clone(), value); + def.push(ContextValue::String(key)); } } } @@ -74,7 +76,9 @@ impl Config { for (key, value) in target.iter() { if key.to_uppercase() == *key { if let Some(value) = util::convert(value) { - output.insert(key.to_owned(), value); + let key = key.to_owned(); + output.insert(key.clone(), value); + def.push(ContextValue::String(key)); } } } @@ -91,10 +95,15 @@ impl Config { for(key, value) in palette.iter() { output.insert(key.to_owned(), value.as_str().unwrap().into()); } - output.insert("palette".to_string(), colors.into()); + let key = "palette".to_string(); + output.insert(key.clone(), colors.into()); + def.push(ContextValue::String(key)); } } + // insert set vars list + output.insert("def".to_string(), def.into()); + output } diff --git a/src/filter.rs b/src/filter.rs new file mode 100644 index 0000000..591beae --- /dev/null +++ b/src/filter.rs @@ -0,0 +1,7 @@ + +use upon::Value; + +pub fn has(list: Vec, key: String) -> bool { + return list.contains(&Value::String(key)); +} + diff --git a/src/main.rs b/src/main.rs index 7659394..5c60335 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use pico_args::Arguments; mod config; mod error; +mod filter; mod operation; mod util; diff --git a/src/operation.rs b/src/operation.rs index 34c7af1..447c854 100644 --- a/src/operation.rs +++ b/src/operation.rs @@ -17,7 +17,10 @@ use termion::{ use toml::{ map::Map, Value }; use upon::Engine; -use crate::config::Config; +use crate::{ + config::Config, + filter +}; static SUCCESS: Fg = Fg(color::Green); static WARNING: Fg = Fg(color::Yellow); @@ -68,7 +71,8 @@ pub fn build(targets: &Vec>, template_dir: String, config: &C let home = var("HOME").unwrap(); println!("running build:"); - let engine = Engine::new(); + let mut engine = Engine::new(); + engine.add_filter("has", filter::has); for target in targets { let context = config.context(target);