handle ProgressStyle's template now returning a Result
This commit is contained in:
parent
81e8a62555
commit
7233477c76
4 changed files with 30 additions and 5 deletions
|
@ -30,7 +30,11 @@ pub fn generate_epubs(
|
||||||
let enabled_bar = ProgressBar::new(articles.len() as u64);
|
let enabled_bar = ProgressBar::new(articles.len() as u64);
|
||||||
let style = ProgressStyle::default_bar().template(
|
let style = ProgressStyle::default_bar().template(
|
||||||
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} epub {pos}/{len:7} {msg:.green}",
|
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} epub {pos}/{len:7} {msg:.green}",
|
||||||
);
|
).map_err(|e| {
|
||||||
|
let mut paperoni_err: PaperoniError = e.into();
|
||||||
|
paperoni_err.set_article_source("progress bar");
|
||||||
|
vec![paperoni_err]
|
||||||
|
})?;
|
||||||
enabled_bar.set_style(style);
|
enabled_bar.set_style(style);
|
||||||
if !articles.is_empty() {
|
if !articles.is_empty() {
|
||||||
enabled_bar.set_message("Generating epubs");
|
enabled_bar.set_message("Generating epubs");
|
||||||
|
|
|
@ -15,6 +15,8 @@ pub enum ErrorKind {
|
||||||
UTF8Error(String),
|
UTF8Error(String),
|
||||||
#[error("[ReadabilityError]: {0}")]
|
#[error("[ReadabilityError]: {0}")]
|
||||||
ReadabilityError(String),
|
ReadabilityError(String),
|
||||||
|
#[error("[TemplateError]: {0}")]
|
||||||
|
TemplateError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -128,6 +130,12 @@ impl From<std::str::Utf8Error> for PaperoniError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<indicatif::style::TemplateError> for PaperoniError {
|
||||||
|
fn from(err: indicatif::style::TemplateError) -> Self {
|
||||||
|
PaperoniError::with_kind(ErrorKind::TemplateError(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum LogError {
|
pub enum LogError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|
|
@ -44,7 +44,11 @@ pub fn generate_html_exports(
|
||||||
let enabled_bar = ProgressBar::new(articles.len() as u64);
|
let enabled_bar = ProgressBar::new(articles.len() as u64);
|
||||||
let style = ProgressStyle::default_bar().template(
|
let style = ProgressStyle::default_bar().template(
|
||||||
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} html {pos}/{len:7} {msg:.green}",
|
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} html {pos}/{len:7} {msg:.green}",
|
||||||
);
|
).map_err(|e| {
|
||||||
|
let mut paperoni_err: PaperoniError = e.into();
|
||||||
|
paperoni_err.set_article_source("progress bar");
|
||||||
|
vec![paperoni_err]
|
||||||
|
})?;
|
||||||
enabled_bar.set_style(style);
|
enabled_bar.set_style(style);
|
||||||
if !articles.is_empty() {
|
if !articles.is_empty() {
|
||||||
enabled_bar.set_message("Generating html files");
|
enabled_bar.set_message("Generating html files");
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -2,6 +2,7 @@
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use comfy_table::presets::{UTF8_FULL, UTF8_HORIZONTAL_ONLY};
|
use comfy_table::presets::{UTF8_FULL, UTF8_HORIZONTAL_ONLY};
|
||||||
|
@ -25,6 +26,8 @@ use epub::generate_epubs;
|
||||||
use html::generate_html_exports;
|
use html::generate_html_exports;
|
||||||
use logs::display_summary;
|
use logs::display_summary;
|
||||||
|
|
||||||
|
use crate::errors::PaperoniError;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app_config = match cli::AppConfig::init_with_cli() {
|
let app_config = match cli::AppConfig::init_with_cli() {
|
||||||
Ok(app_config) => app_config,
|
Ok(app_config) => app_config,
|
||||||
|
@ -58,9 +61,15 @@ fn run(app_config: AppConfig) {
|
||||||
let enabled_bar = ProgressBar::new(app_config.urls.len() as u64);
|
let enabled_bar = ProgressBar::new(app_config.urls.len() as u64);
|
||||||
let style = ProgressStyle::default_bar().template(
|
let style = ProgressStyle::default_bar().template(
|
||||||
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} link {pos}/{len:7} {msg:.yellow/white}",
|
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} link {pos}/{len:7} {msg:.yellow/white}",
|
||||||
);
|
).map_err(|e| {
|
||||||
enabled_bar.set_style(style);
|
let mut paperoni_err: PaperoniError = e.into();
|
||||||
enabled_bar.enable_steady_tick(500);
|
paperoni_err.set_article_source("progress bar");
|
||||||
|
vec![paperoni_err]
|
||||||
|
});
|
||||||
|
if let Ok(style) = style {
|
||||||
|
enabled_bar.set_style(style);
|
||||||
|
}
|
||||||
|
enabled_bar.enable_steady_tick(Duration::from_millis(500));
|
||||||
enabled_bar
|
enabled_bar
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue