use ggen_utils::error::Result;
use serde::{Deserialize, Serialize};
use super::{HookResult, HookStatus};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RemoveInput {
pub hook_id: String,
pub force: bool,
}
pub async fn execute_remove(input: RemoveInput) -> Result<HookResult> {
use dirs::home_dir;
use std::fs;
if !input.force {
return Err(ggen_utils::error::Error::new(
"Use force flag to confirm removal",
));
}
let hooks_dir = home_dir()
.ok_or_else(|| ggen_utils::error::Error::new("Home directory not found"))?
.join(".ggen")
.join("hooks");
let hook_file = hooks_dir.join(format!("{}.json", input.hook_id));
if !hook_file.exists() {
return Err(ggen_utils::error::Error::new(&format!(
"Hook not found: {}",
input.hook_id
)));
}
fs::remove_file(&hook_file)
.map_err(|e| ggen_utils::error::Error::new(&format!("Failed to remove hook: {}", e)))?;
Ok(HookResult {
hook_id: input.hook_id,
status: HookStatus::Removed,
})
}