1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use anyhow::Result;
use clap::{Args, Subcommand};
#[derive(Args, Clone)]
pub struct HooksArgs {
/// Skip all hooks
#[arg(long, global = true)]
pub skip_all: Option<bool>,
/// Run hooks in parallel
#[arg(long, global = true)]
pub parallel: Option<bool>,
#[command(subcommand)]
pub command: Option<HooksCommands>,
}
#[derive(Subcommand, Clone)]
pub enum HooksCommands {
/// Install git hooks into the current repository
Install {
/// Specify which hooks to install (default: all)
#[arg(long, value_delimiter = ',')]
hooks: Option<Vec<String>>,
/// Overwrite existing hooks
#[arg(long)]
force: bool,
},
/// Uninstall git hooks from the current repository
Uninstall {
/// Specify which hooks to uninstall (default: all guardy hooks)
#[arg(long, value_delimiter = ',')]
hooks: Option<Vec<String>>,
/// Skip confirmation prompt
#[arg(short, long)]
yes: bool,
},
/// Run a specific hook manually for testing
Run {
/// Hook name to run
hook: String,
/// Additional arguments for the hook
args: Vec<String>,
},
/// Show hooks installation and configuration status
Status,
/// Dump hooks configuration in various formats
Dump {
/// Output format (json, yaml, toml)
#[arg(long, value_enum)]
format: Option<String>,
/// Output lefthook-compatible configuration
#[arg(long)]
lefthook: bool,
},
/// Validate hooks configuration
Validate,
}
pub async fn execute(args: HooksArgs) -> Result<()> {
match args.command {
Some(HooksCommands::Install { hooks, force }) => {
crate::hooks::install::install_hooks(force, hooks).await
}
Some(HooksCommands::Uninstall { hooks, yes }) => {
crate::hooks::uninstall::uninstall_hooks(hooks, yes).await
}
Some(HooksCommands::Run { hook, args }) => {
use crate::hooks::HookExecutor;
let executor = HookExecutor::new();
match executor.execute(&hook, &args).await {
Ok(()) => Ok(()),
Err(_) => {
// Hook already printed error details, just exit with error code
std::process::exit(1);
}
}
}
Some(HooksCommands::Status) => crate::hooks::status::hooks_status().await,
Some(HooksCommands::Dump { format, lefthook }) => {
if lefthook {
crate::hooks::dump::dump_lefthook_config().await
} else {
crate::hooks::dump::dump_hooks_config(format).await
}
}
Some(HooksCommands::Validate) => {
// TODO: Implement hooks validate functionality
crate::hooks::validate::validate_hooks_config().await
}
None => {
// Default to hooks status if no subcommand provided
crate::hooks::status::hooks_status().await
}
}
}