Merge pull request #1213 from matthiasbeyer/update-toml-query

Update dependency: toml-query -> 0.6
This commit is contained in:
Matthias Beyer 2018-01-13 02:04:17 +01:00 committed by GitHub
commit bb6ab1888a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 227 additions and 332 deletions

View file

@ -24,7 +24,7 @@ clap = ">=2.17"
log = "0.3" log = "0.3"
url = "1.2" url = "1.2"
toml = "0.4" toml = "0.4"
toml-query = "0.4" toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
clap = ">=2.17" clap = ">=2.17"
toml = "0.4" toml = "0.4"
toml-query = "0.4" toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

@ -24,7 +24,7 @@ clap = ">=2.17"
log = "0.3" log = "0.3"
url = "1.2" url = "1.2"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

@ -24,7 +24,7 @@ clap = ">=2.17"
log = "0.3" log = "0.3"
url = "1.5" url = "1.5"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

@ -31,7 +31,7 @@ libimagentrytag = { version = "0.6.0", path = "../../../lib/entry/libimagentryta
libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" } libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" }
[dev-dependencies] [dev-dependencies]
toml-query = "^0.4" toml-query = "0.6"
env_logger = "0.4" env_logger = "0.4"
[dev-dependencies.libimagutil] [dev-dependencies.libimagutil]

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
handlebars = "0.29.0" handlebars = "0.29.0"
tempfile = "2.1" tempfile = "2.1"

View file

@ -51,8 +51,7 @@ use std::process::Command;
use std::process::exit; use std::process::exit;
use handlebars::Handlebars; use handlebars::Handlebars;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml::Value;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::trace_error_exit; use libimagerror::trace::trace_error_exit;
@ -98,72 +97,68 @@ fn main() {
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
let query = format!("view.viewers.{}", viewer); let query = format!("view.viewers.{}", viewer);
match config.read(&query) {
Err(e) => trace_error_exit(&e, 1), let viewer_template = config
Ok(None) => { .read_string(&query)
.map_err_trace_exit_unwrap(1)
.unwrap_or_else(|| {
error!("Cannot find '{}' in config", query); error!("Cannot find '{}' in config", query);
exit(1) exit(1)
}, });
Ok(Some(&Value::String(ref viewer_template))) => { let mut handlebars = Handlebars::new();
let mut handlebars = Handlebars::new(); handlebars.register_escape_fn(::handlebars::no_escape);
handlebars.register_escape_fn(::handlebars::no_escape);
let _ = handlebars.register_template_string("template", viewer_template) let _ = handlebars
.register_template_string("template", viewer_template)
.map_err_trace_exit_unwrap(1);
let file = {
let mut tmpfile = tempfile::NamedTempFile::new()
.map_err_trace_exit_unwrap(1);
if view_header {
let hdr = toml::ser::to_string_pretty(entry.get_header())
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
let file = {
let mut tmpfile = tempfile::NamedTempFile::new()
.map_err_trace_exit_unwrap(1);
if view_header {
let hdr = toml::ser::to_string_pretty(entry.get_header())
.map_err_trace_exit_unwrap(1);
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
.map_err_trace_exit_unwrap(1);
}
if view_content {
let _ = tmpfile.write(entry.get_content().as_bytes())
.map_err_trace_exit_unwrap(1);
}
tmpfile
};
let file_path = file
.path()
.to_str()
.map(String::from)
.ok_or::<VE>("Cannot build path".to_owned().into())
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
}
let mut command = { if view_content {
let mut data = BTreeMap::new(); let _ = tmpfile.write(entry.get_content().as_bytes())
data.insert("entry", file_path); .map_err_trace_exit_unwrap(1);
}
let call = handlebars.render("template", &data).map_err_trace_exit_unwrap(1); tmpfile
let mut elems = call.split_whitespace(); };
let command_string = elems
.next()
.ok_or::<VE>("No command".to_owned().into())
.map_err_trace_exit_unwrap(1);
let mut cmd = Command::new(command_string);
for arg in elems { let file_path = file
cmd.arg(arg); .path()
} .to_str()
.map(String::from)
.ok_or::<VE>("Cannot build path".to_owned().into())
.map_err_trace_exit_unwrap(1);
cmd let mut command = {
}; let mut data = BTreeMap::new();
data.insert("entry", file_path);
if !command.status().map_err_trace_exit_unwrap(1).success() { let call = handlebars.render("template", &data).map_err_trace_exit_unwrap(1);
exit(1) let mut elems = call.split_whitespace();
} let command_string = elems
}, .next()
Ok(Some(_)) => { .ok_or::<VE>("No command".to_owned().into())
error!("Type error: Expected String at {}, found non-string", query); .map_err_trace_exit_unwrap(1);
exit(1) let mut cmd = Command::new(command_string);
},
for arg in elems {
cmd.arg(arg);
}
cmd
};
if !command.status().map_err_trace_exit_unwrap(1).success() {
exit(1)
} }
} else { } else {
let _ = StdoutViewer::new(view_header, view_content) let _ = StdoutViewer::new(view_header, view_content)

View file

@ -24,7 +24,7 @@ walkdir = "1"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }

View file

