summaryrefslogtreecommitdiffstats
path: root/bin/core/imag-category
diff options
context:
space:
mode:
Diffstat (limited to 'bin/core/imag-category')
-rw-r--r--bin/core/imag-category/Cargo.toml2
-rw-r--r--bin/core/imag-category/src/lib.rs24
-rw-r--r--bin/core/imag-category/src/ui.rs6
3 files changed, 16 insertions, 16 deletions
diff --git a/bin/core/imag-category/Cargo.toml b/bin/core/imag-category/Cargo.toml
index 5fb0c0a0..6f75f487 100644
--- a/bin/core/imag-category/Cargo.toml
+++ b/bin/core/imag-category/Cargo.toml
@@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
-failure = "0.1.5"
+anyhow = "1"
resiter = "0.4.0"
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
diff --git a/bin/core/imag-category/src/lib.rs b/bin/core/imag-category/src/lib.rs
index c1c2ed73..d6eb18ef 100644
--- a/bin/core/imag-category/src/lib.rs
+++ b/bin/core/imag-category/src/lib.rs
@@ -38,7 +38,7 @@ extern crate clap;
#[macro_use]
extern crate log;
#[macro_use]
-extern crate failure;
+extern crate anyhow;
extern crate resiter;
extern crate libimagentrycategory;
@@ -47,7 +47,7 @@ extern crate libimagrt;
extern crate libimagstore;
extern crate libimaginteraction;
-use failure::Fallible as Result;
+use anyhow::Result;
use resiter::Map;
use clap::App;
@@ -59,8 +59,8 @@ mod ui;
use std::io::Write;
-use failure::err_msg;
-use failure::Error;
+
+use anyhow::Error;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
@@ -76,7 +76,7 @@ use libimagentrycategory::category::Category;
pub enum ImagCategory {}
impl ImagApplication for ImagCategory {
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"))? {
"set" => set(&rt),
"get" => get(&rt),
"list-category" => list_category(&rt),
@@ -88,7 +88,7 @@ impl ImagApplication for ImagCategory {
if rt.handle_unknown_subcommand("imag-category", other, rt.cli())?.success() {
Ok(())
} else {
- Err(err_msg("Failed to handle unknown subcommand"))
+ Err(anyhow!("Failed to handle unknown subcommand"))
}
},
}
@@ -116,11 +116,11 @@ fn set(rt: &Runtime) -> Result<()> {
let scmd = rt.cli().subcommand_matches("set").unwrap(); // safed by main()
let name = scmd.value_of("set-name").map(String::from).unwrap(); // safed by clap
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(|mut e| e.set_category_checked(rt.store(), &name).map(|_| e))
.map_report_touched(&rt)
.map_ok(|_| ())
@@ -131,11 +131,11 @@ fn get(rt: &Runtime) -> Result<()> {
let out = rt.stdout();
let mut outlock = out.lock();
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"))
.map_report_touched(&rt)
.and_then_ok(|e| e.get_category())
.and_then_ok(|n| writeln!(outlock, "{}", n).map_err(Error::from))
@@ -156,7 +156,7 @@ fn list_category(rt: &Runtime) -> Result<()> {
.map(|entry| writeln!(outlock, "{}", entry?.get_location()).map_err(Error::from))
.collect()
} else {
- Err(format_err!("No category named '{}'", name))
+ Err(anyhow!("No category named '{}'", name))
}
}
@@ -175,7 +175,7 @@ fn delete_category(rt: &Runtime) -> Result<()> {
let name = scmd.value_of("delete-category-name").map(String::from).unwrap(); // safed by clap
let ques = format!("Do you really want to delete category '{}' and remove links to all categorized enties?", name);
- let mut input = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?;
+ let mut input = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?;
let mut output = rt.stdout();
let answer = ask_bool(&ques, Some(false), &mut input, &mut output)?;
diff --git a/bin/core/imag-category/src/ui.rs b/bin/core/imag-category/src/ui.rs
index 6f80539c..a5810c80 100644
--- a/bin/core/imag-category/src/ui.rs
+++ b/bin/core/imag-category/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 libimagstore::storeid::IntoStoreId;
@@ -105,7 +105,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>>> {
@@ -125,7 +125,7 @@ impl IdPathProvider for PathProvider {
("list-category", _) => no_ids_error(),
("set", Some(subm)) => get_id_paths("set-ids", subm),
("get", Some(subm)) => get_id_paths("get-ids", subm),
- (other, _) => Err(format_err!("Not a known command: {}", other)),
+ (other, _) => Err(anyhow!("Not a known command: {}", other)),
}
}
}