fix: add validation when passing --inline-toc

feat: add coloring when displaying CLI errors
This commit is contained in:
Kenneth Gitere 2021-07-24 12:35:30 +03:00
parent 2f4da824ba
commit eac28da798
3 changed files with 15 additions and 2 deletions

View file

@ -119,7 +119,17 @@ impl<'a> TryFrom<ArgMatches<'a>> for AppConfig {
4..=u64::MAX => LogLevel::Debug,
})
.is_logging_to_file(arg_matches.is_present("log-to-file"))
.inline_toc(arg_matches.is_present("inline-toc"))
.inline_toc(
(if arg_matches.is_present("inline-toc") {
if arg_matches.value_of("export") == Some("epub") {
Ok(true)
} else {
Err(Error::WrongExportInliningToC)
}
} else {
Ok(false)
})?,
)
.output_directory(
arg_matches
.value_of("output_directory")

View file

@ -156,4 +156,6 @@ pub enum CliError<BuilderError: Debug + Display> {
OutputDirectoryNotExists,
#[error("Unable to start logger!\n{0}")]
LogError(#[from] LogError),
#[error("The --inline-toc can only be used exporting to epub")]
WrongExportInliningToC,
}

View file

@ -3,6 +3,7 @@ extern crate lazy_static;
use std::process::exit;
use colored::Colorize;
use comfy_table::presets::{UTF8_FULL, UTF8_HORIZONTAL_BORDERS_ONLY};
use comfy_table::{ContentArrangement, Table};
use http::download;
@ -28,7 +29,7 @@ fn main() {
let app_config = match cli::AppConfig::init_with_cli() {
Ok(app_config) => app_config,
Err(err) => {
eprintln!("{}", err);
eprintln!("{}: {}", "ERROR".bold().bright_red(), err);
exit(1);
}
};