diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index b756bb31..6b463000 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -72,7 +72,7 @@ fn main() { } } else if subcmd.is_present("delete") { - println!("To be implemented"); + unimplemented!(); // // Functionality to delete Entry in the store // @@ -80,33 +80,91 @@ fn main() { else { // Should not be possible, as one argument is required via // ArgGroup - panic!("Reached unreachable Code"); + unreachable!(); } }, Some("exec") => { - let subcmd = rt.cli().subcommand_matches("exec").unwrap(); - let mut args = Vec::new(); - if let Some(exec_string) = subcmd.values_of("command") { - for e in exec_string { - args.push(e); - } - let tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| { - panic!("failed to execute taskwarrior: {}", e); - }); + let subcmd = rt.cli().subcommand_matches("exec").unwrap(); + let mut args = Vec::new(); + if let Some(exec_string) = subcmd.values_of("command") { + for e in exec_string { + args.push(e); + } + let tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| { + panic!("failed to execute taskwarrior: {}", e); + }); - let output = tw_process.wait_with_output().unwrap_or_else(|e| { - panic!("failed to unwrap output: {}", e); - }); - let outstring = String::from_utf8(output.stdout).unwrap_or_else(|e| { - panic!("failed to ececute: {}", e); - }); - println!("{}", outstring); - } else { - panic!("faild to execute: You need to exec --command"); - } - }, - _ => panic!("Reached unreachable Code"), + let output = tw_process.wait_with_output().unwrap_or_else(|e| { + panic!("failed to unwrap output: {}", e); + }); + let outstring = String::from_utf8(output.stdout).unwrap_or_else(|e| { + panic!("failed to ececute: {}", e); + }); + println!("{}", outstring); + } else { + panic!("faild to execute: You need to exec --command"); + } } - -} + Some("list") => { + let subcmd = rt.cli().subcommand_matches("list").unwrap(); + let mut args = Vec::new(); + let verbose = subcmd.is_present("verbose"); + let iter = match libimagtodo::read::get_todo_iterator(rt.store()) { + //let iter = match rt.store().retrieve_for_module("todo/taskwarrior") { + Err(e) => { + error!("{}", e); + return; + } + Ok(val) => val, + }; + for task in iter { + match task { + Ok(val) => { + //let val = libimagtodo::task::Task::new(fle); + //println!("{:#?}", val.flentry); + let uuid = match val.flentry.get_header().read("todo.uuid") { + Ok(Some(u)) => u, + Ok(None) => continue, + Err(e) => { + error!("{}", e); + continue; + } + }; + if verbose { + args.clear(); + args.push(format!("uuid:{}", uuid)); + args.push(format!("{}", "information")); + let tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn() + .unwrap_or_else(|e| { + error!("{}", e); + panic!("failed"); + }); + let output = tw_process.wait_with_output().unwrap_or_else(|e| { + panic!("failed to unwrap output: {}", e); + }); + let outstring = String::from_utf8(output.stdout).unwrap_or_else(|e| { + panic!("failed to ececute: {}", e); + }); + println!("{}", outstring); + } + else { + println!("{}", match uuid { + toml::Value::String(s) => s, + _ => { + error!("Unexpected type for todo.uuid: {}", uuid); + continue; + }, + }); + } + } + Err(e) => { + error!("{}", e); + continue; + } + } + } + } + _ => unimplemented!(), + } + } diff --git a/libimagtodo/src/read.rs b/libimagtodo/src/read.rs index 4af86d61..57c326c9 100644 --- a/libimagtodo/src/read.rs +++ b/libimagtodo/src/read.rs @@ -6,7 +6,7 @@ use result::Result; pub fn get_todo_iterator(store: &Store) -> Result { - store.retrieve_for_module("uuid") + store.retrieve_for_module("todo/taskwarrior") .map(|iter| TaskIterator::new(store, iter)) .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) } diff --git a/libimagtodo/src/task.rs b/libimagtodo/src/task.rs index 5fe55990..b9174a56 100644 --- a/libimagtodo/src/task.rs +++ b/libimagtodo/src/task.rs @@ -14,7 +14,7 @@ use result::Result; /// Task struct containing a `FileLockEntry` #[derive(Debug)] pub struct Task<'a> { - flentry : FileLockEntry<'a>, + pub flentry : FileLockEntry<'a>, } impl<'a> Task<'a> {