Merge pull request #930 from matthiasbeyer/update-toml
Dependency: toml: 0.2.* -> 0.4.*
This commit is contained in:
commit
4257ec1026
25 changed files with 161 additions and 124 deletions
|
@ -9,7 +9,7 @@ language: rust
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- rust: 1.13.0
|
- rust: 1.15.0
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
cargo: true
|
cargo: true
|
||||||
|
|
|
@ -18,7 +18,7 @@ semver = "0.5.1"
|
||||||
clap = ">=2.17"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
url = "1.2"
|
url = "1.2"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
|
|
|
@ -18,7 +18,7 @@ clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
semver = "0.5"
|
semver = "0.5"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -18,7 +18,7 @@ clap = "2.*"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
semver = "0.2"
|
semver = "0.2"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
clap = ">=2.17"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
semver = "0.5"
|
semver = "0.5"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
|
|
|
@ -6,7 +6,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uuid = { version = "0.3.1", features = ["v4"] }
|
uuid = { version = "0.3.1", features = ["v4"] }
|
||||||
lazy_static = "0.1.15"
|
lazy_static = "0.1.15"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -20,7 +20,7 @@ itertools = "0.5"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
semver = "0.5.*"
|
semver = "0.5.*"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
semver = "0.5"
|
semver = "0.5"
|
||||||
url = "1.2"
|
url = "1.2"
|
||||||
rust-crypto = "0.2"
|
rust-crypto = "0.2"
|
||||||
|
|
|
@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = ">=2.17"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
prettytable-rs = "0.6.*"
|
prettytable-rs = "0.6.*"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
clap = ">=2.17"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
|
|
|
@ -15,7 +15,7 @@ homepage = "http://imag-pim.org"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
glob = "0.2"
|
glob = "0.2"
|
||||||
|
|
||||||
[dependencies.libimagrt]
|
[dependencies.libimagrt]
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
use toml::encode_str;
|
use toml::ser::to_string;
|
||||||
|
|
||||||
use viewer::Viewer;
|
use viewer::Viewer;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
@ -44,7 +44,7 @@ impl Viewer for StdoutViewer {
|
||||||
|
|
||||||
fn view_entry(&self, e: &Entry) -> Result<()> {
|
fn view_entry(&self, e: &Entry) -> Result<()> {
|
||||||
if self.view_header {
|
if self.view_header {
|
||||||
println!("{}", encode_str(e.get_header()));
|
println!("{}", to_string(e.get_header()).unwrap_or(String::from("TOML Parser error")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.view_content {
|
if self.view_content {
|
||||||
|
|
|
@ -20,7 +20,7 @@ interactor = "0.1"
|
||||||
lazy_static = "0.2.*"
|
lazy_static = "0.2.*"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
toml = "0.2.1"
|
toml = "^0.4"
|
||||||
spinner = "0.4"
|
spinner = "0.4"
|
||||||
rustyline = "1.0"
|
rustyline = "1.0"
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
semver = "0.5"
|
semver = "0.5"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -18,7 +18,7 @@ itertools = "0.5"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
rust-crypto = "0.2"
|
rust-crypto = "0.2"
|
||||||
semver = "0.5"
|
semver = "0.5"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
walkdir = "1.0.*"
|
walkdir = "1.0.*"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ generate_error_module!(
|
||||||
IOError => "IO Error",
|
IOError => "IO Error",
|
||||||
UTF8Error => "UTF8 Error",
|
UTF8Error => "UTF8 Error",
|
||||||
StoreIdError => "Error with storeid",
|
StoreIdError => "Error with storeid",
|
||||||
|
HeaderTomlError => "Error while working with TOML Header",
|
||||||
HeaderTypeError => "Header type error",
|
HeaderTypeError => "Header type error",
|
||||||
HeaderFieldMissingError => "Header field missing error",
|
HeaderFieldMissingError => "Header field missing error",
|
||||||
HeaderFieldWriteError => "Header field cannot be written",
|
HeaderFieldWriteError => "Header field cannot be written",
|
||||||
|
|
|
@ -37,11 +37,16 @@ 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> {
|
||||||
match v.lookup(key) {
|
use libimagstore::toml_ext::TomlValueExt;
|
||||||
Some(&Value::Boolean(b)) => Ok(b),
|
use error::MapErrInto;
|
||||||
|
|
||||||
|
v.read(key)
|
||||||
|
.map_err_into(REK::HeaderTomlError)
|
||||||
|
.and_then(|toml| match toml {
|
||||||
|
Some(Value::Boolean(b)) => Ok(b),
|
||||||
Some(_) => Err(REK::HeaderTypeError.into()),
|
Some(_) => Err(REK::HeaderTypeError.into()),
|
||||||
None => Err(REK::HeaderFieldMissingError.into()),
|
None => Err(REK::HeaderFieldMissingError.into()),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RefFlags {
|
Ok(RefFlags {
|
||||||
|
|
|
@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = ">=2.17"
|
clap = ">=2.17"
|
||||||
env_logger = "0.3"
|
env_logger = "0.3"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
xdg-basedir = "1.0"
|
xdg-basedir = "1.0"
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
|
|
|
@ -21,10 +21,11 @@ use std::path::PathBuf;
|
||||||
use std::result::Result as RResult;
|
use std::result::Result as RResult;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use toml::{Parser, Value};
|
use toml::Value;
|
||||||
|
|
||||||
generate_error_module!(
|
generate_error_module!(
|
||||||
generate_error_types!(ConfigError, ConfigErrorKind,
|
generate_error_types!(ConfigError, ConfigErrorKind,
|
||||||
|
TOMLParserError => "TOML Parsing error",
|
||||||
NoConfigFileFound => "No config file found",
|
NoConfigFileFound => "No config file found",
|
||||||
|
|
||||||
ConfigOverrideError => "Config override error",
|
ConfigOverrideError => "Config override error",
|
||||||
|
@ -119,7 +120,9 @@ impl Configuration {
|
||||||
use libimagutil::key_value_split::*;
|
use libimagutil::key_value_split::*;
|
||||||
use libimagutil::iter::*;
|
use libimagutil::iter::*;
|
||||||
use self::error::ConfigErrorKind as CEK;
|
use self::error::ConfigErrorKind as CEK;
|
||||||
|
use self::error::MapErrInto;
|
||||||
use libimagerror::into::IntoError;
|
use libimagerror::into::IntoError;
|
||||||
|
use libimagstore::toml_ext::TomlValueExt;
|
||||||
|
|
||||||
v.into_iter()
|
v.into_iter()
|
||||||
.map(|s| { debug!("Trying to process '{}'", s); s })
|
.map(|s| { debug!("Trying to process '{}'", s); s })
|
||||||
|
@ -133,19 +136,21 @@ impl Configuration {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|(k, v)| {
|
.map(|(k, v)| {
|
||||||
match self.config.lookup_mut(&k[..]) {
|
self.config
|
||||||
|
.read(&k[..])
|
||||||
|
.map_err_into(CEK::TOMLParserError)
|
||||||
|
.map(|toml| match toml {
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
match into_value(value, v) {
|
match into_value(value, v) {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
*value = v;
|
info!("Successfully overridden: {} = {}", k, v);
|
||||||
info!("Successfully overridden: {} = {}", k, value);
|
Ok(v)
|
||||||
Ok(())
|
|
||||||
},
|
},
|
||||||
None => Err(CEK::ConfigOverrideTypeNotMatching.into_error()),
|
None => Err(CEK::ConfigOverrideTypeNotMatching.into_error()),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => Err(CEK::ConfigOverrideKeyNotAvailable.into_error()),
|
None => Err(CEK::ConfigOverrideKeyNotAvailable.into_error()),
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
.fold_result(|i| i)
|
.fold_result(|i| i)
|
||||||
.map_err(Box::new)
|
.map_err(Box::new)
|
||||||
|
@ -158,19 +163,19 @@ impl Configuration {
|
||||||
/// Returns None if string cannot be converted.
|
/// Returns None if string cannot be converted.
|
||||||
///
|
///
|
||||||
/// Arrays and Tables are not supported and will yield `None`.
|
/// Arrays and Tables are not supported and will yield `None`.
|
||||||
fn into_value(value: &Value, s: String) -> Option<Value> {
|
fn into_value(value: Value, s: String) -> Option<Value> {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
match value {
|
match value {
|
||||||
&Value::String(_) => Some(Value::String(s)),
|
Value::String(_) => Some(Value::String(s)),
|
||||||
&Value::Integer(_) => FromStr::from_str(&s[..]).ok().map(|i| Value::Integer(i)),
|
Value::Integer(_) => FromStr::from_str(&s[..]).ok().map(|i| Value::Integer(i)),
|
||||||
&Value::Float(_) => FromStr::from_str(&s[..]).ok().map(|f| Value::Float(f)),
|
Value::Float(_) => FromStr::from_str(&s[..]).ok().map(|f| Value::Float(f)),
|
||||||
&Value::Boolean(_) => {
|
Value::Boolean(_) => {
|
||||||
if s == "true" { Some(Value::Boolean(true)) }
|
if s == "true" { Some(Value::Boolean(true)) }
|
||||||
else if s == "false" { Some(Value::Boolean(false)) }
|
else if s == "false" { Some(Value::Boolean(false)) }
|
||||||
else { None }
|
else { None }
|
||||||
}
|
}
|
||||||
&Value::Datetime(_) => Some(Value::Datetime(s)),
|
Value::Datetime(_) => Value::try_from(s).ok(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,6 +228,7 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use libimagutil::variants::generate_variants as gen_vars;
|
use libimagutil::variants::generate_variants as gen_vars;
|
||||||
|
use libimagerror::trace::trace_error;
|
||||||
|
|
||||||
let variants = vec!["config", "config.toml", "imagrc", "imagrc.toml"];
|
let variants = vec!["config", "config.toml", "imagrc", "imagrc.toml"];
|
||||||
let modifier = |base: &PathBuf, v: &'static str| {
|
let modifier = |base: &PathBuf, v: &'static str| {
|
||||||
|
@ -255,18 +261,13 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut parser = Parser::new(&content[..]);
|
match ::toml::de::from_str(&content[..]) {
|
||||||
let res = parser.parse();
|
Ok(res) => res,
|
||||||
|
Err(e) => {
|
||||||
if res.is_none() {
|
|
||||||
write!(stderr(), "Config file parser error:").ok();
|
write!(stderr(), "Config file parser error:").ok();
|
||||||
for error in parser.errors {
|
trace_error(&e);
|
||||||
write!(stderr(), "At [{}][{}] <> {}", error.lo, error.hi, error).ok();
|
|
||||||
write!(stderr(), "in: '{}'", &content[error.lo..error.hi]).ok();
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
} else {
|
}
|
||||||
res
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(|loaded| loaded.is_some())
|
.filter(|loaded| loaded.is_some())
|
||||||
|
|
|
@ -20,7 +20,7 @@ lazy_static = "0.2.*"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
semver = "0.5"
|
semver = "0.5"
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
crossbeam = "0.2.*"
|
crossbeam = "0.2.*"
|
||||||
walkdir = "1.0.*"
|
walkdir = "1.0.*"
|
||||||
|
|
|
@ -1252,7 +1252,7 @@ impl Entry {
|
||||||
/// disk).
|
/// disk).
|
||||||
pub fn to_str(&self) -> String {
|
pub fn to_str(&self) -> String {
|
||||||
format!("---\n{header}---\n{content}",
|
format!("---\n{header}---\n{content}",
|
||||||
header = ::toml::encode_str(&self.header),
|
header = ::toml::ser::to_string(&self.header).unwrap(),
|
||||||
content = self.content)
|
content = self.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1915,9 +1915,9 @@ mod store_hook_tests {
|
||||||
use self::test_hook::TestHook;
|
use self::test_hook::TestHook;
|
||||||
|
|
||||||
fn get_store_with_config() -> Store {
|
fn get_store_with_config() -> Store {
|
||||||
use toml::Parser;
|
use toml::de::from_str;
|
||||||
|
|
||||||
let cfg = Parser::new(mini_config()).parse().unwrap();
|
let cfg : ::toml::Value = from_str(mini_config()).unwrap();
|
||||||
println!("Config parsed: {:?}", cfg);
|
println!("Config parsed: {:?}", cfg);
|
||||||
Store::new(PathBuf::from("/"), Some(cfg.get("store").cloned().unwrap())).unwrap()
|
Store::new(PathBuf::from("/"), Some(cfg.get("store").cloned().unwrap())).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
use std::result::Result as RResult;
|
use std::result::Result as RResult;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use toml::{Table, Value};
|
use toml::Value;
|
||||||
|
|
||||||
use store::Result;
|
use store::Result;
|
||||||
use error::StoreError as SE;
|
use error::StoreError as SE;
|
||||||
|
@ -28,6 +28,8 @@ use error::StoreErrorKind as SEK;
|
||||||
use error::{ParserErrorKind, ParserError};
|
use error::{ParserErrorKind, ParserError};
|
||||||
use libimagerror::into::IntoError;
|
use libimagerror::into::IntoError;
|
||||||
|
|
||||||
|
type Table = BTreeMap<String, Value>;
|
||||||
|
|
||||||
pub trait TomlValueExt {
|
pub trait TomlValueExt {
|
||||||
fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<bool>;
|
fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<bool>;
|
||||||
fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<Option<Value>>;
|
fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<Option<Value>>;
|
||||||
|
@ -378,11 +380,10 @@ impl Header for Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(s: &str) -> EntryResult<Value> {
|
fn parse(s: &str) -> EntryResult<Value> {
|
||||||
use toml::Parser;
|
use toml::de::from_str;
|
||||||
|
|
||||||
let mut parser = Parser::new(s);
|
from_str(s)
|
||||||
parser.parse()
|
.map_err(|_| ParserErrorKind::TOMLParserErrors.into())
|
||||||
.ok_or(ParserErrorKind::TOMLParserErrors.into())
|
|
||||||
.and_then(verify_header_consistency)
|
.and_then(verify_header_consistency)
|
||||||
.map(Value::Table)
|
.map(Value::Table)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag"
|
||||||
homepage = "http://imag-pim.org"
|
homepage = "http://imag-pim.org"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
toml = "0.2.*"
|
toml = "^0.4"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
fs2 = "0.3"
|
fs2 = "0.3"
|
||||||
git2 = "0.5"
|
git2 = "0.5"
|
||||||
|
|
|
@ -26,8 +26,9 @@ use libimagstore::hook::accessor::HookDataAccessorProvider;
|
||||||
use libimagstore::hook::accessor::NonMutableHookDataAccessor;
|
use libimagstore::hook::accessor::NonMutableHookDataAccessor;
|
||||||
use libimagstore::hook::result::HookResult;
|
use libimagstore::hook::result::HookResult;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagstore::toml_ext::TomlValueExt;
|
||||||
use libimagentrylink::internal::InternalLinker;
|
use libimagentrylink::internal::InternalLinker;
|
||||||
|
use libimagerror::trace::trace_error;
|
||||||
|
|
||||||
mod error {
|
mod error {
|
||||||
generate_error_imports!();
|
generate_error_imports!();
|
||||||
|
@ -60,17 +61,22 @@ impl Hook for DenyDeletionOfLinkedEntriesHook {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_config(&mut self, v: &Value) {
|
fn set_config(&mut self, v: &Value) {
|
||||||
self.abort = match v.lookup("aborting") {
|
self.abort = match v.read("aborting") {
|
||||||
Some(&Value::Boolean(b)) => b,
|
Ok(Some(Value::Boolean(b))) => b,
|
||||||
Some(_) => {
|
Ok(Some(_)) => {
|
||||||
warn!("Configuration error, 'aborting' must be a Boolean (true|false).");
|
warn!("Configuration error, 'aborting' must be a Boolean (true|false).");
|
||||||
warn!("Assuming 'true' now.");
|
warn!("Assuming 'true' now.");
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
None => {
|
Ok(None) => {
|
||||||
warn!("No key 'aborting' - Assuming 'true'");
|
warn!("No key 'aborting' - Assuming 'true'");
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error parsing TOML:");
|
||||||
|
trace_error(&e);
|
||||||
|
false
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
use libimagerror::into::IntoError;
|
||||||
|
use libimagerror::trace::trace_error;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
use libimagstore::toml_ext::TomlValueExt;
|
||||||
|
|
||||||
use vcs::git::error::GitHookErrorKind as GHEK;
|
use vcs::git::error::GitHookErrorKind as GHEK;
|
||||||
use vcs::git::error::MapErrInto;
|
use vcs::git::error::MapErrInto;
|
||||||
|
@ -32,59 +34,72 @@ use git2::Repository;
|
||||||
|
|
||||||
/// Check the configuration whether we should commit interactively
|
/// Check the configuration whether we should commit interactively
|
||||||
pub fn commit_interactive(config: &Value, action: &StoreAction) -> bool {
|
pub fn commit_interactive(config: &Value, action: &StoreAction) -> bool {
|
||||||
match config.lookup("commit.interactive") {
|
match config.read("commit.interactive") {
|
||||||
Some(&Value::Boolean(b)) => b,
|
Ok(Some(Value::Boolean(b))) => b,
|
||||||
Some(_) => {
|
Ok(Some(_)) => {
|
||||||
warn!("Configuration error, 'store.hooks.stdhook_git_{}.commit.interactive' must be a Boolean.",
|
warn!("Configuration error, 'store.hooks.stdhook_git_{}.commit.interactive' must be a Boolean.",
|
||||||
action);
|
action);
|
||||||
warn!("Defaulting to commit.interactive = false");
|
warn!("Defaulting to commit.interactive = false");
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
None => {
|
Ok(None) => {
|
||||||
warn!("Unavailable configuration for");
|
warn!("Unavailable configuration for");
|
||||||
warn!("\t'store.hooks.stdhook_git_{}.commit.interactive'", action);
|
warn!("\t'store.hooks.stdhook_git_{}.commit.interactive'", action);
|
||||||
warn!("Defaulting to false");
|
warn!("Defaulting to false");
|
||||||
false
|
false
|
||||||
}
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error parsing TOML:");
|
||||||
|
trace_error(&e);
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check the configuration whether we should commit with the editor
|
/// Check the configuration whether we should commit with the editor
|
||||||
fn commit_with_editor(config: &Value, action: &StoreAction) -> bool {
|
fn commit_with_editor(config: &Value, action: &StoreAction) -> bool {
|
||||||
match config.lookup("commit.interactive_editor") {
|
match config.read("commit.interactive_editor") {
|
||||||
Some(&Value::Boolean(b)) => b,
|
Ok(Some(Value::Boolean(b))) => b,
|
||||||
Some(_) => {
|
Ok(Some(_)) => {
|
||||||
warn!("Configuration error, 'store.hooks.stdhook_git_{}.commit.interactive_editor' must be a Boolean.",
|
warn!("Configuration error, 'store.hooks.stdhook_git_{}.commit.interactive_editor' must be a Boolean.",
|
||||||
action);
|
action);
|
||||||
warn!("Defaulting to commit.interactive_editor = false");
|
warn!("Defaulting to commit.interactive_editor = false");
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
None => {
|
Ok(None) => {
|
||||||
warn!("Unavailable configuration for");
|
warn!("Unavailable configuration for");
|
||||||
warn!("\t'store.hooks.stdhook_git_{}.commit.interactive_editor'", action);
|
warn!("\t'store.hooks.stdhook_git_{}.commit.interactive_editor'", action);
|
||||||
warn!("Defaulting to false");
|
warn!("Defaulting to false");
|
||||||
false
|
false
|
||||||
}
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error parsing TOML:");
|
||||||
|
trace_error(&e);
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the commit default message
|
/// Get the commit default message
|
||||||
fn commit_default_msg<'a>(config: &'a Value, action: &'a StoreAction) -> &'a str {
|
fn commit_default_msg<'a>(config: &'a Value, action: &'a StoreAction) -> Result<String> {
|
||||||
match config.lookup("commit.message") {
|
config.read("commit.message")
|
||||||
Some(&Value::String(ref b)) => b,
|
.map(|m| match m {
|
||||||
|
Some(Value::String(b)) => String::from(b),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
warn!("Configuration error, 'store.hooks.stdhook_git_{}.commit.message' must be a String.",
|
warn!("Configuration error, 'store.hooks.stdhook_git_{}.commit.message' must be a String.",
|
||||||
action);
|
action);
|
||||||
warn!("Defaulting to commit.message = '{}'", action.as_commit_message());
|
warn!("Defaulting to commit.message = '{}'", action.as_commit_message());
|
||||||
action.as_commit_message()
|
String::from(action.as_commit_message())
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
warn!("Unavailable configuration for");
|
warn!("Unavailable configuration for");
|
||||||
warn!("\t'store.hooks.stdhook_git_{}.commit.message'", action);
|
warn!("\t'store.hooks.stdhook_git_{}.commit.message'", action);
|
||||||
warn!("Defaulting to commit.message = '{}'", action.as_commit_message());
|
warn!("Defaulting to commit.message = '{}'", action.as_commit_message());
|
||||||
action.as_commit_message()
|
String::from(action.as_commit_message())
|
||||||
}
|
},
|
||||||
}
|
})
|
||||||
|
.map_err_into(GHEK::ConfigError)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the commit template
|
/// Get the commit template
|
||||||
|
@ -129,7 +144,7 @@ pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction, id
|
||||||
Ok(ask_string("Commit Message", None, false, false, None, "> "))
|
Ok(ask_string("Commit Message", None, false, false, None, "> "))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(String::from(commit_default_msg(config, &action)))
|
commit_default_msg(config, &action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +160,10 @@ pub fn abort_on_repo_init_err(cfg: &Value) -> bool {
|
||||||
pub fn ensure_branch(cfg: Option<&Value>) -> Result<Option<String>> {
|
pub fn ensure_branch(cfg: Option<&Value>) -> Result<Option<String>> {
|
||||||
match cfg {
|
match cfg {
|
||||||
Some(cfg) => {
|
Some(cfg) => {
|
||||||
match cfg.lookup("ensure_branch") {
|
cfg.read("ensure_branch")
|
||||||
Some(&Value::String(ref s)) => Ok(Some(s.clone())),
|
.map_err_into(GHEK::ConfigError)
|
||||||
|
.and_then(|toml| match toml {
|
||||||
|
Some(Value::String(ref s)) => Ok(Some(s.clone())),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
warn!("Configuration error, 'ensure_branch' must be a String.");
|
warn!("Configuration error, 'ensure_branch' must be a String.");
|
||||||
Err(GHEK::ConfigTypeError.into_error())
|
Err(GHEK::ConfigTypeError.into_error())
|
||||||
|
@ -156,7 +173,7 @@ pub fn ensure_branch(cfg: Option<&Value>) -> Result<Option<String>> {
|
||||||
debug!("No key `ensure_branch'");
|
debug!("No key `ensure_branch'");
|
||||||
Ok(None)
|
Ok(None)
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
|
@ -170,17 +187,22 @@ pub fn do_checkout_ensure_branch(cfg: Option<&Value>) -> bool {
|
||||||
/// Helper to get a boolean value from the configuration.
|
/// Helper to get a boolean value from the configuration.
|
||||||
fn get_bool_cfg(cfg: Option<&Value>, name: &str, on_fail: bool, on_unavail: bool) -> bool {
|
fn get_bool_cfg(cfg: Option<&Value>, name: &str, on_fail: bool, on_unavail: bool) -> bool {
|
||||||
cfg.map(|cfg| {
|
cfg.map(|cfg| {
|
||||||
match cfg.lookup(name) {
|
match cfg.read(name) {
|
||||||
Some(&Value::Boolean(b)) => b,
|
Ok(Some(Value::Boolean(b))) => b,
|
||||||
Some(_) => {
|
Ok(Some(_)) => {
|
||||||
warn!("Configuration error, '{}' must be a Boolean (true|false).", name);
|
warn!("Configuration error, '{}' must be a Boolean (true|false).", name);
|
||||||
warn!("Assuming '{}' now.", on_fail);
|
warn!("Assuming '{}' now.", on_fail);
|
||||||
on_fail
|
on_fail
|
||||||
},
|
},
|
||||||
None => {
|
Ok(None) => {
|
||||||
warn!("No key '{}' - Assuming '{}'", name, on_unavail);
|
warn!("No key '{}' - Assuming '{}'", name, on_unavail);
|
||||||
on_unavail
|
on_unavail
|
||||||
},
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error parsing TOML:");
|
||||||
|
trace_error(&e);
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
|
@ -197,8 +219,10 @@ pub fn is_enabled(cfg: &Value) -> bool {
|
||||||
|
|
||||||
/// Check whether committing is enabled for a hook.
|
/// Check whether committing is enabled for a hook.
|
||||||
pub fn committing_is_enabled(cfg: &Value) -> Result<bool> {
|
pub fn committing_is_enabled(cfg: &Value) -> Result<bool> {
|
||||||
match cfg.lookup("commit.enabled") {
|
cfg.read("commit.enabled")
|
||||||
Some(&Value::Boolean(b)) => Ok(b),
|
.map_err_into(GHEK::ConfigError)
|
||||||
|
.and_then(|toml| match toml {
|
||||||
|
Some(Value::Boolean(b)) => Ok(b),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
warn!("Config setting whether committing is enabled or not has wrong type.");
|
warn!("Config setting whether committing is enabled or not has wrong type.");
|
||||||
warn!("Expected Boolean");
|
warn!("Expected Boolean");
|
||||||
|
@ -208,8 +232,7 @@ pub fn committing_is_enabled(cfg: &Value) -> Result<bool> {
|
||||||
warn!("No config setting whether committing is enabled or not.");
|
warn!("No config setting whether committing is enabled or not.");
|
||||||
Err(GHEK::NoConfigError.into_error())
|
Err(GHEK::NoConfigError.into_error())
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
.map_err_into(GHEK::ConfigError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_wt_changes_before_committing(cfg: &Value) -> bool {
|
pub fn add_wt_changes_before_committing(cfg: &Value) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue