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"
url = "1.2"
toml = "0.4"
toml-query = "0.4"
toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }

View file

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

View file

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

View file

@ -24,7 +24,7 @@ clap = ">=2.17"
log = "0.3"
url = "1.5"
toml = "0.4"
toml-query = "^0.4"
toml-query = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
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" }
[dev-dependencies]
toml-query = "^0.4"
toml-query = "0.6"
env_logger = "0.4"
[dev-dependencies.libimagutil]

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" }
clap = ">=2.17"
log = "0.3"
toml = "0.4"
toml-query = "^0.4"
toml-query = "0.6"
is-match = "0.1"
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 {
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
let cfg = rt
.config()
@ -160,15 +161,13 @@ fn get_diary_name(rt: &Runtime) -> String {
.into_iter()
.map(Value::as_str)
.map(Option::unwrap)
.collect::<Vec<_>>();
.map(String::from)
.collect::<Vec<String>>();
let current_log = cfg
.read("log.default")
.read_string("log.default")
.map_err_trace_exit_unwrap(1)
.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);
if !logs.contains(&current_log) {

View file

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

View file

@ -82,6 +82,7 @@ fn tw_hook(rt: &Runtime) {
fn list(rt: &Runtime) {
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
let subcmd = rt.cli().subcommand_matches("list").unwrap();
let verbose = subcmd.is_present("verbose");
@ -99,13 +100,8 @@ fn list(rt: &Runtime) {
let uuids : Vec<_> = iter.filter_map(|storeid| {
match rt.store().retrieve(storeid) {
Ok(fle) => {
match fle.get_header().read(&String::from("todo.uuid")) {
Ok(Some(&Value::String(ref u))) => Some(u.clone()),
Ok(Some(_)) => {
error!("Header type error, expected String at 'todo.uuid' in {}",
fle.get_location());
None
},
match fle.get_header().read_string("todo.uuid") {
Ok(Some(ref u)) => Some(u.clone()),
Ok(None) => {
error!("Header missing field in {}", fle.get_location());
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
chaining
* `libimagbookmark` does not longer wrap types from the store.
* The `toml-query` dependency was updated to 0.5.0
* Bugfixes
## 0.5.0

View file

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

View file

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

View file

@ -32,7 +32,7 @@ serde = "1"
serde_json = "1"
serde_derive = "1"
error-chain = "0.11"
toml-query = "0.4"
toml-query = "0.6"
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
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
/// 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> {
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
let key = "store.implicit-create";
if let Some(ref t) = *config {
t.read(key)?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))?
.as_bool()
.ok_or(SE::from_kind(SEK::ConfigTypeError(key, "boolean")))
t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))
} else {
Ok(false)
}

View file

@ -36,6 +36,7 @@ use glob::glob;
use walkdir::WalkDir;
use walkdir::Iter as WalkDirIter;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use error::{StoreError as SE, StoreErrorKind as SEK};
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> {
use toml_query::read::TomlValueReadExt;
t.read("imag.version")?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))?
.as_str()
.map(|s| ::semver::Version::parse(s).is_ok())
.ok_or(SE::from_kind(SEK::ConfigTypeError("imag.version", "String")))
t.read_string("imag.version")?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
.map(String::from)
.map(|s| ::semver::Version::parse(&s).is_ok())
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -93,11 +93,10 @@ impl IsHabitCheck for Entry {
#[inline]
pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<String> {
use error::HabitErrorKind as HEK;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
e.get_header()
.read(path)?
.read_string(path)?
.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]
toml = "0.4"
toml-query = "0.3"
toml-query = "0.6"
error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,7 +18,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
lazy_static = "0.2"
toml = "0.4"
toml-query = "^0.4"
toml-query = "0.6"
error-chain = "0.11"
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::IsKindHeaderPathProvider;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt;
use error::Result;
use error::AnnotationErrorKind as AEK;
use error::AnnotationError as AE;
use error::ResultExt;
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>>> {
for annotation in self.annotations(store)? {
let mut anno = annotation?;
let name = match anno.get_header().read("annotation.name")? {
None => continue,
Some(val) => match *val {
Value::String(ref name) => name.clone(),
_ => return Err(AE::from_kind(AEK::HeaderTypeError)),
},
let name = match anno.get_header().read_string("annotation.name")? {
Some(ref name) => name.clone(),
None => continue,
};
if name == ann_name {

View file

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

View file

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

View file

@ -19,6 +19,7 @@
use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml::Value;
use libimagstore::store::Entry;
@ -81,22 +82,16 @@ impl EntryCategory for Entry {
fn get_category(&self) -> Result<Option<Category>> {
self.get_header()
.read("category.value")
.read_string("category.value")
.chain_err(|| CEK::HeaderReadError)
.and_then(|opt| {
opt.map(|v| {
v.as_str()
.map(String::from)
.map(Category::from)
})
.ok_or(CE::from_kind(CEK::TypeError))
})
.and_then(|o| o.map(Category::from).ok_or(CE::from_kind(CEK::TypeError)))
.map(Some)
}
fn has_category(&self) -> Result<bool> {
self.get_header().read(&String::from("category.value"))
self.get_header().read("category.value")
.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 toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml::Value;
use libimagstore::store::Store;
@ -194,14 +194,13 @@ mod tests {
assert!(category.is_some());
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));
let header_field = header_field.unwrap();
match header_field {
Some(&Value::String(ref s)) => assert_eq!(category_name, s),
Some(_) => assert!(false, "Header field has wrong type"),
None => assert!(false, "Header field not present"),
Some(ref s) => assert_eq!(category_name, s),
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| {
if let Some(fle) = fle {
fle.get_header()
.read(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH))
.read_string(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH))
.chain_err(|| CEK::HeaderReadError)?
.ok_or(CE::from_kind(CEK::TypeError))?
.as_str()
.map(|s| s == name)
.ok_or(CE::from_kind(CEK::TypeError))
.map(|s| s == name)
} else {
Ok(false)
}
@ -278,12 +275,10 @@ impl<'a> Iterator for CategoryNameIter<'a> {
.get(sid)?
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))?
.get_header()
.read(&query)
.read_string(&query)
.chain_err(|| CEK::HeaderReadError)?
.and_then(Value::as_str)
.map(String::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]
chrono = "0.4"
toml-query = "^0.4"
toml-query = "0.6"
lazy_static = "0.2"
toml = "0.4"
error-chain = "0.11"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -24,7 +24,7 @@ itertools = "0.7"
log = "0.3"
rust-crypto = "0.2"
toml = "0.4"
toml-query = "^0.4"
toml-query = "0.6"
error-chain = "0.11"
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.
pub fn read(v: &Value) -> Result<RefFlags> {
fn get_field(v: &Value, key: &str) -> Result<bool> {
use toml_query::read::TomlValueReadExt;
v.read(key)?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_bool()
.ok_or(REK::HeaderTypeError.into())
use toml_query::read::TomlValueReadTypeExt;
v.read_bool(key)?.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
}
Ok(RefFlags {

View file

@ -29,7 +29,7 @@ use libimagentryutil::isa::Is;
use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::set::TomlValueSetExt;
use error::RefErrorKind as REK;
@ -152,11 +152,8 @@ impl Ref for Entry {
/// custom Hasher instance.
fn get_stored_hash_with_hasher<H: Hasher>(&self, h: &H) -> Result<String> {
self.get_header()
.read(&format!("ref.content_hash.{}", h.hash_name())[..])?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_str()
.map(String::from)
.ok_or(RE::from_kind(REK::HeaderTypeError))
.read_string(&format!("ref.content_hash.{}", h.hash_name())[..])?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
}
/// 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> {
self
.get_header()
.read("ref.permissions.ro")
.chain_err(|| REK::HeaderFieldReadError)
.and_then(|ro| {
ro.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_bool()
.ok_or(RE::from_kind(REK::HeaderTypeError))
})
.read_bool("ref.permissions.ro")
.chain_err(|| REK::HeaderFieldReadError)?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
.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
fn fs_file(&self) -> Result<PathBuf> {
self.get_header()
.read("ref.path")?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_str()
.read_string("ref.path")?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.map(PathBuf::from)
.ok_or(RE::from_kind(REK::HeaderTypeError))
}
/// Re-find a referenced file

View file

@ -25,7 +25,7 @@ use error::Result;
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
/// algorithm on it
@ -45,10 +45,8 @@ pub fn hash_path(pb: &PathBuf) -> Result<String> {
/// Read the reference from a file
pub fn read_reference(refentry: &Entry) -> Result<PathBuf> {
refentry.get_header()
.read("ref.path")?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))?
.as_str()
.ok_or(RE::from_kind(REK::HeaderTypeError))
.read_string("ref.path")?
.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
.map(PathBuf::from)
}

View file

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

View file

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

View file

@ -21,7 +21,7 @@ use error::EntryUtilError as EUE;
use error::Result;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt;
/// 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> {
let field = T::kindflag_header_location();
match self.get_header().read(field) {
Ok(Some(&Value::Boolean(b))) => Ok(b),
Ok(Some(_)) => Err(format!("Field {} has not a boolean type", field)).map_err(EUE::from),
Ok(None) => Err(format!("Field {} not available", field)).map_err(EUE::from),
Err(e) => Err(EUE::from(e))
match self.get_header().read_bool(field)? {
Some(b) => Ok(b),
None => Err(format!("Field {} not available", field)).map_err(EUE::from),
}
}