diff --git a/src/main.rs b/src/main.rs index 39e2fc8..dd729b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -128,18 +128,18 @@ struct PatternMatcher { } impl PatternMatcher { - fn from_config_file(config_file: &Path) -> Result { + fn from_config_file(config_file: &Path) -> PatternMatcher { let config = PatternsConfig::from_config_file(config_file); let patterns_to_remove = create_mixed_regex_list(config.remove.iter().map(AsRef::as_ref).collect()).unwrap(); let patterns_to_rename = - create_regex_list(config.cleanup.iter().map(AsRef::as_ref).collect()).unwrap(); - let patterns_to_remove_with_hash = create_patterns_with_hash(config.remove_hash).unwrap(); - Ok(PatternMatcher { + create_regex_list(config.cleanup.iter().map(AsRef::as_ref).collect()); + let patterns_to_remove_with_hash = create_patterns_with_hash(config.remove_hash); + PatternMatcher { patterns_to_remove, patterns_to_remove_with_hash, patterns_to_rename, - }) + } } fn match_remove_pattern(&self, test_file: &str) -> (bool, Option) { @@ -196,8 +196,8 @@ fn create_mixed_regex_list(patterns: Vec<&str>) -> Result, Box>> {:#?}", pattern); - if pattern.starts_with('/') { - Regex::new(&pattern[1..]).unwrap() + if let Some(stripped) = pattern.strip_prefix('/') { + Regex::new(stripped).unwrap() } else { Regex::new(fnmatch_regex::glob_to_regex_string(pattern).as_str()).unwrap() } @@ -209,7 +209,7 @@ fn create_mixed_regex_list(patterns: Vec<&str>) -> Result, Box) -> Result, Box> { +fn create_regex_list(patterns: Vec<&str>) -> Vec { let regex_list: Vec = patterns .iter() .map(|pattern| { @@ -217,13 +217,11 @@ fn create_regex_list(patterns: Vec<&str>) -> Result, Box>, -) -> Result)>, Box> { - let patterns_to_remove_with_hash = patterns +fn create_patterns_with_hash(patterns: HashMap>) -> Vec<(Regex, Vec)> { + patterns .into_iter() .map(|(key, value)| { // println!("hash --> {}", key); @@ -232,8 +230,7 @@ fn create_patterns_with_hash( value, ) }) - .collect(); - Ok(patterns_to_remove_with_hash) + .collect() } fn get_guess_paths(target_path: &Path) -> Vec { @@ -267,7 +264,7 @@ fn guess_path(test_file: &str, mut guess_paths: Vec) -> Option return Some(file_path); } } - None + None // return None; if found nothing in paths } fn dedup_vec(v: &Vec) -> Vec { @@ -389,7 +386,7 @@ fn main() -> std::io::Result<()> { println!("{:#?}", app_options); } - let pattern_matcher = PatternMatcher::from_config_file(&app_options.config_file).unwrap(); + let pattern_matcher = PatternMatcher::from_config_file(&app_options.config_file); if app_options.is_debug_mode() { println!("{:#?}", pattern_matcher); }