Fix imag-contact for new error interface
This commit is contained in:
parent
86abfb88a4
commit
ee23f432de
2 changed files with 30 additions and 9 deletions
|
@ -18,6 +18,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::error::Error;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
|
@ -30,10 +31,10 @@ use toml_query::read::TomlValueReadExt;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use libimagcontact::error::ContactError as CE;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::trace_error_exit;
|
|
||||||
use libimagutil::warn_result::WarnResult;
|
use libimagutil::warn_result::WarnResult;
|
||||||
use libimagentryref::refstore::RefStore;
|
use libimagentryref::refstore::RefStore;
|
||||||
use libimagentryref::flags::RefFlags;
|
use libimagentryref::flags::RefFlags;
|
||||||
|
@ -89,6 +90,8 @@ pub fn create(rt: &Runtime) {
|
||||||
.create_new(true)
|
.create_new(true)
|
||||||
.open(fl.clone())
|
.open(fl.clone())
|
||||||
.map_warn_err_str("Cannot create/open destination File. Stopping.")
|
.map_warn_err_str("Cannot create/open destination File. Stopping.")
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(CE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
(Box::new(file), Some(fl))
|
(Box::new(file), Some(fl))
|
||||||
|
@ -107,7 +110,11 @@ pub fn create(rt: &Runtime) {
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
match ::toml::de::from_str(&template).map(parse_toml_into_vcard) {
|
match ::toml::de::from_str(&template)
|
||||||
|
.map(parse_toml_into_vcard)
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(CE::from)
|
||||||
|
{
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Error parsing template");
|
error!("Error parsing template");
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
|
@ -125,10 +132,10 @@ pub fn create(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let vcard_string = write_component(&vcard);
|
let vcard_string = write_component(&vcard);
|
||||||
if let Err(e) = dest.write_all(&vcard_string.as_bytes()) {
|
let _ = dest
|
||||||
warn!("Error while writing out vcard content");
|
.write_all(&vcard_string.as_bytes())
|
||||||
trace_error_exit(&e, 1);
|
.map_err(CE::from)
|
||||||
}
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ extern crate libimagentryedit;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
use handlebars::Handlebars;
|
use handlebars::Handlebars;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
@ -133,6 +134,8 @@ fn list(rt: &Runtime) {
|
||||||
let data = build_data_object_for_handlebars(i, hash, &vcard);
|
let data = build_data_object_for_handlebars(i, hash, &vcard);
|
||||||
|
|
||||||
let s = list_format.render("format", &data)
|
let s = list_format.render("format", &data)
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(CE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
})
|
})
|
||||||
|
@ -155,7 +158,10 @@ fn import(rt: &Runtime) {
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
} else if path.is_dir() {
|
} else if path.is_dir() {
|
||||||
for entry in WalkDir::new(path).min_depth(1).into_iter() {
|
for entry in WalkDir::new(path).min_depth(1).into_iter() {
|
||||||
let entry = entry.map_err_trace_exit_unwrap(1);
|
let entry = entry
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(CE::from)
|
||||||
|
.map_err_trace_exit_unwrap(1);
|
||||||
if entry.file_type().is_file() {
|
if entry.file_type().is_file() {
|
||||||
let pb = PathBuf::from(entry.path());
|
let pb = PathBuf::from(entry.path());
|
||||||
let _ = rt
|
let _ = rt
|
||||||
|
@ -194,7 +200,11 @@ fn show(rt: &Runtime) {
|
||||||
let show_format = get_contact_print_format("contact.show_format", rt, &scmd);
|
let show_format = get_contact_print_format("contact.show_format", rt, &scmd);
|
||||||
let data = build_data_object_for_handlebars(0, hash, &vcard);
|
let data = build_data_object_for_handlebars(0, hash, &vcard);
|
||||||
|
|
||||||
let s = show_format.render("format", &data).map_err_trace_exit_unwrap(1);
|
let s = show_format
|
||||||
|
.render("format", &data)
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(CE::from)
|
||||||
|
.map_err_trace_exit_unwrap(1);
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +223,11 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd:
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut hb = Handlebars::new();
|
let mut hb = Handlebars::new();
|
||||||
let _ = hb.register_template_string("format", fmt).map_err_trace_exit_unwrap(1);
|
let _ = hb
|
||||||
|
.register_template_string("format", fmt)
|
||||||
|
.map_err(|e| format!("{}", e.description()))
|
||||||
|
.map_err(CE::from)
|
||||||
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
hb.register_escape_fn(::handlebars::no_escape);
|
hb.register_escape_fn(::handlebars::no_escape);
|
||||||
::libimaginteraction::format::register_all_color_helpers(&mut hb);
|
::libimaginteraction::format::register_all_color_helpers(&mut hb);
|
||||||
|
|
Loading…
Reference in a new issue