cstats-hook 0.1.1

Hook generation for cstats shell integration
Documentation
//! # cstats-hook
//!
//! Hook generation library for shell integration with cstats.
//! Provides templates and utilities for generating shell hooks that enable
//! automatic statistics collection for command executions.

pub mod error;
pub mod generator;
pub mod templates;

pub use error::{Error, Result};
pub use generator::HookGenerator;

/// Supported shell types for hook generation
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShellType {
    /// Bash shell
    Bash,
    /// Zsh shell  
    Zsh,
    /// Fish shell
    Fish,
    /// PowerShell
    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())),
        }
    }
}

/// Hook configuration options
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct HookConfig {
    /// Shell type for the hook
    pub shell_type: String,

    /// Commands to automatically wrap with cstats collection
    pub auto_commands: Vec<String>,

    /// Default source identifier for the shell
    pub default_source: Option<String>,

    /// Enable automatic collection for all commands
    pub auto_collect_all: bool,

    /// Custom cstats binary path
    pub cstats_path: Option<String>,

    /// Additional environment variables to set
    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(),
        }
    }
}