From 295c9c4c6f1f6d0c018f429c084269cc5ec1d475 Mon Sep 17 00:00:00 2001 From: mfgm2 Date: Wed, 2 Oct 2019 04:49:52 +0300 Subject: [PATCH] allow dry-run without -d --- Cargo.lock | 2 +- src/main.rs | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 886aaf0..75577be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -381,7 +381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "sg-sprite" -version = "0.1.0" +version = "0.1.1" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "custom_error 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/main.rs b/src/main.rs index 6cc53ab..ffcdb0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use std::path::{Path, PathBuf}; struct Opts { /// Output dir #[structopt(short, long, parse(from_os_str))] - dir: PathBuf, + dir: Option, /// Limit variants to draw per sprite #[structopt(short, long)] @@ -70,10 +70,14 @@ fn main() { fn main_() -> Result<(), PErr> { let o = Opts::from_args(); - let out_dir = o.dir; + let out_dir = &o.dir; - if !out_dir.is_dir() { - raise("out_dir isn't a directory")? + match out_dir { + Some(d) if !d.is_dir() => return raise("out_dir isn't a directory"), + None if !o.dry_run => { + return raise("Output dir should be specified (-d)\nSee --help for details") + } + _ => (), } let total = o.lay_files.len(); @@ -86,7 +90,7 @@ fn main_() -> Result<(), PErr> { let status = |c: usize| move |t: &str| println!("[{}/{}] {}", c + 1, total, t); for lay_i in &o.lay_files { - if let Err(e) = lay_in(&out_dir, lay_i, o.limit, !o.dry_run, status(lay_counter)) { + if let Err(e) = lay_in(out_dir, lay_i, o.limit, !o.dry_run, status(lay_counter)) { print_err(e); } @@ -97,7 +101,7 @@ fn main_() -> Result<(), PErr> { } fn lay_in( - out_dir: &Path, + out_dir: &Option, lay_i: &Path, limit: Option, draw_en: bool, @@ -153,13 +157,13 @@ fn lay_in( SpriteT::Overlay => fmt!("o{}", s.id), }; - let mut out = PathBuf::new(); - out.push(&out_dir); - out.push(fmt!("{}_{}{}", sprite_name, name_suf, SRC_EXT)); - let dep_lst = resolve_dep_list(&dep_refs, sp)?; if let Some(src_i) = src.as_mut() { + let mut out = PathBuf::new(); + out.push(out_dir.as_ref().unwrap()); + out.push(fmt!("{}_{}{}", sprite_name, name_suf, SRC_EXT)); + if let Err(e) = draw_sprites(src_i, &out, dep_lst.as_ref(), pass + 1, &lay) { print_err(e); }