Get config title

This commit is contained in:
Jake Howard 2017-07-19 20:06:57 +01:00
parent 298df33274
commit bdfcd8f7da
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 16 additions and 3 deletions

View file

@ -10,7 +10,8 @@ pub mod consts;
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Config {
input: Vec<PathBuf>,
output: HashMap<String, PathBuf>
output: HashMap<String, PathBuf>,
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()
};
}

View file

@ -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<PathBuf> {
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<String, PathBuf> {
let output_raw = conf.get("output").unwrap().as_mapping().unwrap();
let mut output_map : HashMap<String, PathBuf> = 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;
}