Remove calls to exit() and replace them with error propagation up to main()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
0e14f953ca
commit
ab39aa9353
2 changed files with 21 additions and 26 deletions
|
@ -23,6 +23,7 @@ maintenance = { status = "actively-developed" }
|
|||
[dependencies]
|
||||
log = "0.4.6"
|
||||
failure = "0.1.5"
|
||||
resiter = "0.3.0"
|
||||
|
||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
extern crate clap;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate failure;
|
||||
extern crate resiter;
|
||||
|
||||
extern crate libimagerror;
|
||||
extern crate libimagrt;
|
||||
|
@ -47,13 +48,14 @@ use std::io::Write;
|
|||
use failure::Error;
|
||||
use failure::err_msg;
|
||||
use failure::Fallible as Result;
|
||||
use resiter::AndThen;
|
||||
use resiter::Map;
|
||||
use clap::App;
|
||||
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagrt::application::ImagApplication;
|
||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||
use crate::libimagerror::iter::IterInnerOkOrElse;
|
||||
|
||||
mod ui;
|
||||
|
||||
|
@ -69,40 +71,32 @@ impl ImagApplication for ImagMarkdown {
|
|||
let mut outlock = out.lock();
|
||||
|
||||
let iter = rt
|
||||
.ids::<crate::ui::PathProvider>()
|
||||
.map_err_trace_exit_unwrap()
|
||||
.unwrap_or_else(|| {
|
||||
error!("No ids supplied");
|
||||
::std::process::exit(1);
|
||||
})
|
||||
.ids::<crate::ui::PathProvider>()?
|
||||
.ok_or_else(|| err_msg("No ids supplied"))?
|
||||
.into_iter()
|
||||
.map(Ok)
|
||||
.into_get_iter(rt.store())
|
||||
.trace_unwrap_exit()
|
||||
.map(|ofle| ofle.ok_or_else(|| {
|
||||
err_msg("Entry does not exist but is in store. This is a BUG, please report!")
|
||||
}))
|
||||
.trace_unwrap_exit();
|
||||
.map_inner_ok_or_else(|| err_msg("Entry does not exist but is in store. This is a BUG, please report!"));
|
||||
|
||||
if only_links {
|
||||
iter.map(|fle| libimagentrymarkdown::link::extract_links(fle.get_content()))
|
||||
.for_each(|links| {
|
||||
links.iter().for_each(|link| {
|
||||
writeln!(outlock, "{title}: {link}", title = link.title, link = link.link)
|
||||
.map_err(Error::from)
|
||||
.map_err_trace_exit_unwrap();
|
||||
debug!("Printing only links");
|
||||
iter.map_ok(|fle| libimagentrymarkdown::link::extract_links(fle.get_content()))
|
||||
.and_then_ok(|links| {
|
||||
links.iter()
|
||||
.map(|link| {
|
||||
writeln!(outlock, "{title}: {link}", title = link.title, link = link.link).map_err(Error::from)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
|
||||
} else {
|
||||
iter.map(|fle| libimagentrymarkdown::html::to_html(fle.get_content()))
|
||||
.trace_unwrap_exit()
|
||||
.for_each(|html| {
|
||||
writeln!(outlock, "{}", html).map_err(Error::from).map_err_trace_exit_unwrap();
|
||||
iter.and_then_ok(|fle| libimagentrymarkdown::html::to_html(fle.get_content()))
|
||||
.and_then_ok(|html| {
|
||||
writeln!(outlock, "{}", html).map_err(Error::from).map_err(Error::from)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||
|
|
Loading…
Reference in a new issue