use crate::cli::RunCmd;
use crate::util::colored_print::{print_error, print_success};
pub mod commit_msg;
pub fn init(hook: &str, force: bool) -> Result<(), String> {
match hook {
"commit-msg" => {
commit_msg::init(force)?;
}
_ => {
return Err(
std::io::Error::new(std::io::ErrorKind::InvalidInput, "unknown hook").to_string(),
);
}
}
Ok(())
}
pub fn install(hook: &str, force: bool) -> Result<(), String> {
match hook {
"commit-msg" => {
commit_msg::install(force)?;
}
_ => {
return Err(
std::io::Error::new(std::io::ErrorKind::InvalidInput, "unknown hook").to_string(),
);
}
}
Ok(())
}
pub fn uninstall(hook: &str) -> Result<(), String> {
match hook {
"commit-msg" => {
commit_msg::uninstall()?;
}
_ => {
return Err(
std::io::Error::new(std::io::ErrorKind::InvalidInput, "unknown hook").to_string(),
);
}
}
Ok(())
}
pub fn run_hook(hook: &RunCmd) -> Result<(), String> {
match hook {
RunCmd::CommitMsg { msg, rule } => {
if let Err(e) = commit_msg::run(msg, rule) {
print_error(&e);
std::process::exit(1);
}
print_success("commit-msg validation passed");
std::process::exit(0);
}
_ => Err(format!("unsupported hook: {:?}", hook)),
}
}