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:
parent
0288cc38fc
commit
708a019ce2
3 changed files with 26 additions and 14 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -457,6 +457,7 @@ dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"filetime",
|
"filetime",
|
||||||
|
"glob",
|
||||||
"image",
|
"image",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"libdeflater",
|
"libdeflater",
|
||||||
|
|
@ -465,7 +466,6 @@ dependencies = [
|
||||||
"rgb",
|
"rgb",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"wild",
|
|
||||||
"zopfli",
|
"zopfli",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -608,15 +608,6 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wild"
|
|
||||||
version = "2.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "05b116685a6be0c52f5a103334cbff26db643826c7b3735fc0a3ba9871310a74"
|
|
||||||
dependencies = [
|
|
||||||
"glob",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ version = "1.7.0"
|
||||||
optional = true
|
optional = true
|
||||||
version = "4.3.8"
|
version = "4.3.8"
|
||||||
|
|
||||||
[dependencies.wild]
|
[target.'cfg(windows)'.dependencies.glob]
|
||||||
optional = true
|
optional = true
|
||||||
version = "2.1.0"
|
version = "0.3.1"
|
||||||
|
|
||||||
[dependencies.image]
|
[dependencies.image]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
@ -71,7 +71,7 @@ version = "0.24.6"
|
||||||
rustc_version = "0.4.0"
|
rustc_version = "0.4.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
binary = ["clap", "wild", "env_logger"]
|
binary = ["clap", "glob", "env_logger"]
|
||||||
default = ["binary", "filetime", "parallel", "zopfli"]
|
default = ["binary", "filetime", "parallel", "zopfli"]
|
||||||
parallel = ["rayon", "indexmap/rayon", "crossbeam-channel"]
|
parallel = ["rayon", "indexmap/rayon", "crossbeam-channel"]
|
||||||
freestanding = ["libdeflater/freestanding"]
|
freestanding = ["libdeflater/freestanding"]
|
||||||
|
|
|
||||||
23
src/main.rs
23
src/main.rs
|
|
@ -296,7 +296,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_from(wild::args());
|
.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,
|
||||||
|
|
@ -307,6 +307,14 @@ Heuristic filter selection strategies:
|
||||||
};
|
};
|
||||||
|
|
||||||
let files = collect_files(
|
let files = collect_files(
|
||||||
|
#[cfg(windows)]
|
||||||
|
matches
|
||||||
|
.get_many::<PathBuf>("files")
|
||||||
|
.unwrap()
|
||||||
|
.cloned()
|
||||||
|
.flat_map(apply_glob_pattern)
|
||||||
|
.collect(),
|
||||||
|
#[cfg(not(windows))]
|
||||||
matches
|
matches
|
||||||
.get_many::<PathBuf>("files")
|
.get_many::<PathBuf>("files")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -384,6 +392,19 @@ fn collect_files(
|
||||||
in_out_pairs
|
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(
|
fn parse_opts_into_struct(
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
) -> Result<(OutFile, Option<PathBuf>, Options), String> {
|
) -> Result<(OutFile, Option<PathBuf>, Options), String> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue