Validate output formats
This commit is contained in:
parent
bdfcd8f7da
commit
c62e229dfd
1 changed files with 24 additions and 1 deletions
|
@ -16,7 +16,12 @@ fn check_required_keys(config: &Value) -> ValidationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_input_files(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);
|
let files = read::get_input_files(config);
|
||||||
|
|
||||||
for file in files.iter() {
|
for file in files.iter() {
|
||||||
if !file.exists() || !file.is_file() {
|
if !file.exists() || !file.is_file() {
|
||||||
return Err(format!("Cannot find input file at {}.", file.as_path().display()));
|
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(());
|
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(
|
pub fn unwrap_group(
|
||||||
config: &Value,
|
config: &Value,
|
||||||
|
@ -41,5 +64,5 @@ pub fn unwrap_group(
|
||||||
|
|
||||||
|
|
||||||
pub fn validate(config: &Value) -> ValidationResult {
|
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]);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue