Skip to content

Commit

Permalink
Added support for glob patterns in quotes (#536)
Browse files Browse the repository at this point in the history
Added support for glob patterns in windows paths with spaces that
surrounded with quotes

closes #373
  • Loading branch information
SalOne22 authored Jul 31, 2023
1 parent 0288cc3 commit 708a019
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ version = "1.7.0"
optional = true
version = "4.3.8"

[dependencies.wild]
[target.'cfg(windows)'.dependencies.glob]
optional = true
version = "2.1.0"
version = "0.3.1"

[dependencies.image]
optional = true
Expand All @@ -71,7 +71,7 @@ version = "0.24.6"
rustc_version = "0.4.0"

[features]
binary = ["clap", "wild", "env_logger"]
binary = ["clap", "glob", "env_logger"]
default = ["binary", "filetime", "parallel", "zopfli"]
parallel = ["rayon", "indexmap/rayon", "crossbeam-channel"]
freestanding = ["libdeflater/freestanding"]
Expand Down
23 changes: 22 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,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_from(std::env::args());

let (out_file, out_dir, opts) = match parse_opts_into_struct(&matches) {
Ok(x) => x,
Expand All @@ -307,6 +307,14 @@ Heuristic filter selection strategies:
};

let files = collect_files(
#[cfg(windows)]
matches
.get_many::<PathBuf>("files")
.unwrap()
.cloned()
.flat_map(apply_glob_pattern)
.collect(),
#[cfg(not(windows))]
matches
.get_many::<PathBuf>("files")
.unwrap()
Expand Down Expand Up @@ -384,6 +392,19 @@ fn collect_files(
in_out_pairs
}

#[cfg(windows)]
fn apply_glob_pattern(path: PathBuf) -> Vec<PathBuf> {
let matches = path
.to_str()
.and_then(|pattern| glob::glob(pattern).ok())
.map(|paths| paths.flatten().collect::<Vec<_>>());

match matches {
Some(paths) if !paths.is_empty() => paths,
_ => vec![path],
}
}

fn parse_opts_into_struct(
matches: &ArgMatches,
) -> Result<(OutFile, Option<PathBuf>, Options), String> {
Expand Down

0 comments on commit 708a019

Please sign in to comment.