diff options
Diffstat (limited to 'bin/domain/imag-contact/src')
-rw-r--r-- | bin/domain/imag-contact/src/create.rs | 48 | ||||
-rw-r--r-- | bin/domain/imag-contact/src/edit.rs | 12 | ||||
-rw-r--r-- | bin/domain/imag-contact/src/lib.rs | 34 | ||||
-rw-r--r-- | bin/domain/imag-contact/src/ui.rs | 2 | ||||
-rw-r--r-- | bin/domain/imag-contact/src/util.rs | 8 |
5 files changed, 52 insertions, 52 deletions
diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs index 22394f7a..3c8b3f07 100644 --- a/bin/domain/imag-contact/src/create.rs +++ b/bin/domain/imag-contact/src/create.rs @@ -45,10 +45,10 @@ use toml_query::read::TomlValueReadExt; use toml_query::read::Partial; use toml::Value; use uuid::Uuid; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; + +use anyhow::Result; +use anyhow::Context; use libimagcontact::store::ContactStore; use libimagrt::runtime::Runtime; @@ -85,15 +85,15 @@ pub fn create(rt: &Runtime) -> Result<()> { let collection_name = String::from(collection_name); let ref_config = rt // TODO: Re-Deserialize to libimagentryref::reference::Config .config() - .ok_or_else(|| err_msg("Configuration missing, cannot continue!"))? + .ok_or_else(|| anyhow!("Configuration missing, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; // TODO: Refactor the above to libimagutil or libimagrt? let (mut dest, location, uuid) : (Box<dyn Write>, Option<PathBuf>, String) = { if let Some(mut fl) = scmd.value_of("file-location").map(PathBuf::from) { let uuid = if fl.is_file() { - return Err(err_msg("File does exist, cannot create/override")) + return Err(anyhow!("File does exist, cannot create/override")) } else if fl.is_dir() { let uuid = Uuid::new_v4().to_hyphenated().to_string(); fl.push(uuid.clone()); @@ -135,7 +135,7 @@ pub fn create(rt: &Runtime) -> Result<()> { None => fl.file_name() .and_then(|fname| fname.to_str()) .map(String::from) - .ok_or_else(|| err_msg("Cannot calculate UUID for vcard"))?, + .ok_or_else(|| anyhow!("Cannot calculate UUID for vcard"))?, }; (Box::new(file), Some(fl), uuid_string) @@ -147,7 +147,7 @@ pub fn create(rt: &Runtime) -> Result<()> { }; let mut input = rt.stdin().ok_or_else(|| { - err_msg("No input stream. Cannot ask for permission") + anyhow!("No input stream. Cannot ask for permission") })?; let mut output = rt.stdout(); @@ -156,7 +156,7 @@ pub fn create(rt: &Runtime) -> Result<()> { ::libimagentryedit::edit::edit_in_tmpfile(&rt, &mut template)?; if template == TEMPLATE || template.is_empty() { - return Err(err_msg("No (changed) content in tempfile. Not doing anything.")) + return Err(anyhow!("No (changed) content in tempfile. Not doing anything.")) } match ::toml::de::from_str(&template) @@ -265,7 +265,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'nickname.[{}].name' missing", i)) + return Err(anyhow!("Key 'nickname.[{}].name' missing", i)) } }, }; @@ -286,7 +286,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array or String at 'nickname'")) + return Err(anyhow!("Type Error: Expected Array or String at 'nickname'")) } }, None => { @@ -326,7 +326,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'phones.[{}].type' missing", i)) + return Err(anyhow!("Key 'phones.[{}].type' missing", i)) } } }; @@ -338,7 +338,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'phones.[{}].number' missing", i)) + return Err(anyhow!("Key 'phones.[{}].number' missing", i)) } } }; @@ -355,7 +355,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Expected Array at 'phones'.")) + return Err(anyhow!("Expected Array at 'phones'.")) } }, None => { @@ -375,7 +375,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'adresses.[{}].type' missing", i)) + return Err(anyhow!("Key 'adresses.[{}].type' missing", i)) } }, Some(p) => p, @@ -410,7 +410,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array at 'addresses'")) + return Err(anyhow!("Type Error: Expected Array at 'addresses'")) } }, None => { @@ -430,7 +430,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Error: 'email.[{}].type' missing", i)) + return Err(anyhow!("Error: 'email.[{}].type' missing", i)) } }, Some(p) => p, @@ -442,7 +442,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Error: 'email.[{}].addr' missing", i)) + return Err(anyhow!("Error: 'email.[{}].addr' missing", i)) } }, Some(p) => p, @@ -460,7 +460,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array at 'email'")) + return Err(anyhow!("Type Error: Expected Array at 'email'")) } }, None => { @@ -505,7 +505,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec< match *elem { Value::String(ref s) => v.push(s.clone()), _ => { - return Err(format_err!("Type Error: '{}' must be Array<String>", path)) + return Err(anyhow!("Type Error: '{}' must be Array<String>", path)) }, } } @@ -516,7 +516,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec< warn!("Having String, wanting Array<String> ... going to auto-fix"); Ok(Some(vec![s.clone()])) }, - Ok(Some(_)) => Err(format_err!("Type Error: '{}' must be Array<String>", path)), + Ok(Some(_)) => Err(anyhow!("Type Error: '{}' must be Array<String>", path)), Ok(None) => Ok(None), Err(_) => Ok(None), } @@ -526,11 +526,11 @@ fn read_str_from_toml(toml: &Value, path: &'static str, must_be_there: bool) -> match toml.read(path)? { Some(&Value::String(ref s)) => Ok(Some(s.clone())), Some(_) => { - Err(format_err!("Type Error: '{}' must be String", path)) + Err(anyhow!("Type Error: '{}' must be String", path)) }, None => { if must_be_there { - return Err(format_err!("Expected '{}' to be present, but is not.", path)) + return Err(anyhow!("Expected '{}' to be present, but is not.", path)) } Ok(None) }, diff --git a/bin/domain/imag-contact/src/edit.rs b/bin/domain/imag-contact/src/edit.rs index b276da64..34024949 100644 --- a/bin/domain/imag-contact/src/edit.rs +++ b/bin/domain/imag-contact/src/edit.rs @@ -35,8 +35,8 @@ use std::io::Read; use std::io::Write; -use failure::err_msg; -use failure::Fallible as Result; + +use anyhow::Result; use resiter::Filter; use resiter::Map; use resiter::AndThen; @@ -58,12 +58,12 @@ pub fn edit(rt: &Runtime) -> Result<()> { let retry = !scmd.is_present("fail-on-parse-error"); if rt.output_is_pipe() { - return Err(err_msg("Cannot spawn editor if output is a pipe!")) + return Err(anyhow!("Cannot spawn editor if output is a pipe!")) } let mut output = rt.stdout(); let mut input = rt.stdin().ok_or_else(|| { - err_msg("No input stream. Cannot ask for permission.") + anyhow!("No input stream. Cannot ask for permission.") })?; crate::util::find_contact_by_hash(rt, hash)? @@ -92,13 +92,13 @@ fn edit_contact<'a>(rt: &Runtime, contact: &FileLockEntry<'a>, ref_config: &RefC .get_path(ref_config)?; let success = rt.editor()? - .ok_or_else(|| err_msg("I have no editor configured. Cannot continue!"))? + .ok_or_else(|| anyhow!("I have no editor configured. Cannot continue!"))? .arg(&filepath) .status()? .success(); if !success { - return Err(err_msg("Editor failed!")) + return Err(anyhow!("Editor failed!")) } rt.store() diff --git a/bin/domain/imag-contact/src/lib.rs b/bin/domain/imag-contact/src/lib.rs index dcfaeb26..13f17e0f 100644 --- a/bin/domain/imag-contact/src/lib.rs +++ b/bin/domain/imag-contact/src/lib.rs @@ -43,7 +43,7 @@ extern crate handlebars; extern crate walkdir; extern crate uuid; extern crate serde_json; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagcontact; @@ -64,9 +64,9 @@ use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt; use toml_query::read::Partial; use walkdir::WalkDir; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use resiter::AndThen; use resiter::IterInnerOkOrElse; use resiter::Map; @@ -97,7 +97,7 @@ use crate::edit::edit; pub enum ImagContact {} impl ImagApplication for ImagContact { fn run(rt: Runtime) -> Result<()> { - match rt.cli().subcommand_name().ok_or_else(|| err_msg("No subcommand called"))? { + match rt.cli().subcommand_name().ok_or_else(|| anyhow!("No subcommand called"))? { "list" => list(&rt), "import" => import(&rt), "show" => show(&rt), @@ -109,7 +109,7 @@ impl ImagApplication for ImagContact { if rt.handle_unknown_subcommand("imag-contact", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -141,7 +141,7 @@ fn list(rt: &Runtime) -> Result<()> { .store() .all_contacts()? .into_get_iter() - .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")) .and_then_ok(|fle| { rt.report_touched(fle.get_location())?; Ok(fle) @@ -177,14 +177,14 @@ fn import(rt: &Runtime) -> Result<()> { let collection_name = rt.cli().value_of("contact-ref-collection-name").unwrap(); // default by clap let ref_config = rt.config() - .ok_or_else(|| format_err!("No configuration, cannot continue!"))? + .ok_or_else(|| anyhow!("No configuration, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; // TODO: Refactor the above to libimagutil or libimagrt? if !path.exists() { - return Err(format_err!("Path does not exist: {}", path.display())) + return Err(anyhow!("Path does not exist: {}", path.display())) } if path.is_file() { @@ -216,7 +216,7 @@ fn import(rt: &Runtime) -> Result<()> { .collect::<Result<Vec<_>>>() .map(|_| ()) } else { - Err(err_msg("Path is neither directory nor file")) + Err(anyhow!("Path is neither directory nor file")) } } @@ -253,7 +253,7 @@ fn show(rt: &Runtime) -> Result<()> { .map(PathBuf::from) .map(StoreId::new) .into_get_iter(rt.store()) - .map_inner_ok_or_else(|| err_msg("Did not find one entry")); + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")); show_contacts(rt, &show_format, iter) } else { @@ -268,11 +268,11 @@ fn show(rt: &Runtime) -> Result<()> { } } else { let iter = rt.ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(Ok) .into_get_iter(rt.store()) - .map_inner_ok_or_else(|| err_msg("Did not find one entry")); + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")); show_contacts(rt, &show_format, iter) } @@ -294,7 +294,7 @@ fn find(rt: &Runtime) -> Result<()> { .store() .all_contacts()? .into_get_iter() - .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")) .and_then_ok(|entry| { let card = entry.deser()?; @@ -384,9 +384,9 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd: let fmt = match scmd.value_of("format").map(String::from) { Some(s) => Ok(s), None => rt.config() - .ok_or_else(|| err_msg("No configuration file"))? + .ok_or_else(|| anyhow!("No configuration file"))? .read_string(config_value_path)? - .ok_or_else(|| err_msg("Configuration 'contact.list_format' does not exist")), + .ok_or_else(|| anyhow!("Configuration 'contact.list_format' does not exist")), }?; let mut hb = Handlebars::new(); diff --git a/bin/domain/imag-contact/src/ui.rs b/bin/domain/imag-contact/src/ui.rs index 99cd9704..2d5e1240 100644 --- a/bin/domain/imag-contact/src/ui.rs +++ b/bin/domain/imag-contact/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagrt::runtime::IdPathProvider; diff --git a/bin/domain/imag-contact/src/util.rs b/bin/domain/imag-contact/src/util.rs index c3d2c1fb..2125753c 100644 --- a/bin/domain/imag-contact/src/util.rs +++ b/bin/domain/imag-contact/src/util.rs @@ -19,8 +19,8 @@ use std::collections::BTreeMap; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::IterInnerOkOrElse; use resiter::AndThen; @@ -91,12 +91,12 @@ pub fn find_contact_by_hash<'a, H: AsRef<str>>(rt: &'a Runtime, hash: H) Ok(rt.store() .all_contacts()? .into_get_iter() - .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")) .and_then_ok(move |entry| { let deser = entry.deser()?; let id_starts_with_hash = deser.uid() - .ok_or_else(|| err_msg("Could not get StoreId from Store::all_contacts(). This is a BUG!"))? + .ok_or_else(|| anyhow!("Could not get StoreId from Store::all_contacts(). This is a BUG!"))? .starts_with(hash.as_ref()); if id_starts_with_hash { |