implemented list-featureo

This commit is contained in:
mario 2016-06-28 23:05:05 +02:00
parent aa75b5ad9d
commit 72e85399ff
3 changed files with 85 additions and 27 deletions

View file

@ -72,7 +72,7 @@ fn main() {
} }
} }
else if subcmd.is_present("delete") { else if subcmd.is_present("delete") {
println!("To be implemented"); unimplemented!();
// //
// Functionality to delete Entry in the store // Functionality to delete Entry in the store
// //
@ -80,33 +80,91 @@ fn main() {
else { else {
// Should not be possible, as one argument is required via // Should not be possible, as one argument is required via
// ArgGroup // ArgGroup
panic!("Reached unreachable Code"); unreachable!();
} }
}, },
Some("exec") => { Some("exec") => {
let subcmd = rt.cli().subcommand_matches("exec").unwrap(); let subcmd = rt.cli().subcommand_matches("exec").unwrap();
let mut args = Vec::new(); let mut args = Vec::new();
if let Some(exec_string) = subcmd.values_of("command") { if let Some(exec_string) = subcmd.values_of("command") {
for e in exec_string { for e in exec_string {
args.push(e); args.push(e);
} }
let tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| { let tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| {
panic!("failed to execute taskwarrior: {}", e); panic!("failed to execute taskwarrior: {}", e);
}); });
let output = tw_process.wait_with_output().unwrap_or_else(|e| { let output = tw_process.wait_with_output().unwrap_or_else(|e| {
panic!("failed to unwrap output: {}", e); panic!("failed to unwrap output: {}", e);
}); });
let outstring = String::from_utf8(output.stdout).unwrap_or_else(|e| { let outstring = String::from_utf8(output.stdout).unwrap_or_else(|e| {
panic!("failed to ececute: {}", e); panic!("failed to ececute: {}", e);
}); });
println!("{}", outstring); println!("{}", outstring);
} else { } else {
panic!("faild to execute: You need to exec --command"); panic!("faild to execute: You need to exec --command");
} }
},
_ => panic!("Reached unreachable Code"),
} }
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!(),
}
}

View file

@ -6,7 +6,7 @@ use result::Result;
pub fn get_todo_iterator(store: &Store) -> Result<TaskIterator> { pub fn get_todo_iterator(store: &Store) -> Result<TaskIterator> {
store.retrieve_for_module("uuid") store.retrieve_for_module("todo/taskwarrior")
.map(|iter| TaskIterator::new(store, iter)) .map(|iter| TaskIterator::new(store, iter))
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
} }

View file

@ -14,7 +14,7 @@ use result::Result;
/// Task struct containing a `FileLockEntry` /// Task struct containing a `FileLockEntry`
#[derive(Debug)] #[derive(Debug)]
pub struct Task<'a> { pub struct Task<'a> {
flentry : FileLockEntry<'a>, pub flentry : FileLockEntry<'a>,
} }
impl<'a> Task<'a> { impl<'a> Task<'a> {