diff --git a/src/config/validate.rs b/src/config/validate.rs index 4d2a1d2..e7027f8 100644 --- a/src/config/validate.rs +++ b/src/config/validate.rs @@ -3,6 +3,8 @@ use std::vec::Vec; pub type ValidationResult = Result<(), String>; +use config::read; + fn check_required_keys(config: &Value) -> ValidationResult { for key in vec!( @@ -11,7 +13,17 @@ fn check_required_keys(config: &Value) -> ValidationResult { "title" ).iter() { if config.get(key).is_none() { - return Err("Missing key".into()); + return Err(format!("Missing required key {}.", key)); + } + } + return Ok(()); +} + +fn check_input_files(config: &Value) -> ValidationResult { + let files = read::get_input_files(config); + for file in files.iter() { + if !file.exists() || !file.is_file() { + return Err(format!("Cannot find input file at {}.", file.as_path().display())); } } return Ok(()); @@ -31,6 +43,7 @@ pub fn unwrap_group(config: &Value, funcs: Vec<&Fn(&Value) -> ValidationResult>) pub fn validate(config: &Value) -> ValidationResult { return unwrap_group(config, vec!( - &check_required_keys + &check_required_keys, + &check_input_files )); }