summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-habit/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-habit/src/lib.rs')
-rw-r--r--bin/domain/imag-habit/src/lib.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/bin/domain/imag-habit/src/lib.rs b/bin/domain/imag-habit/src/lib.rs
index 9fa666e1..c2c2aa75 100644
--- a/bin/domain/imag-habit/src/lib.rs
+++ b/bin/domain/imag-habit/src/lib.rs
@@ -42,7 +42,7 @@ extern crate kairos;
extern crate resiter;
extern crate chrono;
extern crate prettytable;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
extern crate result_inspect;
extern crate libimaghabit;
@@ -57,9 +57,9 @@ use std::io::Write;
use prettytable::Table;
use prettytable::Cell;
use prettytable::Row;
-use failure::Error;
-use failure::Fallible as Result;
-use failure::err_msg;
+use anyhow::Error;
+use anyhow::Result;
+
use resiter::AndThen;
use resiter::FilterMap;
use resiter::Filter;
@@ -87,7 +87,7 @@ mod ui;
pub enum ImagHabit {}
impl ImagApplication for ImagHabit {
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"))? {
"create" => create(&rt),
"delete" => delete(&rt),
"list" => list(&rt),
@@ -100,7 +100,7 @@ impl ImagApplication for ImagHabit {
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"))
}
},
}
@@ -132,16 +132,17 @@ fn create(rt: &Runtime) -> Result<()> {
let comm = scmd.value_of("create-comment").map(String::from).unwrap(); // safe by clap
let date = scmd.value_of("create-date").unwrap(); // safe by clap
- let parsedate = |d, pname| match kairos_parse(d)? {
+ let parsedate = |d, pname| match kairos_parse(d).map_err(|e| Error::from(e.compat()))? {
Parsed::TimeType(tt) => tt.calculate()
+ .map_err(|e| Error::from(e.compat()))
.inspect(|y| debug!("TimeType yielded: '{:?}'", y))?
.get_moment()
.ok_or_else(|| {
- format_err!("Error: '{}' parameter does not yield a point in time", pname)
+ anyhow!("Error: '{}' parameter does not yield a point in time", pname)
})
.map(|p| p.date()),
_ => {
- Err(format_err!("Error: '{}' parameter does not yield a point in time", pname))
+ Err(anyhow!("Error: '{}' parameter does not yield a point in time", pname))
},
};
@@ -177,13 +178,13 @@ fn delete(rt: &Runtime) -> Result<()> {
let yes = scmd.is_present("delete-yes");
let delete_instances = scmd.is_present("delete-instances");
- 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();
rt.store()
.all_habit_templates()?
.and_then_ok(|sid| rt.store().get(sid.clone()).map(|e| e.map(|e| (sid, e)))) // get the FileLockEntry
- .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(|(sid, h)| {
let filter_result = h.habit_name()? == name;
Ok((filter_result, sid, h))
@@ -201,7 +202,7 @@ fn delete(rt: &Runtime) -> Result<()> {
fle.linked_instances()?
.and_then_ok(|instance| {
let instance = rt.store().get(instance.clone())?.ok_or_else(|| {
- format_err!("Failed to find instance: {}", instance)
+ anyhow!("Failed to find instance: {}", instance)
})?;
if instance.get_template_name()? == t_name {
@@ -248,7 +249,7 @@ fn delete(rt: &Runtime) -> Result<()> {
// future flag. If it is true, the check will not be performed and it is assumed that `--future`
// was passed.
fn today(rt: &Runtime, future: bool) -> Result<()> {
- use failure::ResultExt;
+ use anyhow::Context;
let (future, show_done) = {
if !future {
@@ -269,7 +270,7 @@ fn today(rt: &Runtime, future: bool) -> Result<()> {
.store()
.all_habit_templates()?
.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(|h| {
let due = h.next_instance_date()?;
// today or in future
@@ -307,7 +308,7 @@ fn today(rt: &Runtime, future: bool) -> Result<()> {
am.value_of("today-show-next-n")
.map(|x| {
x.parse::<usize>()
- .context(format_err!("Cannot parse String '{}' to integer", x))
+ .context(anyhow!("Cannot parse String '{}' to integer", x))
.map_err(Error::from)
})
}).unwrap_or(Ok(5))?;
@@ -441,7 +442,7 @@ fn list(rt: &Runtime) -> Result<()> {
.all_habit_templates()?
.filter_map_ok(|id| match rt.store().get(id.clone()) {
Ok(Some(h)) => Some(Ok(h)),
- Ok(None) => Some(Err(format_err!("No habit found for {:?}", id))),
+ Ok(None) => Some(Err(anyhow!("No habit found for {:?}", id))),
Err(e) => Some(Err(e)),
})
.and_then_ok(|r| r)
@@ -495,7 +496,7 @@ fn show(rt: &Runtime) -> Result<()> {
rt.store()
.all_habit_templates()?
.into_get_iter(rt.store())
- .map_inner_ok_or_else(|| err_msg("Did not find one habit template"))
+ .map_inner_ok_or_else(|| anyhow!("Did not find one habit template"))
.filter_ok(|h| h.habit_name().map(|n| name == n).unwrap_or(false))
.and_then_ok(|habit| {
let name = habit.habit_name()?;
@@ -518,7 +519,7 @@ fn show(rt: &Runtime) -> Result<()> {
drop(habit);
instances
.into_get_iter(rt.store())
- .map_inner_ok_or_else(|| err_msg("Did not find one habit template"))
+ .map_inner_ok_or_else(|| anyhow!("Did not find one habit template"))
.and_then_ok(|e| {
let mut v = vec![format!("{}", j)];
let mut instances = instance_lister_fn(&rt, &e)?;
@@ -554,7 +555,7 @@ fn done(rt: &Runtime) -> Result<()> {
.store()
.all_habit_templates()?
.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(|h| {
let due = h.next_instance_date()?;
let take = due.map(|d| d <= today || scmd.is_present("allow-future")).unwrap_or(false);