summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-todo/src/lib.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-03-07 16:04:33 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-03-08 11:43:24 +0100
commit8527d447ae2047e0d5d54cc70599a895b62a3ee0 (patch)
tree023de5d446d28c6a232308f8604e17a129ee49c7 /bin/domain/imag-todo/src/lib.rs
parent00aa4df88edae1d5eeb3fb365af05f95bd0de3b4 (diff)
downloadimag-8527d447ae2047e0d5d54cc70599a895b62a3ee0.tar.gz
imag-8527d447ae2047e0d5d54cc70599a895b62a3ee0.tar.xz
Diffstat (limited to 'bin/domain/imag-todo/src/lib.rs')
-rw-r--r--bin/domain/imag-todo/src/lib.rs64
1 files changed, 29 insertions, 35 deletions
diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs
index 42f9baeb..db93004d 100644
--- a/bin/domain/imag-todo/src/lib.rs
+++ b/bin/domain/imag-todo/src/lib.rs
@@ -41,7 +41,7 @@ extern crate chrono;
extern crate filters;
extern crate kairos;
#[macro_use] extern crate log;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
extern crate resiter;
extern crate handlebars;
extern crate prettytable;
@@ -69,14 +69,13 @@ extern crate libimaginteraction;
use std::ops::Deref;
use std::io::Write;
-use std::result::Result as RResult;
use std::str::FromStr;
use clap::ArgMatches;
use chrono::NaiveDateTime;
-use failure::Error;
-use failure::Fallible as Result;
-use failure::err_msg;
+use anyhow::Error;
+use anyhow::Result;
+
use clap::App;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
@@ -121,7 +120,7 @@ impl ImagApplication for ImagTodo {
if rt.handle_unknown_subcommand("imag-todo", other, rt.cli())?.success() {
Ok(())
} else {
- Err(err_msg("Failed to handle unknown subcommand"))
+ Err(anyhow!("Failed to handle unknown subcommand"))
}
}
} // end match scmd
@@ -219,11 +218,11 @@ fn create(rt: &Runtime) -> Result<()> {
fn mark(rt: &Runtime) -> Result<()> {
fn mark_todos_as(rt: &Runtime, status: Status) -> 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(|e| rt.report_touched(e.get_location()).map(|_| e))
.and_then_ok(|mut e| e.set_status(status.clone()))
.collect()
@@ -234,8 +233,8 @@ fn mark(rt: &Runtime) -> Result<()> {
Some("done") => mark_todos_as(rt, Status::Done),
Some("deleted") => mark_todos_as(rt, Status::Deleted),
Some("pending") => mark_todos_as(rt, Status::Pending),
- Some(other) => Err(format_err!("Unknown mark type selected: {}", other)),
- None => Err(format_err!("No mark type selected, doing nothing!")),
+ Some(other) => Err(anyhow!("Unknown mark type selected: {}", other)),
+ None => Err(anyhow!("No mark type selected, doing nothing!")),
}
}
@@ -249,19 +248,17 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
details: bool,
}
impl Viewer for TodoViewer {
- fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> RResult<(), libimagentryview::error::Error>
+ fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> Result<()>
where W: Write
{
- use libimagentryview::error::Error as E;
-
trace!("Viewing entry: {}", entry.get_location());
- if !entry.is_todo().map_err(E::from)? {
- return Err(format_err!("Not a Todo: {}", entry.get_location())).map_err(E::from);
+ if !entry.is_todo()? {
+ return Err(anyhow!("Not a Todo: {}", entry.get_location()));
}
- let uuid = entry.get_uuid().map_err(E::from)?;
- let status = entry.get_status().map_err(E::from)?;
+ let uuid = entry.get_uuid()?;
+ let status = entry.get_status()?;
let status = status.as_str();
let first_line = entry.get_content()
.lines()
@@ -272,14 +269,14 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
let r = writeln!(sink, "{uuid} - {status} : {first_line}",
uuid = uuid,
status = status,
- first_line = first_line);
+ first_line = first_line).map_err(Error::from);
trace!("Viewing entry result: {:?}", r);
r
} else {
let sched = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?;
let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?;
let due = util::get_dt_str(entry.get_due(), "No due")?;
- let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string())
+ let priority = entry.get_priority()?.map(|p| p.as_str().to_string())
.unwrap_or_else(|| "No prio".to_string());
let r = writeln!(sink, "{uuid} - {status} - {sched} - {hidden} - {due} - {prio}: {first_line}",
@@ -289,12 +286,11 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
hidden = hidden,
due = due,
prio = priority,
- first_line = first_line);
+ first_line = first_line).map_err(Error::from);
trace!("Viewing entry result: {:?}", r);
r
}
- .map_err(libimagentryview::error::Error::from)
}
}
@@ -343,18 +339,18 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
if rt.ids_from_stdin() {
trace!("Getting IDs from stdin");
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"));
process(&rt, matcher, show_hidden, iter)
} else {
trace!("Getting IDs from store");
let iter = rt.store().get_todos()?
.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"));
process(&rt, matcher, show_hidden, iter)
}
@@ -426,15 +422,13 @@ fn show(rt: &Runtime) -> Result<()> {
};
iter.map(|entry| {
- use libimagentryview::error::Error as E;
-
- let uuid = entry.get_uuid().map_err(E::from)?.to_hyphenated().to_string();
- let status = entry.get_status().map_err(E::from)?;
+ let uuid = entry.get_uuid()?.to_hyphenated().to_string();
+ let status = entry.get_status()?;
let status = status.as_str().to_string();
let sched = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?;
let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?;
let due = util::get_dt_str(entry.get_due(), "No due")?;
- let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string()).unwrap_or_else(|| "No prio".to_string());
+ let priority = entry.get_priority()?.map(|p| p.as_str().to_string()).unwrap_or_else(|| "No prio".to_string());
let text = entry.get_content().to_owned();
@@ -461,11 +455,11 @@ fn show(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"))
.and_then_ok(|e| rt.report_touched(e.get_location()).map(|_| e))
.collect::<Result<Vec<_>>>()?
.into_iter();
@@ -493,13 +487,13 @@ fn get_datetime_arg(scmd: &ArgMatches, argname: &'static str) -> Result<Option<N
match scmd.value_of(argname) {
None => Ok(None),
- Some(v) => match parser::parse(v)? {
+ Some(v) => match parser::parse(v).map_err(|e| Error::from(e.compat()))? {
parser::Parsed::TimeType(TimeType::Moment(moment)) => Ok(Some(moment)),
parser::Parsed::TimeType(other) => {
- Err(format_err!("You did not pass a date, but a {}", other.name()))
+ Err(anyhow!("You did not pass a date, but a {}", other.name()))
},
parser::Parsed::Iterator(_) => {
- Err(format_err!("Argument {} results in a list of dates, but we need a single date.", v))
+ Err(anyhow!("Argument {} results in a list of dates, but we need a single date.", v))
}
}
}
@@ -510,7 +504,7 @@ fn prio_from_str<S: AsRef<str>>(s: S) -> Result<Priority> {
"h" => Ok(Priority::High),
"m" => Ok(Priority::Medium),
"l" => Ok(Priority::Low),
- other => Err(format_err!("Unsupported Priority: '{}'", other)),
+ other => Err(anyhow!("Unsupported Priority: '{}'", other)),
}
}