ggen_cli_lib/cmds/hook/
remove.rs1use clap::Args;
20use ggen_utils::error::Result;
21
22#[derive(Args, Debug)]
23pub struct RemoveArgs {
24 pub name: String,
26
27 #[arg(short = 'f', long)]
29 pub force: bool,
30}
31
32pub async fn run(args: &RemoveArgs) -> Result<()> {
34 if args.name.trim().is_empty() {
36 return Err(ggen_utils::error::Error::new("Hook name cannot be empty"));
37 }
38
39 println!("đď¸ Removing hook '{}'...", args.name);
40
41 if !args.force {
45 println!("\nâ ď¸ This will:");
46 println!(" - Delete hook configuration");
47 println!(" - Uninstall git hooks (if applicable)");
48 println!(" - Stop file watchers (if applicable)");
49 println!(" - Remove cron jobs (if applicable)");
50 println!("\nAre you sure you want to continue? (y/N)");
51
52 println!("Proceeding with removal...");
55 }
56
57 println!(" Uninstalling hook from system...");
66 println!(" Deleting hook configuration...");
67
68 println!("\nâ
Hook '{}' removed successfully!", args.name);
69
70 Ok(())
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[tokio::test]
78 async fn test_remove_hook_basic() {
79 let args = RemoveArgs {
80 name: "test-hook".to_string(),
81 force: true, };
83 let result = run(&args).await;
84 assert!(result.is_ok());
85 }
86
87 #[tokio::test]
88 async fn test_remove_hook_empty_name() {
89 let args = RemoveArgs {
90 name: "".to_string(),
91 force: true,
92 };
93 let result = run(&args).await;
94 assert!(result.is_err());
95 }
96
97 #[tokio::test]
98 async fn test_remove_hook_with_force() {
99 let args = RemoveArgs {
100 name: "test-hook".to_string(),
101 force: true,
102 };
103 let result = run(&args).await;
104 assert!(result.is_ok());
105 }
106}