Skip to content

Commit 5b3eb23

Browse files
committed
Add glob crate to read library path instead of relying on the OS
As explained in amethyst#32 relying on the OS to expand globs caused the CLI to fail in Windows. By using glob it is currently working on Windwos.
1 parent d4336c9 commit 5b3eb23

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

sheep_cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ clap = "2.32"
2323
ron = "0.4"
2424
oxipng = "2.2"
2525
png = "0.15"
26+
glob = "0.3"
2627

2728
[[bin]]
2829
name = "sheep"

sheep_cli/src/main.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
extern crate clap;
2+
extern crate glob;
23
extern crate image;
34
extern crate ron;
45
extern crate serde;
56
extern crate sheep;
67

78
use clap::{App, AppSettings, Arg, SubCommand};
9+
use glob::glob;
810
use serde::Serialize;
911
use sheep::{
1012
AmethystFormat, AmethystNamedFormat, InputSprite, MaxrectsOptions, MaxrectsPacker,
1113
SimplePacker, SpriteSheet,
1214
};
15+
use std::path::{PathBuf, Path};
1316
use std::str::FromStr;
1417
use std::{fs::File, io::prelude::*};
1518

@@ -93,7 +96,16 @@ fn main() {
9396
("pack", Some(matches)) => {
9497
let input = matches
9598
.values_of("INPUT")
96-
.map(|values| values.map(|it| String::from(it)).collect::<Vec<String>>())
99+
.map(|values| {
100+
values
101+
.flat_map(|path_pattern| {
102+
glob(path_pattern)
103+
.expect("Invalid path pattern")
104+
.map(|path| path.expect("Invalid path"))
105+
.collect::<Vec<PathBuf>>()
106+
})
107+
.collect::<Vec<PathBuf>>()
108+
})
97109
.unwrap_or(Vec::new());
98110

99111
let out = matches
@@ -171,20 +183,22 @@ fn main() {
171183
}
172184
}
173185

174-
fn get_filenames(input: &[String]) -> Vec<String> {
186+
fn get_filenames(input: &[PathBuf]) -> Vec<String> {
175187
input
176188
.iter()
177189
.map(|path| {
178-
std::path::PathBuf::from(&path)
179-
.file_stem()
190+
path.file_stem()
180191
.and_then(|name| name.to_str())
181192
.map(|name| String::from_str(name).expect("could not parse string from file name"))
182193
.expect("Failed to extract file name")
183194
})
184195
.collect()
185196
}
186197

187-
fn load_images(input: &[String]) -> Vec<InputSprite> {
198+
fn load_images<T>(input: &[T]) -> Vec<InputSprite>
199+
where
200+
T: AsRef<Path>,
201+
{
188202
input
189203
.iter()
190204
.map(|path| {

0 commit comments

Comments
 (0)