Updated apply_glob_pattern function

This commit is contained in:
SalOne22 2023-07-13 11:29:08 +02:00
parent e87920b736
commit 8124a6d2d7

View file

@ -295,7 +295,7 @@ Heuristic filter selection strategies:
8 => BigEnt Highest Shannon entropy of bigrams 8 => BigEnt Highest Shannon entropy of bigrams
9 => Brute Smallest compressed size (slow)", 9 => Brute Smallest compressed size (slow)",
) )
.get_matches(); .get_matches_from(std::env::args());
let (out_file, out_dir, opts) = match parse_opts_into_struct(&matches) { let (out_file, out_dir, opts) = match parse_opts_into_struct(&matches) {
Ok(x) => x, Ok(x) => x,
@ -310,12 +310,8 @@ Heuristic filter selection strategies:
matches matches
.get_many::<PathBuf>("files") .get_many::<PathBuf>("files")
.unwrap() .unwrap()
.flat_map(|path| { .cloned()
apply_glob_pattern(path).unwrap_or_else(|e| { .flat_map(apply_glob_pattern)
warn!("{path:?}: {e}");
vec![]
})
})
.collect(), .collect(),
#[cfg(not(windows))] #[cfg(not(windows))]
matches matches
@ -396,13 +392,16 @@ fn collect_files(
} }
#[cfg(windows)] #[cfg(windows)]
fn apply_glob_pattern(path: &std::path::Path) -> Result<Vec<PathBuf>, String> { fn apply_glob_pattern(path: PathBuf) -> Vec<PathBuf> {
let input_path = path.to_str().ok_or("Failed to read path.".to_string())?; let matches = path
.to_str()
.and_then(|pattern| glob::glob(pattern).ok())
.map(|paths| paths.flatten().collect::<Vec<_>>());
Ok(glob::glob(input_path) match matches {
.map_err(|e| e.to_string())? Some(paths) if !paths.is_empty() => paths,
.flatten() _ => vec![path],
.collect()) }
} }
fn parse_opts_into_struct( fn parse_opts_into_struct(