summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-diary/src
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-diary/src')
-rw-r--r--bin/domain/imag-diary/src/create.rs26
-rw-r--r--bin/domain/imag-diary/src/delete.rs10
-rw-r--r--bin/domain/imag-diary/src/lib.rs12
-rw-r--r--bin/domain/imag-diary/src/list.rs8
-rw-r--r--bin/domain/imag-diary/src/util.rs11
-rw-r--r--bin/domain/imag-diary/src/view.rs10
6 files changed, 37 insertions, 40 deletions
diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs
index 43b25d6a..8dccbee8 100644
--- a/bin/domain/imag-diary/src/create.rs
+++ b/bin/domain/imag-diary/src/create.rs
@@ -21,10 +21,10 @@ use clap::ArgMatches;
use chrono::NaiveDateTime;
use chrono::Local;
use chrono::Timelike;
-use failure::Error;
-use failure::ResultExt;
-use failure::err_msg;
-use failure::Fallible as Result;
+use anyhow::Error;
+use anyhow::Context;
+
+use anyhow::Result;
use option_inspect::*;
use libimagdiary::diary::Diary;
@@ -39,7 +39,7 @@ use crate::util::Timed;
pub fn create(rt: &Runtime) -> Result<()> {
let diaryname = get_diary_name(rt)
- .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?;
+ .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?;
let mut entry = create_entry(rt.store(), &diaryname, rt)?;
rt.report_touched(entry.get_location())?;
@@ -50,7 +50,7 @@ pub fn create(rt: &Runtime) -> Result<()> {
Ok(())
} else {
debug!("Editing new diary entry");
- entry.edit_content(rt).context(err_msg("Diary edit error")).map_err(Error::from)
+ entry.edit_content(rt).context(anyhow!("Diary edit error")).map_err(Error::from)
}
}
@@ -67,7 +67,7 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> Result<F
if let Some(timed) = timed {
let time = create_id_from_clispec(&create, timed)?;
diary.new_entry_at(&diaryname, &time)
- .context(err_msg("Store write error"))
+ .context(anyhow!("Store write error"))
.map_err(Error::from)
} else {
debug!("Creating non-timed entry");
@@ -107,7 +107,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
.map(|s| {
FromStr::from_str(s)
.map_err(Error::from)
- .context(format_err!("Could not parse minute: '{}'", s))
+ .context(anyhow!("Could not parse minute: '{}'", s))
.map_err(Error::from)
})
.transpose()?
@@ -115,7 +115,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
ndt.with_minute(min)
.ok_or_else(|| {
- format_err!("Cannot set {} as minute, would yield invalid time!", min)
+ anyhow!("Cannot set {} as minute, would yield invalid time!", min)
})
.map(|ndt| ndt.with_second(0).unwrap()) // safe because second = 0 is safe
},
@@ -127,7 +127,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
.map(|s| {
FromStr::from_str(s)
.map_err(Error::from)
- .context(format_err!("Could not parse minute: '{}'", s))
+ .context(anyhow!("Could not parse minute: '{}'", s))
.map_err(Error::from)
})
.transpose()?
@@ -139,7 +139,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
.map(|s| {
FromStr::from_str(s)
.map_err(Error::from)
- .context(format_err!("Could not parse second: '{}'", s))
+ .context(anyhow!("Could not parse second: '{}'", s))
.map_err(Error::from)
})
.transpose()?
@@ -147,11 +147,11 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
ndt.with_minute(min)
.ok_or_else(|| {
- format_err!("Cannot set {} as minute, would yield invalid time!", min)
+ anyhow!("Cannot set {} as minute, would yield invalid time!", min)
})?
.with_second(sec)
.ok_or_else(|| {
- format_err!("Cannot set {} as second, would yield invalid time!", sec)
+ anyhow!("Cannot set {} as second, would yield invalid time!", sec)
})
},
}
diff --git a/bin/domain/imag-diary/src/delete.rs b/bin/domain/imag-diary/src/delete.rs
index 0f313989..d80ac6d5 100644
--- a/bin/domain/imag-diary/src/delete.rs
+++ b/bin/domain/imag-diary/src/delete.rs
@@ -18,8 +18,8 @@
//
use chrono::naive::NaiveDateTime as NDT;
-use failure::Fallible as Result;
-use failure::err_msg;
+use anyhow::Result;
+
use libimagdiary::diaryid::DiaryId;
use libimagrt::runtime::Runtime;
@@ -33,7 +33,7 @@ pub fn delete(rt: &Runtime) -> Result<()> {
use libimaginteraction::ask::ask_bool;
let diaryname = get_diary_name(rt)
- .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?;
+ .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?;
let to_del_location = rt
.cli()
@@ -43,13 +43,13 @@ pub fn delete(rt: &Runtime) -> Result<()> {
.map(|dt| { debug!("DateTime = {:?}", dt); dt })
.and_then(DateTime::parse)
.map(Into::into)
- .ok_or_else(|| err_msg("Not deleting entries: missing date/time specification"))
+ .ok_or_else(|| anyhow!("Not deleting entries: missing date/time specification"))
.and_then(|dt: NDT| DiaryId::from_datetime(diaryname.clone(), dt).into_storeid())
.and_then(|id| rt.store().retrieve(id))?
.get_location()
.clone();
- 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();
if !ask_bool(&format!("Deleting {:?}", to_del_location), Some(true), &mut input, &mut output)? {
diff --git a/bin/domain/imag-diary/src/lib.rs b/bin/domain/imag-diary/src/lib.rs
index 72984106..b781fdc3 100644
--- a/bin/domain/imag-diary/src/lib.rs
+++ b/bin/domain/imag-diary/src/lib.rs
@@ -35,7 +35,7 @@
)]
#[macro_use] extern crate log;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
extern crate resiter;
extern crate clap;
extern crate chrono;
@@ -61,9 +61,9 @@ use libimagrt::application::ImagApplication;
use itertools::Itertools;
use clap::App;
-use failure::Fallible as Result;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Result;
+
+use anyhow::Error;
mod create;
mod delete;
@@ -84,7 +84,7 @@ use crate::view::view;
pub enum ImagDiary {}
impl ImagApplication for ImagDiary {
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"))? {
"diaries" => diaries(&rt),
"create" => create(&rt),
"delete" => delete(&rt),
@@ -95,7 +95,7 @@ impl ImagApplication for ImagDiary {
if rt.handle_unknown_subcommand("imag-diary", other, rt.cli())?.success() {
Ok(())
} else {
- Err(err_msg("Failed to handle unknown subcommand"))
+ Err(anyhow!("Failed to handle unknown subcommand"))
}
},
}
diff --git a/bin/domain/imag-diary/src/list.rs b/bin/domain/imag-diary/src/list.rs
index 9b4a6b7e..d047d83b 100644
--- a/bin/domain/imag-diary/src/list.rs
+++ b/bin/domain/imag-diary/src/list.rs
@@ -19,9 +19,9 @@
use std::io::Write;
-use failure::Fallible as Result;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Result;
+
+use anyhow::Error;
use resiter::AndThen;
use libimagdiary::diary::Diary;
@@ -34,7 +34,7 @@ use crate::util::get_diary_name;
pub fn list(rt: &Runtime) -> Result<()> {
let diaryname = get_diary_name(rt)
- .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?;
+ .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?;
let mut ids = Diary::entries(rt.store(), &diaryname)?
.and_then_ok(|id| DiaryId::from_storeid(&id))
diff --git a/bin/domain/imag-diary/src/util.rs b/bin/domain/imag-diary/src/util.rs
index 4a78adec..ce453358 100644
--- a/bin/domain/imag-diary/src/util.rs
+++ b/bin/domain/imag-diary/src/util.rs
@@ -18,13 +18,11 @@
//
use libimagrt::runtime::Runtime;
-use libimagerror::errors::ErrorMsg as EM;
use toml::Value;
use toml_query::read::TomlValueReadExt;
-use failure::Error;
-use failure::Fallible as Result;
-use failure::ResultExt;
+use anyhow::Error;
+use anyhow::Result;
pub fn get_diary_name(rt: &Runtime) -> Option<String> {
use libimagdiary::config::get_default_diary_name;
@@ -61,7 +59,6 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T
Some(cfg) => {
let v = cfg
.read(&format!("diary.diaries.{}.timed", diary_name))
- .context(EM::IO)
.map_err(Error::from);
match v {
@@ -69,7 +66,7 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T
Ok(Some(_)) => {
let s = format!("Type error at 'diary.diaryies.{}.timed': should be either 'd'/'daily', 'h'/'hourly', 'm'/'minutely' or 's'/'secondly'", diary_name);
- Err(format_err!("{}", s))
+ Err(anyhow!("{}", s))
},
Ok(None) => Ok(None),
@@ -89,6 +86,6 @@ pub fn parse_timed_string(s: &str, diary_name: &str) -> Result<Timed> {
} else if s == "s" || s == "secondly" {
Ok(Timed::Secondly)
} else {
- Err(format_err!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s))
+ Err(anyhow!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s))
}
}
diff --git a/bin/domain/imag-diary/src/view.rs b/bin/domain/imag-diary/src/view.rs
index 76e10b25..1eb45c50 100644
--- a/bin/domain/imag-diary/src/view.rs
+++ b/bin/domain/imag-diary/src/view.rs
@@ -17,9 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-use failure::Fallible as Result;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Result;
+
+use anyhow::Error;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
@@ -32,7 +32,7 @@ use libimagentryview::viewer::Viewer;
use crate::util::get_diary_name;
pub fn view(rt: &Runtime) -> Result<()> {
- let diaryname = get_diary_name(rt).ok_or_else(|| err_msg("No diary name"))?;
+ let diaryname = get_diary_name(rt).ok_or_else(|| anyhow!("No diary name"))?;
let hdr = rt.cli().subcommand_matches("view").unwrap().is_present("show-header");
let out = rt.stdout();
let mut outlock = out.lock();
@@ -40,7 +40,7 @@ pub fn view(rt: &Runtime) -> Result<()> {
Diary::entries(rt.store(), &diaryname)?
.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(|e| viewer.view_entry(&e, &mut outlock).map_err(Error::from).map(|_| e))
.and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from))
.collect()