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]
|
[dependencies]
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
|
resiter = "0.3.0"
|
||||||
|
|
||||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
extern crate resiter;
|
||||||
|
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
|
@ -47,13 +48,14 @@ use std::io::Write;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
use resiter::AndThen;
|
||||||
|
use resiter::Map;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
|
|
||||||
use libimagerror::trace::MapErrTrace;
|
|
||||||
use libimagerror::iter::TraceIterator;
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::application::ImagApplication;
|
use libimagrt::application::ImagApplication;
|
||||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||||
|
use crate::libimagerror::iter::IterInnerOkOrElse;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
@ -69,40 +71,32 @@ impl ImagApplication for ImagMarkdown {
|
||||||
let mut outlock = out.lock();
|
let mut outlock = out.lock();
|
||||||
|
|
||||||
let iter = rt
|
let iter = rt
|
||||||
.ids::<crate::ui::PathProvider>()
|
.ids::<crate::ui::PathProvider>()?
|
||||||
.map_err_trace_exit_unwrap()
|
.ok_or_else(|| err_msg("No ids supplied"))?
|
||||||
.unwrap_or_else(|| {
|
|
||||||
error!("No ids supplied");
|
|
||||||
::std::process::exit(1);
|
|
||||||
})
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Ok)
|
.map(Ok)
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit()
|
.map_inner_ok_or_else(|| err_msg("Entry does not exist but is in store. This is a BUG, please report!"));
|
||||||
.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();
|
|
||||||
|
|
||||||
if only_links {
|
if only_links {
|
||||||
iter.map(|fle| libimagentrymarkdown::link::extract_links(fle.get_content()))
|
debug!("Printing only links");
|
||||||
.for_each(|links| {
|
iter.map_ok(|fle| libimagentrymarkdown::link::extract_links(fle.get_content()))
|
||||||
links.iter().for_each(|link| {
|
.and_then_ok(|links| {
|
||||||
writeln!(outlock, "{title}: {link}", title = link.title, link = link.link)
|
links.iter()
|
||||||
.map_err(Error::from)
|
.map(|link| {
|
||||||
.map_err_trace_exit_unwrap();
|
writeln!(outlock, "{title}: {link}", title = link.title, link = link.link).map_err(Error::from)
|
||||||
})
|
})
|
||||||
|
.collect()
|
||||||
})
|
})
|
||||||
|
.collect()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
iter.map(|fle| libimagentrymarkdown::html::to_html(fle.get_content()))
|
iter.and_then_ok(|fle| libimagentrymarkdown::html::to_html(fle.get_content()))
|
||||||
.trace_unwrap_exit()
|
.and_then_ok(|html| {
|
||||||
.for_each(|html| {
|
writeln!(outlock, "{}", html).map_err(Error::from).map_err(Error::from)
|
||||||
writeln!(outlock, "{}", html).map_err(Error::from).map_err_trace_exit_unwrap();
|
|
||||||
})
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
|
|
Loading…
Reference in a new issue