diff --git a/bin/core/imag-annotate/Cargo.toml b/bin/core/imag-annotate/Cargo.toml index 63cdc07c..5c5b89da 100644 --- a/bin/core/imag-annotate/Cargo.toml +++ b/bin/core/imag-annotate/Cargo.toml @@ -25,6 +25,7 @@ url = "2" toml = "0.5.1" toml-query = "0.9.2" failure = "0.1.5" +resiter = "0.4.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-annotate/src/lib.rs b/bin/core/imag-annotate/src/lib.rs index 0e80fbe5..61ce94ae 100644 --- a/bin/core/imag-annotate/src/lib.rs +++ b/bin/core/imag-annotate/src/lib.rs @@ -40,6 +40,7 @@ extern crate log; #[macro_use] extern crate failure; extern crate toml_query; +extern crate resiter; extern crate libimagentryannotation; extern crate libimagentryedit; @@ -55,6 +56,9 @@ use failure::Error; use failure::Fallible as Result; use failure::ResultExt; use failure::err_msg; +use resiter::IterInnerOkOrElse; +use resiter::AndThen; +use resiter::Map; use toml_query::read::TomlValueReadTypeExt; use clap::App; @@ -67,6 +71,7 @@ use libimagrt::application::ImagApplication; use libimagstore::store::FileLockEntry; use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimagentrylink::linkable::Linkable; +use libimagrt::iter::ReportTouchedResultEntry; mod ui; @@ -121,12 +126,13 @@ fn add(rt: &Runtime) -> Result<()> { annotation.edit_content(&rt)?; - for id in ids { - let mut entry = rt.store().get(id.clone())? - .ok_or_else(|| format_err!("Not found: {}", id.local_display_string()))?; - - entry.add_link(&mut annotation)?; - } + rt.report_touched(&first)?; // report first one first + ids.map(Ok).into_get_iter(rt.store()) + .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .and_then_ok(|mut entry| entry.add_link(&mut annotation).map(|_| entry)) + .map_report_touched(&rt) + .map_ok(|_| ()) + .collect::>>()?; if !scmd.is_present("dont-print-name") { if let Some(annotation_id) = annotation @@ -139,6 +145,8 @@ fn add(rt: &Runtime) -> Result<()> { .context("This is most likely a BUG, please report!")?; } } + + rt.report_touched(annotation.get_location())?; } else { debug!("No entries to annotate"); } @@ -176,7 +184,7 @@ fn remove(rt: &Runtime) -> Result<()> { debug!("Not deleting annotation object"); } - Ok(()) + rt.report_touched(entry.get_location()).map_err(Error::from) }) .collect() } @@ -200,7 +208,9 @@ fn list(rt: &Runtime) -> Result<()> { .into_get_iter(rt.store()) .map(|el| el.and_then(|o| o.ok_or_else(|| format_err!("Cannot find entry")))) .enumerate() - .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, e, with_text))) + .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, &e, with_text).map(|_| e))) + .map_report_touched(&rt) + .map_ok(|_| ()) .collect()) }) .flatten() @@ -212,12 +222,14 @@ fn list(rt: &Runtime) -> Result<()> { .into_get_iter() .map(|el| el.and_then(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))) .enumerate() - .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, e, with_text))) + .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, &e, with_text).map(|_| e))) + .map_report_touched(&rt) + .map_ok(|_| ()) .collect() } } -fn list_annotation<'a>(rt: &Runtime, i: usize, a: FileLockEntry<'a>, with_text: bool) -> Result<()> { +fn list_annotation<'a>(rt: &Runtime, i: usize, a: &FileLockEntry<'a>, with_text: bool) -> Result<()> { if with_text { writeln!(rt.stdout(), "--- {i: >5} | {id}\n{text}\n\n", diff --git a/bin/core/imag-category/src/lib.rs b/bin/core/imag-category/src/lib.rs index 3a2a867d..27fd2d6b 100644 --- a/bin/core/imag-category/src/lib.rs +++ b/bin/core/imag-category/src/lib.rs @@ -48,10 +48,11 @@ extern crate libimagstore; extern crate libimaginteraction; use failure::Fallible as Result; +use resiter::Map; use clap::App; -use libimagerror::trace::MapErrTrace; use libimagrt::runtime::Runtime; +use libimagrt::iter::ReportTouchedResultEntry; use libimagrt::application::ImagApplication; mod ui; @@ -120,7 +121,9 @@ fn set(rt: &Runtime) -> Result<()> { .map(Ok) .into_get_iter(rt.store()) .map_inner_ok_or_else(|| err_msg("Did not find one entry")) - .and_then_ok(|mut e| e.set_category_checked(rt.store(), &name)) + .and_then_ok(|mut e| e.set_category_checked(rt.store(), &name).map(|_| e)) + .map_report_touched(&rt) + .map_ok(|_| ()) .collect() } @@ -132,9 +135,10 @@ fn get(rt: &Runtime) -> Result<()> { .into_iter() .map(Ok) .into_get_iter(rt.store()) - .map(|el| el.and_then(|o| o.ok_or_else(|| err_msg("Did not find one entry")))) - .map(|entry| entry.and_then(|e| e.get_category())) - .map(|name| name.and_then(|n| writeln!(outlock, "{}", n).map_err(Error::from))) + .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .map_report_touched(&rt) + .and_then_ok(|e| e.get_category()) + .and_then_ok(|n| writeln!(outlock, "{}", n).map_err(Error::from)) .collect() } @@ -147,8 +151,8 @@ fn list_category(rt: &Runtime) -> Result<()> { let mut outlock = out.lock(); category - .get_entries(rt.store()) - .map_err_trace_exit_unwrap() + .get_entries(rt.store())? + .map_report_touched(&rt) .map(|entry| writeln!(outlock, "{}", entry?.get_location()).map_err(Error::from)) .collect() } else { @@ -159,7 +163,9 @@ fn list_category(rt: &Runtime) -> Result<()> { fn create_category(rt: &Runtime) -> Result<()> { let scmd = rt.cli().subcommand_matches("create-category").unwrap(); // safed by main() let name = scmd.value_of("create-category-name").map(String::from).unwrap(); // safed by clap - rt.store().create_category(&name).map(|_| ()) + rt.store() + .create_category(&name) + .and_then(|e| rt.report_touched(e.get_location()).map_err(Error::from)) } fn delete_category(rt: &Runtime) -> Result<()> { @@ -175,7 +181,7 @@ fn delete_category(rt: &Runtime) -> Result<()> { if answer { info!("Deleting category '{}'", name); - rt.store().delete_category(&name).map(|_| ()) + rt.store().delete_category(&name) } else { info!("Not doing anything"); Ok(()) @@ -188,7 +194,7 @@ fn list_categories(rt: &Runtime) -> Result<()> { rt.store() .all_category_names()? - .map(|name| name.and_then(|n| writeln!(outlock, "{}", n).map_err(Error::from))) + .and_then_ok(|n| writeln!(outlock, "{}", n).map_err(Error::from)) .collect() } diff --git a/bin/core/imag-create/src/lib.rs b/bin/core/imag-create/src/lib.rs index ced6e0ac..c208aa54 100644 --- a/bin/core/imag-create/src/lib.rs +++ b/bin/core/imag-create/src/lib.rs @@ -47,6 +47,7 @@ use clap::App; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; +use libimagrt::iter::ReportTouchedResultEntry; use libimagstore::iter::create::StoreIdCreateIteratorExtension; use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension; @@ -65,9 +66,9 @@ impl ImagApplication for ImagCreate { .map(Ok); if force { - ids.into_retrieve_iter(rt.store()).collect::>>() + ids.into_retrieve_iter(rt.store()).map_report_touched(&rt).collect::>>() } else { - ids.into_create_iter(rt.store()).collect::>>() + ids.into_create_iter(rt.store()).map_report_touched(&rt).collect::>>() }.map(|_| ()) } diff --git a/bin/core/imag-edit/src/lib.rs b/bin/core/imag-edit/src/lib.rs index 85d005fe..10a00fea 100644 --- a/bin/core/imag-edit/src/lib.rs +++ b/bin/core/imag-edit/src/lib.rs @@ -49,6 +49,7 @@ use libimagentryedit::edit::Edit; use libimagentryedit::edit::EditHeader; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; +use libimagrt::iter::ReportTouchedResultEntry; use libimagstore::iter::get::StoreIdGetIteratorExtension; use failure::Fallible as Result; @@ -76,6 +77,7 @@ impl ImagApplication for ImagEdit { .into_get_iter(rt.store()) .map_inner_ok_or_else(|| err_msg("Did not find one entry")) .inspect(|e| debug!("Editing = {:?}", e)) + .map_report_touched(&rt) .and_then_ok(|mut entry| { if edit_header { entry.edit_header_and_content(&rt) diff --git a/bin/core/imag-grep/src/lib.rs b/bin/core/imag-grep/src/lib.rs index ae75759b..8a04eaf3 100644 --- a/bin/core/imag-grep/src/lib.rs +++ b/bin/core/imag-grep/src/lib.rs @@ -95,6 +95,7 @@ impl ImagApplication for ImagGrep { .and_then_ok(|entry| { if pattern.is_match(entry.get_content()) { debug!("Matched: {}", entry.get_location()); + rt.report_touched(entry.get_location())?; show(&rt, &entry, &pattern, &opts, &mut count) } else { debug!("Not matched: {}", entry.get_location());