Add helper to check config whether to abort the hook failing

This helper can be used to check the configuration of the hook whether
it should abort if the repository cannot be opened.
This commit is contained in:
Matthias Beyer 2016-07-16 17:28:49 +02:00
parent af089952c8
commit 4436a294e2

View file

@ -13,3 +13,22 @@ pub fn commit_message(config: &Value, action: StoreAction) -> Option<String> {
unimplemented!() unimplemented!()
} }
} }
pub fn abort_on_repo_init_err(cfg: Option<&Value>) -> bool {
cfg.map(|cfg| {
match cfg.lookup("abort_on_repo_init_failure") {
Some(&Value::Boolean(b)) => b,
Some(_) => {
warn!("Configuration error, 'abort_on_repo_init_failure' must be a Boolean (true|false).");
warn!("Assuming 'true' now.");
true
},
None => {
debug!("No key `abort_on_repo_init_failure' - Assuming 'true'");
true
},
}
})
.unwrap_or(false)
}