summaryrefslogtreecommitdiffstats
path: root/bin/core
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-10-19 08:54:57 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-26 18:15:20 +0200
commitab39aa935337fa08219138364c440275cd989852 (patch)
treef8073c24cb78ffe1e8349cff4cea288768d95989 /bin/core
parent0e14f953ca72a98ee7dc51fe70a0341e4b04eee6 (diff)
Remove calls to exit() and replace them with error propagation up to main()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin/core')
-rw-r--r--bin/core/imag-markdown/Cargo.toml1
-rw-r--r--bin/core/imag-markdown/src/lib.rs46
2 files changed, 21 insertions, 26 deletions
diff --git a/bin/core/imag-markdown/Cargo.toml b/bin/core/imag-markdown/Cargo.toml
index e35d431a..21311975 100644
--- a/bin/core/imag-markdown/Cargo.toml
+++ b/bin/core/imag-markdown/Cargo.toml
@@ -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" }
diff --git a/bin/core/imag-markdown/src/lib.rs b/bin/core/imag-markdown/src/lib.rs
index 2250fe41..1d88e4c2 100644
--- a/bin/core/imag-markdown/src/lib.rs
+++ b/bin/core/imag-markdown/src/lib.rs
@@ -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> {