parent
1b1a66fe6c
commit
abedfc9c70
2 changed files with 11 additions and 9 deletions
|
|
@ -16,6 +16,7 @@ pub mod deflate {
|
||||||
}
|
}
|
||||||
pub mod png;
|
pub mod png;
|
||||||
|
|
||||||
|
#[derive(Clone,Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
pub backup: bool,
|
pub backup: bool,
|
||||||
pub out_file: PathBuf,
|
pub out_file: PathBuf,
|
||||||
|
|
|
||||||
19
src/main.rs
19
src/main.rs
|
|
@ -230,26 +230,27 @@ fn main() {
|
||||||
.iter()
|
.iter()
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.collect(),
|
.collect(),
|
||||||
&mut opts);
|
opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_optimization(inputs: Vec<PathBuf>, opts: &mut oxipng::Options) {
|
fn handle_optimization(inputs: Vec<PathBuf>, opts: oxipng::Options) {
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
|
let mut current_opts = opts.clone();
|
||||||
if input.is_dir() {
|
if input.is_dir() {
|
||||||
if opts.recursive {
|
if current_opts.recursive {
|
||||||
handle_optimization(input.read_dir().unwrap().map(|x| x.unwrap().path()).collect(),
|
handle_optimization(input.read_dir().unwrap().map(|x| x.unwrap().path()).collect(),
|
||||||
opts)
|
current_opts)
|
||||||
} else {
|
} else {
|
||||||
println!("{} is a directory, skipping", input.display());
|
println!("{} is a directory, skipping", input.display());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(out_dir) = opts.out_dir.clone() {
|
if let Some(out_dir) = current_opts.out_dir.clone() {
|
||||||
opts.out_file = out_dir.join(input.file_name().unwrap());
|
current_opts.out_file = out_dir.join(input.file_name().unwrap());
|
||||||
} else if opts.out_file.components().count() == 0 {
|
} else if current_opts.out_file.components().count() == 0 {
|
||||||
opts.out_file = input.clone();
|
current_opts.out_file = input.clone();
|
||||||
}
|
}
|
||||||
match oxipng::optimize(&input, opts) {
|
match oxipng::optimize(&input, ¤t_opts) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(x) => println!("{}", x),
|
Err(x) => println!("{}", x),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue