From af965dd117cf0766b7021cb6ae15baca2afca511 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 May 2017 21:09:52 +0200 Subject: [PATCH] Fix imag-todo for new toml read interface --- imag-todo/Cargo.toml | 2 ++ imag-todo/src/main.rs | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/imag-todo/Cargo.toml b/imag-todo/Cargo.toml index 1216f738..8d40adb9 100644 --- a/imag-todo/Cargo.toml +++ b/imag-todo/Cargo.toml @@ -21,6 +21,8 @@ semver = "0.5.1" serde_json = "0.8.3" task-hookrs = "0.2.2" toml = "0.4.*" +toml-query = "0.1.*" +is-match = "0.1.*" version = "2.0.1" [dependencies.libimagrt] diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index bcdae191..4d6396bc 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -23,6 +23,8 @@ extern crate glob; extern crate serde_json; extern crate semver; extern crate toml; +extern crate toml_query; +#[macro_use] extern crate is_match; #[macro_use] extern crate version; extern crate task_hookrs; @@ -84,22 +86,32 @@ fn tw_hook(rt: &Runtime) { } fn list(rt: &Runtime) { + use toml_query::read::TomlValueReadExt; + let subcmd = rt.cli().subcommand_matches("list").unwrap(); let verbose = subcmd.is_present("verbose"); + // Helper for toml_query::read::TomlValueReadExt::read() return value, which does only + // return Result instead of Result>, 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 .map(|iter| { // and if this succeeded // filter out the ones were we can read the uuid let uuids : Vec<_> = iter.filter_map(|t| match t { - Ok(v) => match v.get_header().read("todo.uuid") { - Ok(Some(Value::String(ref u))) => Some(u.clone()), - Ok(Some(_)) => { + Ok(v) => match v.get_header().read(&String::from("todo.uuid")) { + Ok(&Value::String(ref u)) => Some(u.clone()), + Ok(_) => { warn!("Header type error"); None }, - Ok(None) => None, Err(e) => { - trace_error(&e); + if !no_identifier(&e) { + trace_error(&e); + } None } },