Fix imag-todo for new toml read interface

This commit is contained in:
Matthias Beyer 2017-05-30 21:09:52 +02:00
parent 50c4c16aaf
commit af965dd117
2 changed files with 19 additions and 5 deletions

View file

@ -21,6 +21,8 @@ semver = "0.5.1"
serde_json = "0.8.3" serde_json = "0.8.3"
task-hookrs = "0.2.2" task-hookrs = "0.2.2"
toml = "0.4.*" toml = "0.4.*"
toml-query = "0.1.*"
is-match = "0.1.*"
version = "2.0.1" version = "2.0.1"
[dependencies.libimagrt] [dependencies.libimagrt]

View file

@ -23,6 +23,8 @@ extern crate glob;
extern crate serde_json; extern crate serde_json;
extern crate semver; extern crate semver;
extern crate toml; extern crate toml;
extern crate toml_query;
#[macro_use] extern crate is_match;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate task_hookrs; extern crate task_hookrs;
@ -84,22 +86,32 @@ fn tw_hook(rt: &Runtime) {
} }
fn list(rt: &Runtime) { fn list(rt: &Runtime) {
use toml_query::read::TomlValueReadExt;
let subcmd = rt.cli().subcommand_matches("list").unwrap(); let subcmd = rt.cli().subcommand_matches("list").unwrap();
let verbose = subcmd.is_present("verbose"); let verbose = subcmd.is_present("verbose");
// Helper for toml_query::read::TomlValueReadExt::read() return value, which does only
// return Result<T> instead of Result<Option<T>>, which is a real inconvenience.
//
let no_identifier = |e: &::toml_query::error::Error| -> bool {
is_match!(e.kind(), &::toml_query::error::ErrorKind::IdentifierNotFoundInDocument(_))
};
let res = Task::all(rt.store()) // get all tasks let res = Task::all(rt.store()) // get all tasks
.map(|iter| { // and if this succeeded .map(|iter| { // and if this succeeded
// filter out the ones were we can read the uuid // filter out the ones were we can read the uuid
let uuids : Vec<_> = iter.filter_map(|t| match t { let uuids : Vec<_> = iter.filter_map(|t| match t {
Ok(v) => match v.get_header().read("todo.uuid") { Ok(v) => match v.get_header().read(&String::from("todo.uuid")) {
Ok(Some(Value::String(ref u))) => Some(u.clone()), Ok(&Value::String(ref u)) => Some(u.clone()),
Ok(Some(_)) => { Ok(_) => {
warn!("Header type error"); warn!("Header type error");
None None
}, },
Ok(None) => None,
Err(e) => { Err(e) => {
trace_error(&e); if !no_identifier(&e) {
trace_error(&e);
}
None None
} }
}, },