summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-04-09 19:40:13 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-04-22 16:50:07 +0200
commit9945cb38b7ba068531f0619343f704c3f63e7e22 (patch)
tree999bd9076096d298eef64e70d03a4704392d29c8
parent26664a5aec93d22ff83ae153373cdce997744438 (diff)
downloadimag-9945cb38b7ba068531f0619343f704c3f63e7e22.tar.gz
imag-9945cb38b7ba068531f0619343f704c3f63e7e22.tar.xz
-rw-r--r--bin/domain/imag-contact/src/main.rs28
-rw-r--r--bin/domain/imag-contact/src/util.rs40
2 files changed, 42 insertions, 26 deletions
diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs
index bc950fa1..bd429bd5 100644
--- a/bin/domain/imag-contact/src/main.rs
+++ b/bin/domain/imag-contact/src/main.rs
@@ -217,34 +217,10 @@ fn show(rt: &Runtime) {
let out = rt.stdout();
let mut outlock = out.lock();
- rt.store()
- .all_contacts()
- .map_err_trace_exit_unwrap()
- .into_get_iter()
- .trace_unwrap_exit()
- .map(|o| o.unwrap_or_else(|| {
- error!("Failed to get entry");
- exit(1)
- }))
- .filter_map(|entry| {
- let deser = entry.deser().map_err_trace_exit_unwrap();
-
- if deser.uid()
- .ok_or_else(|| {
- error!("Could not get StoreId from Store::all_contacts(). This is a BUG!");
- ::std::process::exit(1)
- })
- .unwrap() // exited above
- .starts_with(&hash)
- {
- let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
- Some(deser)
- } else {
- None
- }
- })
+ util::find_contact_by_hash(rt, hash)
.enumerate()
.for_each(|(i, elem)| {
+ let elem = elem.deser().map_err_trace_exit_unwrap();
let data = build_data_object_for_handlebars(i, &elem);
let s = show_format
diff --git a/bin/domain/imag-contact/src/util.rs b/bin/domain/imag-contact/src/util.rs
index ccd13ed6..0ed8be05 100644
--- a/bin/domain/imag-contact/src/util.rs
+++ b/bin/domain/imag-contact/src/util.rs
@@ -18,8 +18,17 @@
//
use std::collections::BTreeMap;
+use std::process::exit;
use libimagcontact::deser::DeserVcard;
+use libimagcontact::store::ContactStore;
+use libimagcontact::contact::Contact;
+use libimagerror::exit::ExitUnwrap;
+use libimagerror::iter::TraceIterator;
+use libimagerror::trace::MapErrTrace;
+use libimagrt::runtime::Runtime;
+use libimagstore::store::FileLockEntry;
+
pub fn build_data_object_for_handlebars<'a>(i: usize, vcard: &DeserVcard) -> BTreeMap<&'static str, String> {
let mut data = BTreeMap::new();
@@ -75,3 +84,34 @@ pub fn build_data_object_for_handlebars<'a>(i: usize, vcard: &DeserVcard) -> BTr
data
}
+pub fn find_contact_by_hash<'a, H: AsRef<str>>(rt: &'a Runtime, hash: H)
+ -> impl Iterator<Item = FileLockEntry<'a>>
+{
+ rt.store()
+ .all_contacts()
+ .map_err_trace_exit_unwrap()
+ .into_get_iter()
+ .trace_unwrap_exit()
+ .map(|o| o.unwrap_or_else(|| {
+ error!("Failed to get entry");
+ exit(1)
+ }))
+ .filter_map(move |entry| {
+ let deser = entry.deser().map_err_trace_exit_unwrap();
+
+ if deser.uid()
+ .ok_or_else(|| {
+ error!("Could not get StoreId from Store::all_contacts(). This is a BUG!");
+ ::std::process::exit(1)
+ })
+ .unwrap() // exited above
+ .starts_with(hash.as_ref())
+ {
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
+ Some(entry)
+ } else {
+ None
+ }
+ })
+}
+