Initial implementation of the Validate function
ci/woodpecker/push/workflow Pipeline failed Details

Added stubs and general flow, some rust stuff to figure out
pull/5/head
Ayrton Chilibeck 2024-01-12 23:58:58 -07:00
parent eaca213f26
commit 8d4b5b3f1c
Signed by: ayrton
GPG Key ID: BAE24A03DCBF160D
1 changed files with 61 additions and 6 deletions

View File

@ -5,11 +5,37 @@ use crate::util;
pub fn validate(verbosity: u8, config: util::config::Config) {
println!("Validating");
let in_suffix = "in"; //TODO make this configurable?
let out_suffix = "out";
// get list of all file names in input/output
let in_files: Vec<PathBuf>;
let out_files: Vec<PathBuf>;
let in_files: Vec<PathBuf> = get_dir_files(config.input_path).expect("Failed to read the input directory contents");
let out_files: Vec<PathBuf> = get_dir_files(config.output_path).expect("Failed to read the output directory contents");
let mismatch: Vec<(PathBuf, PathBuf)>;
let mut invalid_suffix_in: Vec<PathBuf> = vec![];
let mut invalid_suffix_out: Vec<PathBuf> = vec![];
// check if they end in .in or .out respectively
for file in in_files {
if !file.ends_with(in_suffix) {
invalid_suffix_in.push(file);
}
}
for file in out_files {
if !file.ends_with(out_suffix) {
invalid_suffix_out.push(file);
}
}
// print the delinquints
if invalid_suffix_in.len() > 0 {
print_invalid_suffixes(invalid_suffix_in, String::from(in_suffix));
}
if invalid_suffix_out.len() > 0 {
print_invalid_suffixes(invalid_suffix_out, String::from(out_suffix));
}
// make sure each has a match
}
@ -35,15 +61,44 @@ fn get_dir_files(path: PathBuf) -> Result<Vec<PathBuf>, &'static str> {
return Ok(res);
}
fn compare_files(in_files: Vec<PathBuf>, out_files: Vec<PathBuf>) -> Vec<PathBuf> {
let mut res: Vec<PathBuf> = vec![];
fn check_suffix(path: PathBuf, suf: String) -> bool {
return false;
res.append(&mut compare_list(in_files, out_files));
res.append(&mut compare_list(out_files, in_files));
return res;
}
fn check_match(path1: PathBuf, path2: PathBuf, in_suf: String, out_suf: String) -> bool {
return false;
fn compare_list(from: Vec<PathBuf>, against: Vec<PathBuf>) -> Vec<PathBuf> {
let res: Vec<PathBuf> = vec![];
// Compare each input file to each output file
for file in from {
let beg = file.file_stem().unwrap(); // ignore suffix
for out in against {
if beg == out.file_stem().unwrap() {
break;
}
}
res.push(file); // if the file does not have a counterpart, then push to the lost files
}
return res;
}
fn print_invalid_suffixes(files: Vec<PathBuf>, exp: String) {
println!("Invalid suffixes detected 😱:" );
println!("Current => Suggested");
for mut file in files {
let initial = match file.to_str() {
Some(x) => x,
_ => panic!("Failed to load the file"),
};
println!("{} => {}", initial, file.set_extension(exp).to_string());
}
}
#[cfg(test)]
mod tests {