Skip to content

Commit 708a019

Browse files
authored
Added support for glob patterns in quotes (oxipng#536)
Added support for glob patterns in windows paths with spaces that surrounded with quotes closes oxipng#373
1 parent 0288cc3 commit 708a019

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ version = "1.7.0"
5757
optional = true
5858
version = "4.3.8"
5959

60-
[dependencies.wild]
60+
[target.'cfg(windows)'.dependencies.glob]
6161
optional = true
62-
version = "2.1.0"
62+
version = "0.3.1"
6363

6464
[dependencies.image]
6565
optional = true
@@ -71,7 +71,7 @@ version = "0.24.6"
7171
rustc_version = "0.4.0"
7272

7373
[features]
74-
binary = ["clap", "wild", "env_logger"]
74+
binary = ["clap", "glob", "env_logger"]
7575
default = ["binary", "filetime", "parallel", "zopfli"]
7676
parallel = ["rayon", "indexmap/rayon", "crossbeam-channel"]
7777
freestanding = ["libdeflater/freestanding"]

src/main.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Heuristic filter selection strategies:
296296
8 => BigEnt Highest Shannon entropy of bigrams
297297
9 => Brute Smallest compressed size (slow)",
298298
)
299-
.get_matches_from(wild::args());
299+
.get_matches_from(std::env::args());
300300

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

309309
let files = collect_files(
310+
#[cfg(windows)]
311+
matches
312+
.get_many::<PathBuf>("files")
313+
.unwrap()
314+
.cloned()
315+
.flat_map(apply_glob_pattern)
316+
.collect(),
317+
#[cfg(not(windows))]
310318
matches
311319
.get_many::<PathBuf>("files")
312320
.unwrap()
@@ -384,6 +392,19 @@ fn collect_files(
384392
in_out_pairs
385393
}
386394

395+
#[cfg(windows)]
396+
fn apply_glob_pattern(path: PathBuf) -> Vec<PathBuf> {
397+
let matches = path
398+
.to_str()
399+
.and_then(|pattern| glob::glob(pattern).ok())
400+
.map(|paths| paths.flatten().collect::<Vec<_>>());
401+
402+
match matches {
403+
Some(paths) if !paths.is_empty() => paths,
404+
_ => vec![path],
405+
}
406+
}
407+
387408
fn parse_opts_into_struct(
388409
matches: &ArgMatches,
389410
) -> Result<(OutFile, Option<PathBuf>, Options), String> {

0 commit comments

Comments
 (0)