diff options
Diffstat (limited to 'bin/domain/imag-contact/src/lib.rs')
-rw-r--r-- | bin/domain/imag-contact/src/lib.rs | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/bin/domain/imag-contact/src/lib.rs b/bin/domain/imag-contact/src/lib.rs index 873c822a..5b7a808c 100644 --- a/bin/domain/imag-contact/src/lib.rs +++ b/bin/domain/imag-contact/src/lib.rs @@ -74,6 +74,9 @@ use resiter::Filter; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; +use libimagstore::store::FileLockEntry; +use libimagstore::storeid::StoreId; +use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimagcontact::store::ContactStore; use libimagcontact::contact::Contact; use libimagcontact::deser::DeserVcard; @@ -217,28 +220,64 @@ fn import(rt: &Runtime) -> Result<()> { } } -fn show(rt: &Runtime) -> Result<()> { - let scmd = rt.cli().subcommand_matches("show").unwrap(); - let hash = scmd.value_of("hash").map(String::from).unwrap(); // safed by clap - let show_format = get_contact_print_format("contact.show_format", rt, &scmd)?; +fn show_contacts<'a, I>(rt: &Runtime, show_format: &Handlebars, iter: I) -> Result<()> + where I: Iterator<Item = Result<FileLockEntry<'a>>> +{ let out = rt.stdout(); let mut outlock = out.lock(); - util::find_contact_by_hash(rt, hash)? - .filter_ok(|tpl| tpl.0) - .map_ok(|tpl| tpl.1) - .enumerate() + iter.enumerate() .map(|(i, elem)| { - let elem = elem?.deser()?; - let data = build_data_object_for_handlebars(i, &elem); + elem.and_then(|e| { + let elem = e.deser()?; + let data = build_data_object_for_handlebars(i, &elem); - let s = show_format.render("format", &data)?; - writeln!(outlock, "{}", s).map_err(Error::from) + let s = show_format.render("format", &data)?; + writeln!(outlock, "{}", s).map_err(Error::from) + }) }) .collect::<Result<Vec<_>>>() .map(|_| ()) } +fn show(rt: &Runtime) -> Result<()> { + let scmd = rt.cli().subcommand_matches("show").unwrap(); + let show_format = get_contact_print_format("contact.show_format", rt, &scmd)?; + + if let Some(ids) = scmd.values_of("ids") { + let ids = ids.collect::<Vec<_>>(); + if ids.iter().all(|id| id.starts_with("contact")) { + let iter = ids + .into_iter() + .map(String::from) + .map(PathBuf::from) + .map(StoreId::new) + .into_get_iter(rt.store()) + .map_inner_ok_or_else(|| err_msg("Did not find one entry")); + + show_contacts(rt, &show_format, iter) + } else { + ids + .into_iter() + .map(|hash| util::find_contact_by_hash(rt, hash)) + .collect::<Result<Vec<_>>>()? + .into_iter() + .map(|iter| show_contacts(rt, &show_format, iter.filter_ok(|tpl| tpl.0).map_ok(|tpl| tpl.1))) + .collect::<Result<Vec<_>>>() + .map(|_| ()) + } + } else { + let iter = rt.ids::<crate::ui::PathProvider>()? + .ok_or_else(|| err_msg("No ids supplied"))? + .into_iter() + .map(Ok) + .into_get_iter(rt.store()) + .map_inner_ok_or_else(|| err_msg("Did not find one entry")); + + show_contacts(rt, &show_format, iter) + } +} + fn find(rt: &Runtime) -> Result<()> { let scmd = rt.cli().subcommand_matches("find").unwrap(); let grepstring = scmd |