Added support for glob patterns in quotes (#536)

Added support for glob patterns in windows paths with spaces that
surrounded with quotes

closes #373
This commit is contained in:
Vladyslav Vladinov 2023-07-31 17:35:00 +02:00 committed by GitHub
parent 0288cc38fc
commit 708a019ce2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 14 deletions

11
Cargo.lock generated
View file

@ -457,6 +457,7 @@ dependencies = [
"crossbeam-channel",
"env_logger",
"filetime",
"glob",
"image",
"indexmap",
"libdeflater",
@ -465,7 +466,6 @@ dependencies = [
"rgb",
"rustc-hash",
"rustc_version",
"wild",
"zopfli",
]
@ -608,15 +608,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "wild"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b116685a6be0c52f5a103334cbff26db643826c7b3735fc0a3ba9871310a74"
dependencies = [
"glob",
]
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -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
@ -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"]

View file

@ -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,
@ -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()
@ -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> {