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