fix: add validation when passing inline-images flag

This commit is contained in:
Kenneth Gitere 2021-07-27 17:08:58 +03:00
parent 40cf5b06c9
commit 9c2232e37f
2 changed files with 14 additions and 2 deletions

View file

@ -164,7 +164,17 @@ impl<'a> TryFrom<ArgMatches<'a>> for AppConfig {
ExportType::EPUB 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() .try_init()
} }
} }

View file

@ -156,6 +156,8 @@ pub enum CliError<BuilderError: Debug + Display> {
OutputDirectoryNotExists, OutputDirectoryNotExists,
#[error("Unable to start logger!\n{0}")] #[error("Unable to start logger!\n{0}")]
LogError(#[from] LogError), 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, WrongExportInliningToC,
#[error("The --inline-images flag can only be used when exporting to html")]
WrongExportInliningImages,
} }