diff --git a/src/lib.rs b/src/lib.rs index 989df7f..9957c77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,10 +15,13 @@ pub struct Opt { // TODO: check if I really do this or not when implementing the recursive option pub comic_folder: PathBuf, - // TODO: implement the recursivity - /// Recursively treat each child folder as a it's own comic to bind - #[structopt(short, long)] - pub recursive: bool, + /// Set the pad you want to use + /// + /// If not set or set to a value inferior to the maximum pad of the comic, the value is + /// ignored. + #[structopt(long)] + pub pad: Option, + // TODO: implement the prefix // /// Prefix to use for the files // /// @@ -26,6 +29,11 @@ pub struct Opt { // /// For example: when the title contains the name of the comic with its season: fooS02-42.png // #[structopt(short, long)] // pub prefix: &str, + + // TODO: implement the recursivity + /// Recursively treat each child folder as a it's own comic to bind + #[structopt(short, long)] + pub recursive: bool, } impl Opt { @@ -78,15 +86,15 @@ impl Page { } pub struct ComicBook { - pad: Option, + pad: Option, pages: Vec, } impl ComicBook { - pub fn new(files: ReadDir) -> ComicBook { + pub fn new(files: ReadDir, pad: Option) -> ComicBook { let regex = Regex::new(r"\./(?P\D*)(?P\d*)(?P.*)").unwrap(); ComicBook { - pad: None, + pad, pages: files .map(|entry| entry.unwrap().path()) .filter(|entry| entry.is_file()) @@ -109,7 +117,7 @@ impl ComicBook { for page in self.pages.iter() { //if let Some(pos) = page.position { let original_file = page.original_filename(); - let new_file = page.new_filename(dbg!(pad)); + let new_file = page.new_filename(pad); println!("{} -> {}", original_file, dbg!(new_file)); @@ -119,13 +127,23 @@ impl ComicBook { } fn get_pad_size(&self) -> Option { - Some( - self.pages - .iter() - .max_by_key(|x| x.number.len())? - .number - .len(), - ) + let pad_pages = self + .pages + .iter() + .max_by_key(|x| x.number.len())? + .number + .len(); + + let pad = if let Some(pad_conf) = self.pad { + if pad_conf < pad_pages { + pad_pages + } else { + pad_conf + } + } else { + pad_pages + }; + Some(pad) } } diff --git a/src/main.rs b/src/main.rs index 9d53e02..e9df017 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ fn main() { } env::set_current_dir(opt.comic_folder).unwrap(); - let mut book = ComicBook::new(fs::read_dir(".").unwrap()); + let mut book = ComicBook::new(fs::read_dir(".").unwrap(), opt.pad); book.bind();