summaryrefslogtreecommitdiffstats
path: root/imag-bookmark
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-10-11 11:17:20 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-10-11 11:20:38 +0200
commit9bb21e6a190e16888ad1725ebe6f7e4978189707 (patch)
tree85a4699c07dd2883a91c4ce0c70885aac50efc96 /imag-bookmark
parent49b054aeda4f4ede53fcf30a6ab503d26584f76b (diff)
imag-bookmark: Rewrite add() with iterator helpers
Diffstat (limited to 'imag-bookmark')
-rw-r--r--imag-bookmark/src/main.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/imag-bookmark/src/main.rs b/imag-bookmark/src/main.rs
index 88f41f7b..dd4e20a6 100644
--- a/imag-bookmark/src/main.rs
+++ b/imag-bookmark/src/main.rs
@@ -49,7 +49,9 @@ use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
use libimagbookmark::collection::BookmarkCollection;
use libimagbookmark::link::Link as BookmarkLink;
-use libimagerror::trace::{trace_error, trace_error_exit};
+use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
+use libimagutil::info_result::*;
+use libimagutil::iter::*;
mod ui;
@@ -82,12 +84,14 @@ fn add(rt: &Runtime) {
let coll = scmd.value_of("collection").unwrap(); // enforced by clap
BookmarkCollection::get(rt.store(), coll)
- .map(|mut collection| {
- for url in scmd.values_of("urls").unwrap() { // enforced by clap
- collection.add_link(BookmarkLink::from(url)).map_err(|e| trace_error(&e)).ok();
- }
- });
- info!("Ready");
+ .and_then(|mut collection| {
+ scmd.values_of("urls")
+ .unwrap() // enforced by clap
+ .fold_defresult(|url| collection.add_link(BookmarkLink::from(url)))
+ })
+ .map_err_trace()
+ .map_info_str("Ready")
+ .ok();
}
fn collection(rt: &Runtime) {