diff --git a/Cargo.lock b/Cargo.lock index aa4dc97c..d94955d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,6 +471,7 @@ dependencies = [ "clap", "crossbeam-channel", "filetime", + "glob", "image", "indexmap", "libdeflater", diff --git a/Cargo.toml b/Cargo.toml index 20f25ffc..9b64fcec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,10 @@ version = "4.3.8" optional = true version = "2.1.0" +[dependencies.glob] +optional = true +version = "0.3.1" + [dependencies.image] optional = true default-features = false @@ -66,7 +70,7 @@ version = "0.24.6" rustc_version = "0.4.0" [features] -binary = ["clap", "wild", "stderrlog"] +binary = ["clap", "wild", "glob", "stderrlog"] default = ["binary", "filetime", "parallel", "zopfli"] parallel = ["rayon", "indexmap/rayon", "crossbeam-channel"] freestanding = ["libdeflater/freestanding"] diff --git a/src/main.rs b/src/main.rs index 6b536fc0..2ae6ff57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -295,7 +295,7 @@ Heuristic filter selection strategies: 8 => BigEnt Highest Shannon entropy of bigrams 9 => Brute Smallest compressed size (slow)", ) - .get_matches_from(wild::args()); + .get_matches(); let (out_file, out_dir, opts) = match parse_opts_into_struct(&matches) { Ok(x) => x, @@ -306,6 +306,14 @@ Heuristic filter selection strategies: }; let files = collect_files( + #[cfg(windows)] + matches + .get_many::("files") + .unwrap() + .cloned() + .flat_map(apply_glob_pattern) + .collect(), + #[cfg(not(windows))] matches .get_many::("files") .unwrap() @@ -383,6 +391,20 @@ fn collect_files( in_out_pairs } +#[cfg(target_os = "windows")] +fn apply_glob_pattern(path: PathBuf) -> Vec { + let mut paths = vec![]; + let input_path = path.to_str().unwrap(); + glob::glob(input_path) + .expect("Failed to read glob pattern") + .for_each(|path| { + let path = path.unwrap(); + paths.push(path) + }); + + paths +} + fn parse_opts_into_struct( matches: &ArgMatches, ) -> Result<(OutFile, Option, Options), String> {