diff options
Diffstat (limited to 'bin/domain/imag-todo/src/import.rs')
-rw-r--r-- | bin/domain/imag-todo/src/import.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/bin/domain/imag-todo/src/import.rs b/bin/domain/imag-todo/src/import.rs index 8d5b6e81..810faa55 100644 --- a/bin/domain/imag-todo/src/import.rs +++ b/bin/domain/imag-todo/src/import.rs @@ -17,8 +17,8 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; +use anyhow::Error; use libimagrt::runtime::Runtime; @@ -26,14 +26,14 @@ pub fn import(rt: &Runtime) -> Result<()> { let scmd = rt.cli().subcommand().1.unwrap(); match scmd.subcommand_name() { - None => Err(err_msg("No subcommand called")), + None => Err(anyhow!("No subcommand called")), Some("taskwarrior") => import_taskwarrior(rt), Some(other) => { debug!("Unknown command"); if rt.handle_unknown_subcommand("imag-todo-import", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -43,7 +43,7 @@ pub fn import(rt: &Runtime) -> Result<()> { fn import_taskwarrior(rt: &Runtime) -> Result<()> { #[cfg(not(feature = "import-taskwarrior"))] { - Err(err_msg("Binary not compiled with taskwarrior import functionality")) + Err(anyhow!("Binary not compiled with taskwarrior import functionality")) } #[cfg(feature = "import-taskwarrior")] @@ -65,7 +65,7 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { let store = rt.store(); if !rt.input_is_pipe() { - return Err(err_msg("Cannot get stdin for importing tasks")) + return Err(anyhow!("Cannot get stdin for importing tasks")) } let stdin = ::std::io::stdin(); @@ -86,7 +86,8 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { } }; - taskwarrior_import(stdin)? + taskwarrior_import(stdin) + .map_err(|e| Error::from(e.compat()))? .into_iter() .map(|task| { let mut todo = store @@ -103,12 +104,12 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { todo.set_content(task.description().clone()); if let Some(tags) = task.tags() { - tags.iter().map(|tag| { + tags.iter().map(String::from).map(|tag| { if libimagentrytag::tag::is_tag_str(&tag).is_err() { warn!("Not a valid tag, ignoring: {}", tag); Ok(()) } else { - todo.add_tag(tag.clone()) + todo.add_tag(tag) } }).collect::<Result<Vec<_>>>()?; } @@ -142,14 +143,14 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { .filter(|(_, list)| !list.is_empty()) .map(|(key, list)| { let mut entry = store.get_todo_by_uuid(key)?.ok_or_else(|| { - format_err!("Cannot find todo by UUID: {}", key) + anyhow!("Cannot find todo by UUID: {}", key) })?; list.iter() .map(move |element| { store.get_todo_by_uuid(element)? .ok_or_else(|| { - format_err!("Cannot find todo by UUID: {}", key) + anyhow!("Cannot find todo by UUID: {}", key) }) .and_then(|mut target| entry.add_link(&mut target)) }) |