add an option to set the pad wanted
This commit is contained in:
parent
4f7ecbf9ff
commit
38980f8d8a
42
src/lib.rs
42
src/lib.rs
@ -15,10 +15,13 @@ pub struct Opt {
|
|||||||
// TODO: check if I really do this or not when implementing the recursive option
|
// TODO: check if I really do this or not when implementing the recursive option
|
||||||
pub comic_folder: PathBuf,
|
pub comic_folder: PathBuf,
|
||||||
|
|
||||||
// TODO: implement the recursivity
|
/// Set the pad you want to use
|
||||||
/// Recursively treat each child folder as a it's own comic to bind
|
///
|
||||||
#[structopt(short, long)]
|
/// If not set or set to a value inferior to the maximum pad of the comic, the value is
|
||||||
pub recursive: bool,
|
/// ignored.
|
||||||
|
#[structopt(long)]
|
||||||
|
pub pad: Option<usize>,
|
||||||
|
|
||||||
// TODO: implement the prefix
|
// TODO: implement the prefix
|
||||||
// /// Prefix to use for the files
|
// /// 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
|
// /// For example: when the title contains the name of the comic with its season: fooS02-42.png
|
||||||
// #[structopt(short, long)]
|
// #[structopt(short, long)]
|
||||||
// pub prefix: &str,
|
// 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 {
|
impl Opt {
|
||||||
@ -78,15 +86,15 @@ impl Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ComicBook {
|
pub struct ComicBook {
|
||||||
pad: Option<u64>,
|
pad: Option<usize>,
|
||||||
pages: Vec<Page>,
|
pages: Vec<Page>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComicBook {
|
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();
|
let regex = Regex::new(r"\./(?P<prefix>\D*)(?P<number>\d*)(?P<suffix>.*)").unwrap();
|
||||||
ComicBook {
|
ComicBook {
|
||||||
pad: None,
|
pad,
|
||||||
pages: files
|
pages: files
|
||||||
.map(|entry| entry.unwrap().path())
|
.map(|entry| entry.unwrap().path())
|
||||||
.filter(|entry| entry.is_file())
|
.filter(|entry| entry.is_file())
|
||||||
@ -109,7 +117,7 @@ impl ComicBook {
|
|||||||
for page in self.pages.iter() {
|
for page in self.pages.iter() {
|
||||||
//if let Some(pos) = page.position {
|
//if let Some(pos) = page.position {
|
||||||
let original_file = page.original_filename();
|
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));
|
println!("{} -> {}", original_file, dbg!(new_file));
|
||||||
|
|
||||||
@ -119,13 +127,23 @@ impl ComicBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_pad_size(&self) -> Option<usize> {
|
fn get_pad_size(&self) -> Option<usize> {
|
||||||
Some(
|
let pad_pages = self
|
||||||
self.pages
|
.pages
|
||||||
.iter()
|
.iter()
|
||||||
.max_by_key(|x| x.number.len())?
|
.max_by_key(|x| x.number.len())?
|
||||||
.number
|
.number
|
||||||
.len(),
|
.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();
|
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();
|
book.bind();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user