From bdfcd8f7da6cfb393bd0bf1b2987fa32e3b7792f Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 19 Jul 2017 20:06:57 +0100 Subject: [PATCH] Get config title --- src/config/mod.rs | 4 +++- src/config/read.rs | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 096d98d..2de499b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -10,7 +10,8 @@ pub mod consts; #[derive(Debug, Serialize, Deserialize, Default)] pub struct Config { input: Vec, - output: HashMap + output: HashMap, + title: String } impl Config { @@ -18,6 +19,7 @@ impl Config { return Config { input: read::get_input_files(&raw), output: read::get_output_files(&raw), + title: read::get_string(&raw, "title"), ..Default::default() }; } diff --git a/src/config/read.rs b/src/config/read.rs index e95fc74..0006d2c 100644 --- a/src/config/read.rs +++ b/src/config/read.rs @@ -23,12 +23,22 @@ pub fn read() -> String { } +fn to_string(data: &Value) -> String { + return data.as_str().unwrap().to_string(); +} + + +pub fn get_string(conf: &Value, key: &str) -> String { + return to_string(conf.get(key).unwrap()); +} + + pub fn get_input_files(conf: &Value) -> Vec { let working_dir = current_dir().unwrap(); let input_values = conf.get("input").unwrap().as_sequence().unwrap().to_vec(); return input_values .into_iter() - .map(|x| working_dir.join(x.as_str().unwrap().to_string())) + .map(|x| working_dir.join(to_string(&x))) .collect(); } @@ -38,7 +48,8 @@ pub fn get_output_files(conf: &Value) -> HashMap { let output_raw = conf.get("output").unwrap().as_mapping().unwrap(); let mut output_map : HashMap = HashMap::new(); for output in output_raw.into_iter() { - output_map.insert(output.0.as_str().unwrap().to_string(), working_dir.join(output.1.as_str().unwrap().to_string())); + output_map.insert(to_string(output.0), working_dir.join(to_string(output.1))); } return output_map; } +