pub mod error;
pub mod generator;
pub mod templates;
pub use error::{Error, Result};
pub use generator::HookGenerator;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShellType {
Bash,
Zsh,
Fish,
PowerShell,
}
impl std::fmt::Display for ShellType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ShellType::Bash => write!(f, "bash"),
ShellType::Zsh => write!(f, "zsh"),
ShellType::Fish => write!(f, "fish"),
ShellType::PowerShell => write!(f, "powershell"),
}
}
}
impl std::str::FromStr for ShellType {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s.to_lowercase().as_str() {
"bash" => Ok(ShellType::Bash),
"zsh" => Ok(ShellType::Zsh),
"fish" => Ok(ShellType::Fish),
"powershell" | "pwsh" => Ok(ShellType::PowerShell),
_ => Err(Error::UnsupportedShell(s.to_string())),
}
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct HookConfig {
pub shell_type: String,
pub auto_commands: Vec<String>,
pub default_source: Option<String>,
pub auto_collect_all: bool,
pub cstats_path: Option<String>,
pub env_vars: std::collections::HashMap<String, String>,
}
impl Default for HookConfig {
fn default() -> Self {
Self {
shell_type: "bash".to_string(),
auto_commands: vec![
"git".to_string(),
"cargo".to_string(),
"make".to_string(),
"npm".to_string(),
"yarn".to_string(),
],
default_source: None,
auto_collect_all: false,
cstats_path: None,
env_vars: std::collections::HashMap::new(),
}
}
}