add an option to set the pad wanted
This commit is contained in:
parent
4f7ecbf9ff
commit
38980f8d8a
48
src/lib.rs
48
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<usize>,
|
||||
|
||||
// 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<u64>,
|
||||
pad: Option<usize>,
|
||||
pages: Vec<Page>,
|
||||
}
|
||||
|
||||
impl ComicBook {
|
||||
pub fn new(files: ReadDir) -> ComicBook {
|
||||
pub fn new(files: ReadDir, pad: Option<usize>) -> ComicBook {
|
||||
let regex = Regex::new(r"\./(?P<prefix>\D*)(?P<number>\d*)(?P<suffix>.*)").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<usize> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user