diff options
Diffstat (limited to 'src/tw.rs')
-rw-r--r-- | src/tw.rs | 31 |
1 files changed, 14 insertions, 17 deletions
@@ -8,20 +8,18 @@ //! in your path. This will always call task and never interact with your `.task` directory itself. //! (This is in accordance with the taskwarrior api guide lines.) -use crate::error::ErrorKind as EK; +use crate::error::Error; use crate::import::import; use crate::task::Task; use std::io::Write; use std::iter::once; use std::process::{Child, Command, Stdio}; -use failure::Fallible as Result; -use failure::ResultExt; use serde_json; /// This will give you all tasks which match the given query in the taskwarrior query syntax. /// This is not sanitized. Never get the query string from an untrusted user. -pub fn query(query: &str) -> Result<Vec<Task>> { +pub fn query(query: &str) -> Result<Vec<Task>, Error> { let mut cmd = add_query_to_cmd(query, Command::new("task")); cmd.stdout(Stdio::piped()); run_query_cmd(cmd) @@ -37,38 +35,37 @@ pub fn add_query_to_cmd(query: &str, mut cmd: Command) -> Command { } /// This executes the given Command and trys to convert the Result into a Vec<Task>. -pub fn run_query_cmd(mut cmd: Command) -> Result<Vec<Task>> { - let mut export = cmd.spawn().context(EK::TaskCmdError)?; - export.wait().context(EK::TaskCmdError)?; - import(export.stdout.ok_or(EK::TaskCmdError)?) +pub fn run_query_cmd(mut cmd: Command) -> Result<Vec<Task>, Error> { + let mut export = cmd.spawn()?; + export.wait()?; + import(export.stdout.ok_or(Error::TaskCmdError)?) } /// This function runs the given Command, pipes the tasks as JSON to it and returns a handle to the child process. -pub fn save_to_cmd(tasks: Vec<&'_ Task>, mut cmd: Command) -> Result<Child> { - let input_buffer = serde_json::to_string(&tasks).context(EK::SerializeError)?; - let mut import = cmd.spawn().context(EK::TaskCmdError)?; +pub fn save_to_cmd(tasks: Vec<&'_ Task>, mut cmd: Command) -> Result<Child, Error> { + let input_buffer = serde_json::to_string(&tasks)?; + let mut import = cmd.spawn()?; import .stdin .as_mut() - .ok_or(EK::TaskCmdError)? - .write_all(input_buffer.as_bytes()) - .context(EK::TaskCmdError)?; + .ok_or(Error::TaskCmdError)? + .write_all(input_buffer.as_bytes())?; Ok(import) } /// This will save the given tasks to taskwarrior. Call with `Some(&task)` if you just have one /// task. /// This will block until the save was successful. -pub fn save<'a, T>(tasks: T) -> Result<()> +pub fn save<'a, T>(tasks: T) -> Result<(), Error> where T: IntoIterator<Item = &'a Task>, { - save_async(tasks)?.wait().context(EK::TaskCmdError)?; + save_async(tasks)?.wait()?; Ok(()) } /// This function returns the handle to a child process which saves the given tasks. -pub fn save_async<'a, T>(tasks: T) -> Result<Child> +pub fn save_async<'a, T>(tasks: T) -> Result<Child, Error> where T: IntoIterator<Item = &'a Task>, { |