diff options
Diffstat (limited to 'bin/domain/imag-bookmark/src')
-rw-r--r-- | bin/domain/imag-bookmark/src/lib.rs | 38 | ||||
-rw-r--r-- | bin/domain/imag-bookmark/src/ui.rs | 6 |
2 files changed, 22 insertions, 22 deletions
diff --git a/bin/domain/imag-bookmark/src/lib.rs b/bin/domain/imag-bookmark/src/lib.rs index 51259481..ad36c80f 100644 --- a/bin/domain/imag-bookmark/src/lib.rs +++ b/bin/domain/imag-bookmark/src/lib.rs @@ -40,7 +40,7 @@ extern crate toml; extern crate url; extern crate uuid; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate handlebars; extern crate rayon; @@ -56,9 +56,9 @@ use std::io::Write; use std::collections::BTreeMap; use std::process::Command; -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 clap::App; @@ -86,7 +86,7 @@ mod ui; pub enum ImagBookmark {} impl ImagApplication for ImagBookmark { 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"))? { "add" => add(&rt), "open" => open(&rt), "list" => list(&rt), @@ -97,7 +97,7 @@ impl ImagApplication for ImagBookmark { if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -139,12 +139,12 @@ fn open(rt: &Runtime) -> Result<()> { let open_command = rt.config() .map(|value| { value.read("bookmark.open")? - .ok_or_else(|| err_msg("Configuration missing: 'bookmark.open'"))? + .ok_or_else(|| anyhow!("Configuration missing: 'bookmark.open'"))? .as_str() - .ok_or_else(|| err_msg("Open command should be a string")) + .ok_or_else(|| anyhow!("Open command should be a string")) }) .or_else(|| Ok(scmd.value_of("opencmd")).transpose()) - .unwrap_or_else(|| Err(err_msg("No open command available in config or on commandline")))?; + .unwrap_or_else(|| Err(anyhow!("No open command available in config or on commandline")))?; let hb = { let mut hb = Handlebars::new(); @@ -153,11 +153,11 @@ fn open(rt: &Runtime) -> Result<()> { }; 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")); if scmd.is_present("openparallel") { let links = iter @@ -195,11 +195,11 @@ fn list(rt: &Runtime) -> Result<()> { rt.store() .all_bookmarks()? .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| { if entry.is_bookmark()? { let url = entry.get_url()? - .ok_or_else(|| format_err!("Failed to retrieve URL for {}", entry.get_location()))?; + .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", entry.get_location()))?; if !rt.output_is_pipe() { writeln!(rt.stdout(), "{}", url)?; } @@ -214,11 +214,11 @@ fn list(rt: &Runtime) -> Result<()> { fn remove(rt: &Runtime) -> Result<()> { 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")) .and_then_ok(|fle| { rt.report_touched(fle.get_location()) .map_err(Error::from) @@ -239,12 +239,12 @@ fn find(rt: &Runtime) -> Result<()> { .all_bookmarks()? .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| { if fle.is_bookmark()? { let url = fle .get_url()? - .ok_or_else(|| format_err!("Failed to retrieve URL for {}", fle.get_location()))?; + .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", fle.get_location()))?; if url.as_str().contains(substr) { if !rt.output_is_pipe() { writeln!(rt.stdout(), "{}", url)?; @@ -262,7 +262,7 @@ fn find(rt: &Runtime) -> Result<()> { fn calculate_command_data<'a>(hb: &Handlebars, entry: &FileLockEntry<'a>, open_command: &str) -> Result<Vec<String>> { let url = entry.get_url()? - .ok_or_else(|| format_err!("Failed to retrieve URL for {}", entry.get_location()))? + .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", entry.get_location()))? .into_string(); let data = { @@ -277,7 +277,7 @@ fn calculate_command_data<'a>(hb: &Handlebars, entry: &FileLockEntry<'a>, open_c .collect::<Vec<String>>(); if command_rendered.len() > 2 { - return Err(format_err!("Command seems not to include URL: '{}'", open_command)); + return Err(anyhow!("Command seems not to include URL: '{}'", open_command)); } Ok(command_rendered.into_iter().map(String::from).collect()) diff --git a/bin/domain/imag-bookmark/src/ui.rs b/bin/domain/imag-bookmark/src/ui.rs index c7c1a0e4..e4645486 100644 --- a/bin/domain/imag-bookmark/src/ui.rs +++ b/bin/domain/imag-bookmark/src/ui.rs @@ -19,7 +19,7 @@ use std::path::PathBuf; -use failure::Fallible as Result; +use anyhow::Result; use clap::{Arg, ArgMatches, App, SubCommand}; use libimagutil::cli_validators::*; @@ -118,7 +118,7 @@ pub struct PathProvider; impl IdPathProvider for PathProvider { fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> { fn no_ids_error() -> Result<Option<Vec<StoreId>>> { - Err(format_err!("Command does not get IDs as input")) + Err(anyhow!("Command does not get IDs as input")) } fn get_id_paths(field: &str, subm: &ArgMatches) -> Result<Option<Vec<StoreId>>> { @@ -137,7 +137,7 @@ impl IdPathProvider for PathProvider { ("remove", Some(subm)) => get_id_paths("ids", subm), ("list", Some(subm)) => get_id_paths("ids", subm), ("find", Some(subm)) => get_id_paths("ids", subm), - (other, _) => Err(format_err!("Not a known command: {}", other)), + (other, _) => Err(anyhow!("Not a known command: {}", other)), } } } |