added new 'def' list to allow checking if a variable exists
This commit is contained in:
parent
cd7dc90657
commit
9b6c3c9422
5 changed files with 29 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "oink"
|
name = "oink"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -17,8 +17,8 @@ use toml::{
|
||||||
|
|
||||||
use crate::{ error, util };
|
use crate::{ error, util };
|
||||||
|
|
||||||
pub type Context = BTreeMap<String, ContextValue>;
|
pub type Context = BTreeMap<String, ContextValue>;
|
||||||
pub type Table = toml::map::Map<String, Value>;
|
pub type Table = toml::map::Map<String, Value>;
|
||||||
|
|
||||||
/// configuration struct
|
/// configuration struct
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -59,13 +59,15 @@ impl Config {
|
||||||
/// build context from "vars" and "colors" config sections
|
/// build context from "vars" and "colors" config sections
|
||||||
pub fn context(&self, target: &Table) -> Context {
|
pub fn context(&self, target: &Table) -> Context {
|
||||||
let mut output = Context::new();
|
let mut output = Context::new();
|
||||||
|
let mut def: Vec<ContextValue> = Vec::new();
|
||||||
|
|
||||||
// pull global vars
|
// pull global vars
|
||||||
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();
|
||||||
if let Some(value) = util::convert(value) {
|
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() {
|
for (key, value) in target.iter() {
|
||||||
if key.to_uppercase() == *key {
|
if key.to_uppercase() == *key {
|
||||||
if let Some(value) = util::convert(value) {
|
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() {
|
for(key, value) in palette.iter() {
|
||||||
output.insert(key.to_owned(), value.as_str().unwrap().into());
|
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
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
src/filter.rs
Normal file
7
src/filter.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
use upon::Value;
|
||||||
|
|
||||||
|
pub fn has(list: Vec<Value>, key: String) -> bool {
|
||||||
|
return list.contains(&Value::String(key));
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use pico_args::Arguments;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod error;
|
mod error;
|
||||||
|
mod filter;
|
||||||
mod operation;
|
mod operation;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,10 @@ use termion::{
|
||||||
use toml::{ map::Map, Value };
|
use toml::{ map::Map, Value };
|
||||||
use upon::Engine;
|
use upon::Engine;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::{
|
||||||
|
config::Config,
|
||||||
|
filter
|
||||||
|
};
|
||||||
|
|
||||||
static SUCCESS: Fg<color::Green> = Fg(color::Green);
|
static SUCCESS: Fg<color::Green> = Fg(color::Green);
|
||||||
static WARNING: Fg<color::Yellow> = Fg(color::Yellow);
|
static WARNING: Fg<color::Yellow> = Fg(color::Yellow);
|
||||||
|
@ -68,7 +71,8 @@ pub fn build(targets: &Vec<Map<String, Value>>, template_dir: String, config: &C
|
||||||
let home = var("HOME").unwrap();
|
let home = var("HOME").unwrap();
|
||||||
println!("running build:");
|
println!("running build:");
|
||||||
|
|
||||||
let engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
engine.add_filter("has", filter::has);
|
||||||
|
|
||||||
for target in targets {
|
for target in targets {
|
||||||
let context = config.context(target);
|
let context = config.context(target);
|
||||||
|
|
Loading…
Reference in a new issue