Validate output formats

This commit is contained in:
Jake Howard 2017-07-19 21:22:07 +01:00
parent bdfcd8f7da
commit c62e229dfd
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -16,7 +16,12 @@ fn check_required_keys(config: &Value) -> ValidationResult {
}
fn check_input_files(config: &Value) -> ValidationResult {
match config.get("input").unwrap() {
&Value::Sequence(_) => (),
_ => return Err("Input must be sequence".into())
}
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()));
@ -25,6 +30,24 @@ fn check_input_files(config: &Value) -> ValidationResult {
return Ok(());
}
fn check_output_files(config: &Value) -> ValidationResult {
match config.get("output").unwrap() {
&Value::Mapping(_) => (),
_ => return Err("Output must be mapping".into())
}
let files = read::get_output_files(config);
let output_types = vec!["pdf".into()];
for file_def in files.iter() {
let dir = file_def.1.parent().unwrap();
if !dir.exists() || !dir.is_dir() {
return Err(format!("Cannot find output directory at {}.", dir.display()));
}
if !output_types.contains(file_def.0) {
return Err(format!("Invalid output type {}.", file_def.0));
}
}
return Ok(());
}
pub fn unwrap_group(
config: &Value,
@ -41,5 +64,5 @@ pub fn unwrap_group(
pub fn validate(config: &Value) -> ValidationResult {
return unwrap_group(config, vec![&check_required_keys, &check_input_files]);
return unwrap_group(config, vec![&check_required_keys, &check_input_files, &check_output_files]);
}