@ -44,8 +44,7 @@ extern crate libimagutil;
use std::process::exit; use std::process::exit;
use toml::Value; use toml_query::read::TomlValueReadTypeExt;
use toml_query::read::TomlValueReadExt;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
@ -177,19 +176,15 @@ fn get_collection_name(rt: &Runtime,
.and_then(|scmd| scmd.value_of(collection_argument_name).map(String::from)) .and_then(|scmd| scmd.value_of(collection_argument_name).map(String::from))
.unwrap_or_else(|| { .unwrap_or_else(|| {
rt.config() rt.config()
.map(|cfg| match cfg.read("bookmark.default_collection") { .map(|cfg| {
Err(e) => trace_error_exit(&e, 1), cfg.read_string("bookmark.default_collection")
Ok(Some(&Value::String(ref name))) => name.clone(), .map_err_trace_exit_unwrap(1)
Ok(None) => { .ok_or_else(|| {
error!("Missing config: 'bookmark.default_collection'. Set or use commandline to specify."); error!("Missing config: 'bookmark.default_collection'. Set or use commandline to specify.");
exit(1) exit(1)
}, })
.unwrap()
Ok(Some(_)) => { .clone()
error!("Type error in configuration: 'bookmark.default_collection' should be string");
exit(1)
}
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
error!("Failed to read configuration"); error!("Failed to read configuration");

View file

@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.3.1" toml-query = "0.6"
handlebars = "0.29" handlebars = "0.29"
vobject = "0.4" vobject = "0.4"
walkdir = "1" walkdir = "1"

View file

@ -56,8 +56,7 @@ use std::path::PathBuf;
use handlebars::Handlebars; use handlebars::Handlebars;
use clap::ArgMatches; use clap::ArgMatches;
use vobject::vcard::Vcard; use vobject::vcard::Vcard;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml::Value;
use walkdir::WalkDir; use walkdir::WalkDir;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
@ -219,18 +218,11 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd:
.unwrap_or_else(|| { .unwrap_or_else(|| {
rt.config() rt.config()
.ok_or_else(|| CE::from("No configuration file".to_owned())) .ok_or_else(|| CE::from("No configuration file".to_owned()))
.map_err_trace_exit(1) .map_err_trace_exit_unwrap(1)
.unwrap() .read_string(config_value_path)
.read(config_value_path) .map_err_trace_exit_unwrap(1)
.map_err_trace_exit(1)
.unwrap()
.ok_or_else(|| CE::from("Configuration 'contact.list_format' does not exist".to_owned())) .ok_or_else(|| CE::from("Configuration 'contact.list_format' does not exist".to_owned()))
.and_then(|value| match *value { .map_err_trace_exit_unwrap(1)
Value::String(ref s) => Ok(s.clone()),
_ => Err(CE::from("Type error: Expected String at 'contact.list_format'. Have non-String".to_owned()))
})
.map_err_trace_exit(1)
.unwrap()
}); });
let mut hb = Handlebars::new(); let mut hb = Handlebars::new();

View file

@ -24,7 +24,7 @@ chrono = "0.4"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -18,7 +18,7 @@ chrono = "0.4"
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
kairos = "0.1.0-beta-2" kairos = "0.1.0-beta-2"
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
is-match = "0.1" is-match = "0.1"
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

@ -136,6 +136,7 @@ fn show(rt: &Runtime) {
fn get_diary_name(rt: &Runtime) -> String { fn get_diary_name(rt: &Runtime) -> String {
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
let cfg = rt let cfg = rt
.config() .config()
@ -160,15 +161,13 @@ fn get_diary_name(rt: &Runtime) -> String {
.into_iter() .into_iter()
.map(Value::as_str) .map(Value::as_str)
.map(Option::unwrap) .map(Option::unwrap)
.collect::<Vec<_>>(); .map(String::from)
.collect::<Vec<String>>();
let current_log = cfg let current_log = cfg
.read("log.default") .read_string("log.default")
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
.ok_or(LE::from("Configuration missing: 'log.default'")) .ok_or(LE::from("Configuration missing: 'log.default'"))
.map_err_trace_exit_unwrap(1)
.as_str()
.ok_or(LE::from("Configuration 'log.default' is not a String"))
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
if !logs.contains(&current_log) { if !logs.contains(&current_log) {

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
clap = ">=2.17" clap = ">=2.17"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
is-match = "0.1" is-match = "0.1"
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

@ -82,6 +82,7 @@ fn tw_hook(rt: &Runtime) {
fn list(rt: &Runtime) { fn list(rt: &Runtime) {
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
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");
@ -99,13 +100,8 @@ fn list(rt: &Runtime) {
let uuids : Vec<_> = iter.filter_map(|storeid| { let uuids : Vec<_> = iter.filter_map(|storeid| {
match rt.store().retrieve(storeid) { match rt.store().retrieve(storeid) {
Ok(fle) => { Ok(fle) => {
match fle.get_header().read(&String::from("todo.uuid")) { match fle.get_header().read_string("todo.uuid") {
Ok(Some(&Value::String(ref u))) => Some(u.clone()), Ok(Some(ref u)) => Some(u.clone()),
Ok(Some(_)) => {
error!("Header type error, expected String at 'todo.uuid' in {}",
fle.get_location());
None
},
Ok(None) => { Ok(None) => {
error!("Header missing field in {}", fle.get_location()); error!("Header missing field in {}", fle.get_location());
None None

View file

@ -36,6 +36,7 @@ This section contains the changelog from the last release to the next release.
* Internals were refactored from `match`ing all the things into function * Internals were refactored from `match`ing all the things into function
chaining chaining
* `libimagbookmark` does not longer wrap types from the store. * `libimagbookmark` does not longer wrap types from the store.
* The `toml-query` dependency was updated to 0.5.0
* Bugfixes * Bugfixes
## 0.5.0 ## 0.5.0

View file

@ -28,7 +28,7 @@ xdg-basedir = "1.0"
itertools = "0.7" itertools = "0.7"
ansi_term = "0.10" ansi_term = "0.10"
is-match = "0.1" is-match = "0.1"
toml-query = "^0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
handlebars = "0.29.0" handlebars = "0.29.0"

View file

@ -33,6 +33,7 @@ use clap::ArgMatches;
use log::{Log, LogLevel, LogRecord, LogMetadata}; use log::{Log, LogLevel, LogRecord, LogMetadata};
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use handlebars::Handlebars; use handlebars::Handlebars;
type ModuleName = String; type ModuleName = String;
@ -239,15 +240,9 @@ fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Value>)
if let Some(cfg) = config { if let Some(cfg) = config {
let cfg_loglevel = cfg let cfg_loglevel = cfg
.read("imag.logging.level")? .read_string("imag.logging.level")?
.ok_or(RE::from_kind(EK::GlobalLogLevelConfigMissing))? .ok_or(RE::from_kind(EK::GlobalLogLevelConfigMissing))
.as_str() .and_then(|s| match_log_level_str(&s))?;
.ok_or_else(|| {
let path = "imag.logging.level".to_owned();
let ty = "String";
RE::from_kind(EK::ConfigTypeError(path, ty))
})
.and_then(match_log_level_str)?;
if let Some(cli_loglevel) = get_arg_loglevel(matches)? { if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
if cli_loglevel > cfg_loglevel { if cli_loglevel > cfg_loglevel {
@ -334,11 +329,8 @@ fn aggregate_global_destinations(matches: &ArgMatches, config: Option<&Value>)
macro_rules! aggregate_global_format { macro_rules! aggregate_global_format {
($read_str:expr, $error_kind_if_missing:expr, $config:expr) => { ($read_str:expr, $error_kind_if_missing:expr, $config:expr) => {
try!($config.ok_or(RE::from_kind($error_kind_if_missing))) try!($config.ok_or(RE::from_kind($error_kind_if_missing)))
.read($read_str)? .read_string($read_str)?
.ok_or_else(|| RE::from_kind($error_kind_if_missing))? .ok_or_else(|| RE::from_kind($error_kind_if_missing))
.as_str()
.map(String::from)
.ok_or_else(|| RE::from_kind(EK::ConfigTypeError($read_str.to_owned(), "String")))
}; };
} }
@ -418,16 +410,7 @@ fn aggregate_module_settings(_matches: &ArgMatches, config: Option<&Value>)
}; };
let level = inner_try! { let level = inner_try! {
v.read("level")? v.read_string("level")?.map(|s| match_log_level_str(&s))
.map(|val| {
val.as_str()
.ok_or_else(|| {
let path = "imag.logging.modules.<mod>.level".to_owned();
let ty = "String";
RE::from_kind(EK::ConfigTypeError(path, ty))
})
.and_then(match_log_level_str)
})
}; };
let enabled = v.read("enabled")? let enabled = v.read("enabled")?

View file

@ -32,7 +32,7 @@ serde = "1"
serde_json = "1" serde_json = "1"
serde_derive = "1" serde_derive = "1"
error-chain = "0.11" error-chain = "0.11"
toml-query = "0.4" toml-query = "0.6"
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" } libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" }

View file

@ -26,15 +26,12 @@ use error::StoreErrorKind as SEK;
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean /// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
/// value. If that key is present, the boolean is returned, otherwise false is returned. /// value. If that key is present, the boolean is returned, otherwise false is returned.
pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bool> { pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bool> {
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
let key = "store.implicit-create"; let key = "store.implicit-create";
if let Some(ref t) = *config { if let Some(ref t) = *config {
t.read(key)? t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))?
.as_bool()
.ok_or(SE::from_kind(SEK::ConfigTypeError(key, "boolean")))
} else { } else {
Ok(false) Ok(false)
} }

View file

@ -36,6 +36,7 @@ use glob::glob;
use walkdir::WalkDir; use walkdir::WalkDir;
use walkdir::Iter as WalkDirIter; use walkdir::Iter as WalkDirIter;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use error::{StoreError as SE, StoreErrorKind as SEK}; use error::{StoreError as SE, StoreErrorKind as SEK};
use error::ResultExt; use error::ResultExt;
@ -1102,13 +1103,10 @@ fn has_main_section(t: &Value) -> Result<bool> {
} }
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> { fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
use toml_query::read::TomlValueReadExt; t.read_string("imag.version")?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
t.read("imag.version")? .map(String::from)
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))? .map(|s| ::semver::Version::parse(&s).is_ok())
.as_str()
.map(|s| ::semver::Version::parse(s).is_ok())
.ok_or(SE::from_kind(SEK::ConfigTypeError("imag.version", "String")))
} }

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
chrono = "0.4" chrono = "0.4"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
itertools = "0.7" itertools = "0.7"
error-chain = "0.11" error-chain = "0.11"

View file

@ -22,19 +22,20 @@ use toml::Value;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
pub fn get_default_diary_name(rt: &Runtime) -> Option<String> { pub fn get_default_diary_name(rt: &Runtime) -> Option<String> {
get_diary_config_section(rt) get_diary_config_section(rt)
.and_then(|config| { .and_then(|config| {
match config.read(&String::from("default_diary")) { match config.read_string("default_diary") {
Ok(Some(&Value::String(ref s))) => Some(s.clone()), Ok(Some(ref s)) => Some(s.clone()),
_ => None, _ => None,
} }
}) })
} }
pub fn get_diary_config_section<'a>(rt: &'a Runtime) -> Option<&'a Value> { pub fn get_diary_config_section<'a>(rt: &'a Runtime) -> Option<&'a Value> {
rt.config().and_then(|config| match config.read(&String::from("diary")) { rt.config().and_then(|config| match config.read("diary") {
Ok(x) => x, Ok(x) => x,
Err(_) => None, Err(_) => None,
}) })

View file

@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
chrono = "0.4" chrono = "0.4"
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "0.4.0" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
kairos = "0.1.0-beta-2" kairos = "0.1.0-beta-2"

View file

@ -18,7 +18,7 @@
// //
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use chrono::Local; use chrono::Local;
@ -217,9 +217,9 @@ impl HabitTemplate for Entry {
fn habit_until_date(&self) -> Result<Option<String>> { fn habit_until_date(&self) -> Result<Option<String>> {
self.get_header() self.get_header()
.read("habit.template.until")? .read_string("habit.template.until")
.map(|v| v.as_str().map(String::from)) .map_err(From::from)
.ok_or(HEK::HeaderTypeError("habit.template.until", "String").into()) .map(|os| os.map(String::from))
} }
fn instance_id_for(habit_name: &String, habit_date: &NaiveDate) -> Result<StoreId> { fn instance_id_for(habit_name: &String, habit_date: &NaiveDate) -> Result<StoreId> {

View file

@ -19,7 +19,6 @@
use chrono::NaiveDate; use chrono::NaiveDate;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt; use toml_query::set::TomlValueSetExt;
use error::*; use error::*;

View file

@ -93,11 +93,10 @@ impl IsHabitCheck for Entry {
#[inline] #[inline]
pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<String> { pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<String> {
use error::HabitErrorKind as HEK; use error::HabitErrorKind as HEK;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
e.get_header() e.get_header()
.read(path)? .read_string(path)?
.ok_or(HEK::HeaderFieldMissing(path).into()) .ok_or(HEK::HeaderFieldMissing(path).into())
.and_then(|o| o.as_str().map(String::from).ok_or(HEK::HeaderTypeError(path, "String").into()))
} }

View file

@ -21,7 +21,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
toml = "0.4" toml = "0.4"
toml-query = "0.3" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -21,11 +21,10 @@ use libimagdiary::entry::DiaryEntry;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use error::LogError as LE; use error::LogError as LE;
use error::LogErrorKind as LEK;
use error::Result; use error::Result;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
pub trait Log : DiaryEntry { pub trait Log : DiaryEntry {
@ -35,11 +34,7 @@ pub trait Log : DiaryEntry {
impl Log for Entry { impl Log for Entry {
fn is_log(&self) -> Result<bool> { fn is_log(&self) -> Result<bool> {
let location = "log.is_log"; self.get_header().read_bool("log.is_log").map(|v| v.unwrap_or(false)).map_err(From::from)
self.get_header()
.read(location)?
.ok_or(LE::from_kind(LEK::HeaderTypeError("boolean", location)))
.map(|v| v.as_bool().unwrap_or(false))
} }
fn make_log_entry(&mut self) -> Result<()> { fn make_log_entry(&mut self) -> Result<()> {

View file

@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -21,7 +21,7 @@ use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::set::TomlValueSetExt; use toml_query::set::TomlValueSetExt;
use error::Result; use error::Result;
@ -47,10 +47,8 @@ impl Note for Entry {
fn get_name(&self) -> Result<String> { fn get_name(&self) -> Result<String> {
self.get_header() self.get_header()
.read("note.name") .read_string("note.name")
.chain_err(|| NEK::StoreReadError)? .chain_err(|| NEK::StoreReadError)?
.and_then(Value::as_str)
.map(String::from)
.ok_or(NE::from_kind(NEK::HeaderTypeError)) .ok_or(NE::from_kind(NEK::HeaderTypeError))
} }

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
filters = "0.2" filters = "0.2"
chrono = "0.4" chrono = "0.4"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
lazy_static = "0.2" lazy_static = "0.2"
is-match = "0.1" is-match = "0.1"
error-chain = "0.11" error-chain = "0.11"

View file

@ -38,7 +38,7 @@ use constants::*;
use toml::Value; use toml::Value;
use toml_query::delete::TomlValueDeleteExt; use toml_query::delete::TomlValueDeleteExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
pub trait TimeTracking { pub trait TimeTracking {
@ -64,15 +64,10 @@ impl TimeTracking for Entry {
fn get_timetrack_tag(&self) -> Result<TTT> { fn get_timetrack_tag(&self) -> Result<TTT> {
self.get_header() self.get_header()
.read(DATE_TIME_TAG_HEADER_PATH) .read_string(DATE_TIME_TAG_HEADER_PATH)
.chain_err(|| TTEK::HeaderReadError)? .chain_err(|| TTEK::HeaderReadError)?
.ok_or(TTE::from_kind(TTEK::HeaderReadError)) .ok_or(TTE::from_kind(TTEK::HeaderReadError))
.and_then(|v| { .map(Into::into)
v.as_str()
.map(String::from)
.map(Into::into)
.ok_or(TTE::from_kind(TTEK::HeaderFieldTypeError))
})
} }
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()> { fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()> {
@ -86,7 +81,7 @@ impl TimeTracking for Entry {
fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>> { fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>> {
self.get_header() self.get_header()
.read(DATE_TIME_START_HEADER_PATH) .read_string(DATE_TIME_START_HEADER_PATH)
.chain_err(|| TTEK::HeaderReadError) .chain_err(|| TTEK::HeaderReadError)
.and_then(header_value_to_dt) .and_then(header_value_to_dt)
} }
@ -109,7 +104,7 @@ impl TimeTracking for Entry {
fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>> { fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>> {
self.get_header() self.get_header()
.read(DATE_TIME_END_HEADER_PATH) .read_string(DATE_TIME_END_HEADER_PATH)
.chain_err(|| TTEK::HeaderReadError) .chain_err(|| TTEK::HeaderReadError)
.and_then(header_value_to_dt) .and_then(header_value_to_dt)
} }
@ -139,15 +134,13 @@ impl TimeTracking for Entry {
} }
fn header_value_to_dt(val: Option<&Value>) -> Result<Option<NaiveDateTime>> { fn header_value_to_dt(val: Option<String>) -> Result<Option<NaiveDateTime>> {
match val { match val {
Some(&Value::String(ref s)) => { Some(ref s) => {
NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT) NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT)
.chain_err(|| TTEK::DateTimeParserError) .chain_err(|| TTEK::DateTimeParserError)
.map(Some) .map(Some)
}, },
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)),
None => Ok(None), None => Ok(None),
} }
} }

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
task-hookrs = "0.4" task-hookrs = "0.4"
uuid = "0.5" uuid = "0.5"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
log = "0.3" log = "0.3"
serde_json = "1" serde_json = "1"
error-chain = "0.11" error-chain = "0.11"

View file

@ -25,7 +25,7 @@ use error::Result;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use uuid::Uuid; use uuid::Uuid;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
pub trait Task { pub trait Task {
fn get_uuid(&self) -> Result<Uuid>; fn get_uuid(&self) -> Result<Uuid>;
@ -34,12 +34,10 @@ pub trait Task {
impl Task for Entry { impl Task for Entry {
fn get_uuid(&self) -> Result<Uuid> { fn get_uuid(&self) -> Result<Uuid> {
self.get_header() self.get_header()
.read("todo.uuid") .read_string("todo.uuid")
.chain_err(|| TEK::StoreError)? .chain_err(|| TEK::StoreError)?
.ok_or(TE::from_kind(TEK::HeaderFieldMissing))? .ok_or(TE::from_kind(TEK::HeaderFieldMissing))
.as_str() .and_then(|u| Uuid::parse_str(&u).chain_err(|| TEK::UuidParserError))
.ok_or(TE::from_kind(TEK::HeaderTypeError))
.and_then(|u| Uuid::parse_str(u).chain_err(|| TEK::UuidParserError))
} }
} }

View file

@ -18,7 +18,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
lazy_static = "0.2" lazy_static = "0.2"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -28,12 +28,11 @@ use libimagentrylink::internal::InternalLinker;
use libimagentryutil::isa::Is; use libimagentryutil::isa::Is;
use libimagentryutil::isa::IsKindHeaderPathProvider; use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use error::Result; use error::Result;
use error::AnnotationErrorKind as AEK; use error::AnnotationErrorKind as AEK;
use error::AnnotationError as AE;
use error::ResultExt; use error::ResultExt;
use iter::*; use iter::*;
@ -75,12 +74,9 @@ impl Annotateable for Entry {
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> { fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
for annotation in self.annotations(store)? { for annotation in self.annotations(store)? {
let mut anno = annotation?; let mut anno = annotation?;
let name = match anno.get_header().read("annotation.name")? { let name = match anno.get_header().read_string("annotation.name")? {
None => continue, Some(ref name) => name.clone(),
Some(val) => match *val { None => continue,
Value::String(ref name) => name.clone(),
_ => return Err(AE::from_kind(AEK::HeaderTypeError)),
},
}; };
if name == ann_name { if name == ann_name {

View file

@ -17,8 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
use toml::Value; use toml_query::read::TomlValueReadTypeExt;
use toml_query::read::TomlValueReadExt;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
@ -26,7 +25,6 @@ use libimagstore::storeid::StoreIdIterator;
use error::Result; use error::Result;
use error::AnnotationErrorKind as AEK; use error::AnnotationErrorKind as AEK;
use error::AnnotationError as AE;
use error::ResultExt; use error::ResultExt;
#[derive(Debug)] #[derive(Debug)]
@ -47,11 +45,11 @@ impl<'a> Iterator for AnnotationIter<'a> {
loop { loop {
match self.0.next().map(|id| self.1.get(id)) { match self.0.next().map(|id| self.1.get(id)) {
Some(Ok(Some(entry))) => { Some(Ok(Some(entry))) => {
match entry.get_header().read("annotation.is_annotation") { match entry.get_header().read_bool("annotation.is_annotation").chain_err(|| AEK::HeaderReadError) {
Ok(None) => continue, // not an annotation Ok(None) => continue, // not an annotation
Ok(Some(&Value::Boolean(true))) => return Some(Ok(entry)), Ok(Some(false)) => continue,
Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))), Ok(Some(true)) => return Some(Ok(entry)),
Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)), Err(e) => return Some(Err(e)),
} }
}, },
Some(Ok(None)) => continue, Some(Ok(None)) => continue,

View file

@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
log = "0.3" log = "0.3"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
is-match = "0.1" is-match = "0.1"
error-chain = "0.11" error-chain = "0.11"

View file

@ -19,6 +19,7 @@
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml::Value; use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
@ -81,22 +82,16 @@ impl EntryCategory for Entry {
fn get_category(&self) -> Result<Option<Category>> { fn get_category(&self) -> Result<Option<Category>> {
self.get_header() self.get_header()
.read("category.value") .read_string("category.value")
.chain_err(|| CEK::HeaderReadError) .chain_err(|| CEK::HeaderReadError)
.and_then(|opt| { .and_then(|o| o.map(Category::from).ok_or(CE::from_kind(CEK::TypeError)))
opt.map(|v| { .map(Some)
v.as_str()
.map(String::from)
.map(Category::from)
})
.ok_or(CE::from_kind(CEK::TypeError))
})
} }
fn has_category(&self) -> Result<bool> { fn has_category(&self) -> Result<bool> {
self.get_header().read(&String::from("category.value")) self.get_header().read("category.value")
.chain_err(|| CEK::HeaderReadError) .chain_err(|| CEK::HeaderReadError)
.map(|e| e.is_some()) .map(|x| x.is_some())
} }
} }

View file

@ -20,7 +20,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml::Value; use toml::Value;
use libimagstore::store::Store; use libimagstore::store::Store;
@ -194,14 +194,13 @@ mod tests {
assert!(category.is_some()); assert!(category.is_some());
let category = category.unwrap(); let category = category.unwrap();
let header_field = category.get_header().read(CATEGORY_REGISTER_NAME_FIELD_PATH); let header_field = category.get_header().read_string(CATEGORY_REGISTER_NAME_FIELD_PATH);
assert!(header_field.is_ok(), format!("Expected Ok(_), got: {:?}", header_field)); assert!(header_field.is_ok(), format!("Expected Ok(_), got: {:?}", header_field));
let header_field = header_field.unwrap(); let header_field = header_field.unwrap();
match header_field { match header_field {
Some(&Value::String(ref s)) => assert_eq!(category_name, s), Some(ref s) => assert_eq!(category_name, s),
Some(_) => assert!(false, "Header field has wrong type"), None => assert!(false, "Header field not present"),
None => assert!(false, "Header field not present"),
} }
} }
} }
@ -226,12 +225,10 @@ fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result<bool>
.and_then(|fle| { .and_then(|fle| {
if let Some(fle) = fle { if let Some(fle) = fle {
fle.get_header() fle.get_header()
.read(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH)) .read_string(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH))
.chain_err(|| CEK::HeaderReadError)? .chain_err(|| CEK::HeaderReadError)?
.ok_or(CE::from_kind(CEK::TypeError))?
.as_str()
.map(|s| s == name)
.ok_or(CE::from_kind(CEK::TypeError)) .ok_or(CE::from_kind(CEK::TypeError))
.map(|s| s == name)
} else { } else {
Ok(false) Ok(false)
} }
@ -278,12 +275,10 @@ impl<'a> Iterator for CategoryNameIter<'a> {
.get(sid)? .get(sid)?
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))? .ok_or_else(|| CE::from_kind(CEK::StoreReadError))?
.get_header() .get_header()
.read(&query) .read_string(&query)
.chain_err(|| CEK::HeaderReadError)? .chain_err(|| CEK::HeaderReadError)?
.and_then(Value::as_str)
.map(String::from)
.map(Category::from) .map(Category::from)
.ok_or_else(|| CE::from_kind(CEK::TypeError)) .ok_or_else(|| CE::from_kind(CEK::StoreReadError))
}) })
} }
} }

View file

@ -21,7 +21,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
chrono = "0.4" chrono = "0.4"
toml-query = "^0.4" toml-query = "0.6"
lazy_static = "0.2" lazy_static = "0.2"
toml = "0.4" toml = "0.4"
error-chain = "0.11" error-chain = "0.11"

View file

@ -20,7 +20,7 @@
use chrono::naive::NaiveDateTime; use chrono::naive::NaiveDateTime;
use toml_query::delete::TomlValueDeleteExt; use toml_query::delete::TomlValueDeleteExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml::Value; use toml::Value;
use libimagstore::store::Entry; use libimagstore::store::Entry;
@ -60,15 +60,11 @@ impl EntryDate for Entry {
fn read_date(&self) -> Result<NaiveDateTime> { fn read_date(&self) -> Result<NaiveDateTime> {
self.get_header() self.get_header()
.read(&DATE_HEADER_LOCATION) .read_string(&DATE_HEADER_LOCATION)
.chain_err(|| DEK::ReadDateError) .chain_err(|| DEK::ReadDateError)?
.and_then(|v| { .ok_or(DE::from_kind(DEK::ReadDateError))?
v.ok_or(DE::from_kind(DEK::ReadDateError))? .parse::<NaiveDateTime>()
.as_str() .chain_err(|| DEK::DateTimeParsingError)
.ok_or(DE::from_kind(DEK::DateHeaderFieldTypeError))?
.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError)
})
} }
/// Set a Date for this entry /// Set a Date for this entry
@ -125,15 +121,17 @@ impl EntryDate for Entry {
fn read_date_range(&self) -> Result<DateTimeRange> { fn read_date_range(&self) -> Result<DateTimeRange> {
let start = self let start = self
.get_header() .get_header()
.read(&DATE_RANGE_START_HEADER_LOCATION) .read_string(&DATE_RANGE_START_HEADER_LOCATION)
.chain_err(|| DEK::ReadDateTimeRangeError) .chain_err(|| DEK::ReadDateTimeRangeError)?
.and_then(|v| str_to_ndt(v.ok_or(DE::from_kind(DEK::ReadDateError))?))?; .ok_or_else(|| DE::from_kind(DEK::ReadDateError))
.and_then(str_to_ndt)?;
let end = self let end = self
.get_header() .get_header()
.read(&DATE_RANGE_START_HEADER_LOCATION) .read_string(&DATE_RANGE_START_HEADER_LOCATION)
.chain_err(|| DEK::ReadDateTimeRangeError) .chain_err(|| DEK::ReadDateTimeRangeError)?
.and_then(|v| str_to_ndt(v.ok_or(DE::from_kind(DEK::ReadDateError))?))?; .ok_or_else(|| DE::from_kind(DEK::ReadDateError))
.and_then(str_to_ndt)?;
DateTimeRange::new(start, end).chain_err(|| DEK::DateTimeRangeError) DateTimeRange::new(start, end).chain_err(|| DEK::DateTimeRangeError)
} }
@ -154,13 +152,13 @@ impl EntryDate for Entry {
let opt_old_start = self let opt_old_start = self
.get_header_mut() .get_header_mut()
.insert(&DATE_RANGE_START_HEADER_LOCATION, Value::String(start)) .insert(&DATE_RANGE_START_HEADER_LOCATION, Value::String(start))
.map(|opt| opt.as_ref().map(str_to_ndt)) .map(|opt| opt.as_ref().map(val_to_ndt))
.chain_err(|| DEK::SetDateTimeRangeError)?; .chain_err(|| DEK::SetDateTimeRangeError)?;
let opt_old_end = self let opt_old_end = self
.get_header_mut() .get_header_mut()
.insert(&DATE_RANGE_END_HEADER_LOCATION, Value::String(end)) .insert(&DATE_RANGE_END_HEADER_LOCATION, Value::String(end))
.map(|opt| opt.as_ref().map(str_to_ndt)) .map(|opt| opt.as_ref().map(val_to_ndt))
.chain_err(|| DEK::SetDateTimeRangeError)?; .chain_err(|| DEK::SetDateTimeRangeError)?;
match (opt_old_start, opt_old_end) { match (opt_old_start, opt_old_end) {
@ -181,7 +179,13 @@ impl EntryDate for Entry {
} }
fn str_to_ndt(v: &Value) -> Result<NaiveDateTime> { #[inline]
fn str_to_ndt(v: String) -> Result<NaiveDateTime> {
v.parse::<NaiveDateTime>().chain_err(|| DEK::DateTimeParsingError)
}
#[inline]
fn val_to_ndt(v: &Value) -> Result<NaiveDateTime> {
v.as_str() v.as_str()
.ok_or(DE::from_kind(DEK::DateHeaderFieldTypeError))? .ok_or(DE::from_kind(DEK::DateHeaderFieldTypeError))?
.parse::<NaiveDateTime>() .parse::<NaiveDateTime>()
@ -191,6 +195,7 @@ fn str_to_ndt(v: &Value) -> Result<NaiveDateTime> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::path::PathBuf; use std::path::PathBuf;
use toml_query::read::TomlValueReadExt;
use super::*; use super::*;

View file

@ -27,7 +27,7 @@ log = "0.3"
regex = "0.2" regex = "0.2"
semver = "0.8" semver = "0.8"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagentrytag = { version = "0.6.0", path = "../../../lib/entry/libimagentrytag" } libimagentrytag = { version = "0.6.0", path = "../../../lib/entry/libimagentrytag" }

View file

@ -21,7 +21,7 @@ use semver::Version;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionEq { pub struct VersionEq {
@ -40,13 +40,9 @@ impl Filter<Entry> for VersionEq {
fn filter(&self, e: &Entry) -> bool { fn filter(&self, e: &Entry) -> bool {
e.get_header() e.get_header()
.read("imag.version") .read_string("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |s| Version::parse(&s).map(|v| v == self.version).unwrap_or(false))
v.as_str()
.map(|s| Version::parse(s).map(|v| v == self.version).unwrap_or(false))
.unwrap_or(false)
})
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -21,7 +21,7 @@ use semver::Version;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionGt { pub struct VersionGt {
@ -40,13 +40,9 @@ impl Filter<Entry> for VersionGt {
fn filter(&self, e: &Entry) -> bool { fn filter(&self, e: &Entry) -> bool {
e.get_header() e.get_header()
.read("imag.version") .read_string("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |s| Version::parse(&s).map(|v| v > self.version).unwrap_or(false))
v.as_str()
.map(|s| Version::parse(s).map(|v| v > self.version).unwrap_or(false))
.unwrap_or(false)
})
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -21,7 +21,7 @@ use semver::Version;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use filters::filter::Filter; use filters::filter::Filter;
pub struct VersionLt { pub struct VersionLt {
@ -40,13 +40,9 @@ impl Filter<Entry> for VersionLt {
fn filter(&self, e: &Entry) -> bool { fn filter(&self, e: &Entry) -> bool {
e.get_header() e.get_header()
.read("imag.version") .read_string("imag.version")
.map(|val| { .map(|val| {
val.map_or(false, |v| { val.map_or(false, |s| Version::parse(&s).map(|v| v < self.version).unwrap_or(false))
v.as_str()
.map(|s| Version::parse(s).map(|v| v < self.version).unwrap_or(false))
.unwrap_or(false)
})
}) })
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
serde_derive = "1" serde_derive = "1"
serde = "1" serde = "1"
error-chain = "0.11" error-chain = "0.11"

View file

@ -26,7 +26,7 @@ toml = "0.4"
url = "1.5" url = "1.5"
rust-crypto = "0.2" rust-crypto = "0.2"
is-match = "0.1" is-match = "0.1"
toml-query = "^0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -41,10 +41,10 @@ use libimagstore::storeid::IntoStoreId;
use libimagutil::debug_result::*; use libimagutil::debug_result::*;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use error::LinkErrorKind as LEK; use error::LinkErrorKind as LEK;
use error::LinkError as LE;
use error::Result; use error::Result;
use internal::InternalLinker; use internal::InternalLinker;
use module_path::ModuleEntryPath; use module_path::ModuleEntryPath;
@ -69,27 +69,23 @@ impl Link for Entry {
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> { fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
self.get_header() self.get_header()
.read("links.external.content.url") .read_string("links.external.content.url")
.chain_err(|| LEK::EntryHeaderReadError) .chain_err(|| LEK::EntryHeaderReadError)
.and_then(|opt| match opt { .and_then(|opt| match opt {
Some(&Value::String(ref s)) => { None => Ok(None),
Some(ref s) => {
debug!("Found url, parsing: {:?}", s); debug!("Found url, parsing: {:?}", s);
Url::parse(&s[..]).chain_err(|| LEK::InvalidUri).map(Some) Url::parse(&s[..]).chain_err(|| LEK::InvalidUri).map(Some)
}, },
Some(_) => Err(LE::from_kind(LEK::LinkParserFieldTypeError)),
None => Ok(None),
}) })
} }
fn get_url(&self) -> Result<Option<Url>> { fn get_url(&self) -> Result<Option<Url>> {
match self.get_header().read("links.external.url") { match self.get_header().read_string("links.external.url")? {
Ok(Some(&Value::String(ref s))) => { None => Ok(None),
Url::parse(&s[..]) Some(ref s) => Url::parse(&s[..])
.map(Some) .map(Some)
.chain_err(|| LEK::EntryHeaderReadError) .chain_err(|| LEK::EntryHeaderReadError),
},
Ok(None) => Ok(None),
_ => Err(LE::from_kind(LEK::EntryHeaderReadError))
} }
} }

View file

@ -24,7 +24,7 @@ itertools = "0.7"
log = "0.3" log = "0.3"
rust-crypto = "0.2" rust-crypto = "0.2"
toml = "0.4" toml = "0.4"
toml-query = "^0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
walkdir = "1" walkdir = "1"

View file

@ -38,12 +38,8 @@ impl RefFlags {
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean. /// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
pub fn read(v: &Value) -> Result<RefFlags> { pub fn read(v: &Value) -> Result<RefFlags> {
fn get_field(v: &Value, key: &str) -> Result<bool> { fn get_field(v: &Value, key: &str) -> Result<bool> {
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
v.read_bool(key)?.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
v.read(key)?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_bool()
.ok_or(REK::HeaderTypeError.into())
} }
Ok(RefFlags { Ok(RefFlags {

View file

@ -29,7 +29,7 @@ use libimagentryutil::isa::Is;
use libimagentryutil::isa::IsKindHeaderPathProvider; use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::set::TomlValueSetExt; use toml_query::set::TomlValueSetExt;
use error::RefErrorKind as REK; use error::RefErrorKind as REK;
@ -152,11 +152,8 @@ impl Ref for Entry {
/// custom Hasher instance. /// custom Hasher instance.
fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> { fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> {
self.get_header() self.get_header()
.read(&format!("ref.content_hash.{}", h.hash_name())[..])? .read_string(&format!("ref.content_hash.{}", h.hash_name())[..])?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))? .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.as_str()
.map(String::from)
.ok_or(RE::from_kind(REK::HeaderTypeError))
} }
/// Get the hash of the link target by reading the link target and hashing the contents /// Get the hash of the link target by reading the link target and hashing the contents
@ -210,13 +207,9 @@ impl Ref for Entry {
fn fs_link_valid_permissions(&self) -> Result<bool> { fn fs_link_valid_permissions(&self) -> Result<bool> {
self self
.get_header() .get_header()
.read("ref.permissions.ro") .read_bool("ref.permissions.ro")
.chain_err(|| REK::HeaderFieldReadError) .chain_err(|| REK::HeaderFieldReadError)?
.and_then(|ro| { .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
ro.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_bool()
.ok_or(RE::from_kind(REK::HeaderTypeError))
})
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly())) .and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
.chain_err(|| REK::RefTargetCannotReadPermissions) .chain_err(|| REK::RefTargetCannotReadPermissions)
} }
@ -256,11 +249,9 @@ impl Ref for Entry {
/// Get the path of the file which is reffered to by this Ref /// Get the path of the file which is reffered to by this Ref
fn fs_file(&self) -> Result<PathBuf> { fn fs_file(&self) -> Result<PathBuf> {
self.get_header() self.get_header()
.read("ref.path")? .read_string("ref.path")?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))? .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.as_str()
.map(PathBuf::from) .map(PathBuf::from)
.ok_or(RE::from_kind(REK::HeaderTypeError))
} }
/// Re-find a referenced file /// Re-find a referenced file

View file

@ -25,7 +25,7 @@ use error::Result;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
/// Creates a Hash from a PathBuf by making the PathBuf absolute and then running a hash /// Creates a Hash from a PathBuf by making the PathBuf absolute and then running a hash
/// algorithm on it /// algorithm on it
@ -45,10 +45,8 @@ pub fn hash_path(pb: &PathBuf) -> Result<String> {
/// Read the reference from a file /// Read the reference from a file
pub fn read_reference(refentry: &Entry) -> Result<PathBuf> { pub fn read_reference(refentry: &Entry) -> Result<PathBuf> {
refentry.get_header() refentry.get_header()
.read("ref.path")? .read_string("ref.path")?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))? .ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.as_str()
.ok_or(RE::from_kind(REK::HeaderTypeError))
.map(PathBuf::from) .map(PathBuf::from)
} }

View file

@ -27,7 +27,7 @@ toml = "0.4"
itertools = "0.7" itertools = "0.7"
is-match = "0.1" is-match = "0.1"
filters = "0.2" filters = "0.2"
toml-query = "^0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -21,7 +21,7 @@ maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
toml = "0.4" toml = "0.4"
toml-query = "0.4" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

@ -21,7 +21,7 @@ use error::EntryUtilError as EUE;
use error::Result; use error::Result;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
/// Trait to check whether an entry is a certain kind of entry /// Trait to check whether an entry is a certain kind of entry
@ -76,11 +76,9 @@ impl Is for ::libimagstore::store::Entry {
fn is<T: IsKindHeaderPathProvider>(&self) -> Result<bool> { fn is<T: IsKindHeaderPathProvider>(&self) -> Result<bool> {
let field = T::kindflag_header_location(); let field = T::kindflag_header_location();
match self.get_header().read(field) { match self.get_header().read_bool(field)? {
Ok(Some(&Value::Boolean(b))) => Ok(b), Some(b) => Ok(b),
Ok(Some(_)) => Err(format!("Field {} has not a boolean type", field)).map_err(EUE::from), None => Err(format!("Field {} not available", field)).map_err(EUE::from),
Ok(None) => Err(format!("Field {} not available", field)).map_err(EUE::from),
Err(e) => Err(EUE::from(e))
} }
} }