2022-10-28 17:39:15 +00:00
|
|
|
//! # Hooked
|
|
|
|
//!
|
|
|
|
//! > **Git hooks manager.**
|
|
|
|
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
|
|
|
|
|
|
|
use {
|
|
|
|
clap::Parser,
|
2022-11-04 17:09:15 +00:00
|
|
|
color_eyre::{install, Result},
|
2022-10-31 14:35:10 +00:00
|
|
|
hooked_config::Config,
|
2022-10-28 17:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
use crate::cli::{Args, MainSubcommands};
|
|
|
|
|
|
|
|
/// The default template for all hooks.
|
|
|
|
pub const DEFAULT_TEMPLATE: &str = include_str!("templates/default.sh");
|
|
|
|
|
|
|
|
/// All supported hook types.
|
2022-10-30 20:14:12 +00:00
|
|
|
pub const HOOK_TYPES: [&str; 1] = ["pre-commit"];
|
2022-10-28 17:39:15 +00:00
|
|
|
|
|
|
|
mod cli;
|
2022-10-31 21:05:47 +00:00
|
|
|
mod utilities;
|
2022-10-28 17:39:15 +00:00
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
install()?;
|
|
|
|
|
|
|
|
let args = Args::parse();
|
|
|
|
let config = Config::from_toml_file(args.config)?;
|
|
|
|
|
|
|
|
match args.command {
|
2022-11-04 16:54:05 +00:00
|
|
|
MainSubcommands::Install(sub_args) => {
|
2022-11-04 17:09:15 +00:00
|
|
|
cli::hooked_install(config, sub_args)?;
|
2022-10-28 17:39:15 +00:00
|
|
|
}
|
2022-10-28 18:24:07 +00:00
|
|
|
|
2022-11-04 16:54:05 +00:00
|
|
|
MainSubcommands::Uninstall(sub_args) => {
|
2022-11-04 17:09:15 +00:00
|
|
|
cli::hooked_uninstall(config, sub_args)?;
|
2022-10-28 18:24:07 +00:00
|
|
|
}
|
2022-10-30 20:14:12 +00:00
|
|
|
|
2022-11-04 16:54:05 +00:00
|
|
|
MainSubcommands::Run(sub_args) => {
|
|
|
|
cli::hooked_run(config, sub_args.hook_type)?;
|
2022-10-30 20:14:12 +00:00
|
|
|
}
|
2022-11-06 17:44:23 +00:00
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
MainSubcommands::CliReference(sub_args) => {
|
|
|
|
cli::hooked_cli_reference(config, sub_args)?;
|
|
|
|
}
|
2022-10-28 17:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|