From ebd2f3443ebb9c1f7b20ac0a0344df738215f519 Mon Sep 17 00:00:00 2001 From: Marc Plano-Lesay Date: Tue, 15 Oct 2024 17:30:02 +1100 Subject: [PATCH] Cleanup --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 30 ++++++++++++++---------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 076cda4..3d2428e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,6 +244,7 @@ dependencies = [ name = "cbz2pdf" version = "0.1.0" dependencies = [ + "anyhow", "clap", "dialoguer", "image", diff --git a/Cargo.toml b/Cargo.toml index e6d5ba1..9c3b0f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +anyhow = "1.0.89" clap = { version = "4.5.20", features = ["derive"] } dialoguer = "0.11.0" image = "0.25.2" diff --git a/src/main.rs b/src/main.rs index 479a912..195a5b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use anyhow::Result; use clap::{Parser, ValueHint}; use dialoguer::theme::ColorfulTheme; use dialoguer::Confirm; @@ -86,7 +87,7 @@ fn main() -> Result<(), Box> { }; if proceed { - process_jobs(jobs); + process_jobs(jobs)?; } Ok(()) @@ -145,7 +146,7 @@ impl Job { } } -fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<(), Box> { +fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<()> { let a4 = Rect::new(0.0, 0.0, 595.0, 842.0); let mut zip = ZipArchive::new(File::open(cbz_path)?)?; @@ -180,13 +181,12 @@ fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<(), Box Result<(), Box) { - let pb = ProgressBar::new(jobs.len().try_into().unwrap()); +fn process_jobs(jobs: Vec) -> Result<()> { + let pb = ProgressBar::new(jobs.len() as u64); pb.enable_steady_tick(Duration::from_millis(300)); - pb.set_style( - ProgressStyle::with_template("[{elapsed_precise}] {wide_bar} {pos:>7}/{len:7} {msg}") - .unwrap(), - ); + pb.set_style(ProgressStyle::with_template( + "[{elapsed_precise}] {wide_bar} {pos:>7}/{len:7} {msg}", + )?); jobs.par_iter().for_each(|entry| { convert_cbz(&entry.cbz_path, &entry.pdf_path).unwrap(); @@ -237,4 +234,5 @@ fn process_jobs(jobs: Vec) { }); pb.finish(); + Ok(()) }