Add helper to check whether committing is enabled

This commit is contained in:
Matthias Beyer 2016-09-20 15:33:55 +02:00
parent 1509e074f8
commit 5b7ff231a9

View file

@ -195,3 +195,20 @@ pub fn is_enabled(cfg: &Value) -> bool {
get_bool_cfg(Some(cfg), "enabled", true, true)
}
/// 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)
}