1pub mod error;
8pub mod generator;
9pub mod templates;
10
11pub use error::{Error, Result};
12pub use generator::HookGenerator;
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum ShellType {
17 Bash,
19 Zsh,
21 Fish,
23 PowerShell,
25}
26
27impl std::fmt::Display for ShellType {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 match self {
30 ShellType::Bash => write!(f, "bash"),
31 ShellType::Zsh => write!(f, "zsh"),
32 ShellType::Fish => write!(f, "fish"),
33 ShellType::PowerShell => write!(f, "powershell"),
34 }
35 }
36}
37
38impl std::str::FromStr for ShellType {
39 type Err = Error;
40
41 fn from_str(s: &str) -> Result<Self> {
42 match s.to_lowercase().as_str() {
43 "bash" => Ok(ShellType::Bash),
44 "zsh" => Ok(ShellType::Zsh),
45 "fish" => Ok(ShellType::Fish),
46 "powershell" | "pwsh" => Ok(ShellType::PowerShell),
47 _ => Err(Error::UnsupportedShell(s.to_string())),
48 }
49 }
50}
51
52#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
54pub struct HookConfig {
55 pub shell_type: String,
57
58 pub auto_commands: Vec<String>,
60
61 pub default_source: Option<String>,
63
64 pub auto_collect_all: bool,
66
67 pub cstats_path: Option<String>,
69
70 pub env_vars: std::collections::HashMap<String, String>,
72}
73
74impl Default for HookConfig {
75 fn default() -> Self {
76 Self {
77 shell_type: "bash".to_string(),
78 auto_commands: vec![
79 "git".to_string(),
80 "cargo".to_string(),
81 "make".to_string(),
82 "npm".to_string(),
83 "yarn".to_string(),
84 ],
85 default_source: None,
86 auto_collect_all: false,
87 cstats_path: None,
88 env_vars: std::collections::HashMap::new(),
89 }
90 }
91}