Reimplement list()

This commit is contained in:
Matthias Beyer 2016-07-21 15:54:38 +02:00
parent 0da8df3c26
commit 98a8356150

View file

@ -17,6 +17,8 @@ use std::process::exit;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::io::stdin; use std::io::stdin;
use toml::Value;
use task_hookrs::import::import_tasks; use task_hookrs::import::import_tasks;
use task_hookrs::status::TaskStatus; use task_hookrs::status::TaskStatus;
@ -99,63 +101,54 @@ fn tw_hook(rt: &Runtime) {
} }
fn list(rt: &Runtime) { fn list(rt: &Runtime) {
let subcmd = rt.cli().subcommand_matches("list").unwrap(); let subcmd = rt.cli().subcommand_matches("list").unwrap();
let mut args = Vec::new(); let verbose = subcmd.is_present("verbose");
let verbose = subcmd.is_present("verbose");
let iter = match Task::all(rt.store()) {
Ok(iter) => iter,
Err(e) => {
trace_error(&e);
exit(1);
},
};
for task in iter { let res = Task::all(rt.store())
match task { .map(|iter| {
Ok(val) => { let uuids : Vec<_> = iter.filter_map(|t| match t {
let uuid = match val.get_header().read("todo.uuid") { Ok(v) => match v.get_header().read("todo.uuid") {
Ok(Some(u)) => u, Ok(Some(Value::String(ref u))) => Some(u.clone()),
Ok(None) => continue, Ok(Some(_)) => {
Err(e) => { warn!("Header type error");
None
},
Ok(None) => None,
Err(e) => {
trace_error(&e); trace_error(&e);
continue; None
} }
}; },
Err(e) => {
if verbose { trace_error(&e);
args.clear(); None
args.push(format!("uuid:{} information", uuid));
let tw_process = Command::new("task")
.stdin(Stdio::null())
.args(&args)
.spawn()
.unwrap_or_else(|e| {
trace_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 execute: {}", e));
println!("{}", outstring);
} else {
println!("{}", match uuid {
toml::Value::String(s) => s,
_ => {
error!("Unexpected type for todo.uuid: {}", uuid);
continue;
},
});
} }
} })
Err(e) => { .collect();
trace_error(&e);
continue; let outstring = if verbose {
} let output = Command::new("task")
} // end match task .stdin(Stdio::null())
} // end for .args(&uuids)
.spawn()
.unwrap_or_else(|e| {
trace_error(&e);
panic!("Failed to execute `task` on the commandline. I'm dying now.");
})
.wait_with_output()
.unwrap_or_else(|e| panic!("failed to unwrap output: {}", e));
String::from_utf8(output.stdout)
.unwrap_or_else(|e| panic!("failed to execute: {}", e))
} else {
uuids.join("\n")
};
println!("{}", outstring);
});
if let Err(e) = res {
trace_error(&e);
}
} }