From 9c2232e37f25815d7335211f50a0e4c404257c8a Mon Sep 17 00:00:00 2001 From: Kenneth Gitere Date: Tue, 27 Jul 2021 17:08:58 +0300 Subject: [PATCH] fix: add validation when passing inline-images flag --- src/cli.rs | 12 +++++++++++- src/errors.rs | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 12a6357..9578a49 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -164,7 +164,17 @@ impl<'a> TryFrom> for AppConfig { ExportType::EPUB } }) - .is_inlining_images(arg_matches.is_present("inline-images")) + .is_inlining_images( + (if arg_matches.is_present("inline-images") { + if arg_matches.value_of("export") == Some("html") { + Ok(true) + } else { + Err(Error::WrongExportInliningImages) + } + } else { + Ok(false) + })?, + ) .try_init() } } diff --git a/src/errors.rs b/src/errors.rs index 8fbfeea..5b1cc25 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -156,6 +156,8 @@ pub enum CliError { OutputDirectoryNotExists, #[error("Unable to start logger!\n{0}")] LogError(#[from] LogError), - #[error("The --inline-toc can only be used exporting to epub")] + #[error("The --inline-toc flag can only be used when exporting to epub")] WrongExportInliningToC, + #[error("The --inline-images flag can only be used when exporting to html")] + WrongExportInliningImages, }