ricecoder_cli/commands/
hooks.rs1use crate::error::{CliError, CliResult};
4use ricecoder_hooks::{HookCli, HookCommand, InMemoryHookRegistry};
5
6#[derive(Debug, Clone)]
8pub enum HooksAction {
9 List {
11 format: Option<String>,
13 },
14
15 Inspect {
17 id: String,
19
20 format: Option<String>,
22 },
23
24 Enable {
26 id: String,
28 },
29
30 Disable {
32 id: String,
34 },
35
36 Delete {
38 id: String,
40 },
41}
42
43pub struct HooksCommand {
45 action: HooksAction,
46}
47
48impl HooksCommand {
49 pub fn new(action: HooksAction) -> Self {
51 Self { action }
52 }
53
54 pub fn execute(&self) -> CliResult<()> {
56 let registry = InMemoryHookRegistry::new();
59 let mut cli = HookCli::new(registry);
60
61 let command = match &self.action {
62 HooksAction::List { format } => HookCommand::List {
63 format: format.clone(),
64 },
65 HooksAction::Inspect { id, format } => HookCommand::Inspect {
66 id: id.clone(),
67 format: format.clone(),
68 },
69 HooksAction::Enable { id } => HookCommand::Enable { id: id.clone() },
70 HooksAction::Disable { id } => HookCommand::Disable { id: id.clone() },
71 HooksAction::Delete { id } => HookCommand::Delete { id: id.clone() },
72 };
73
74 let result = cli
75 .execute(command)
76 .map_err(|e| CliError::Internal(format!("Hook command failed: {}", e)))?;
77
78 println!("{}", result);
79 Ok(())
80 }
81}
82
83#[cfg(test)]
84mod tests {
85 use super::*;
86
87 #[test]
88 fn test_hooks_list_action() {
89 let action = HooksAction::List { format: None };
90 let _cmd = HooksCommand::new(action);
91 assert!(true);
93 }
94
95 #[test]
96 fn test_hooks_inspect_action() {
97 let action = HooksAction::Inspect {
98 id: "hook1".to_string(),
99 format: None,
100 };
101 let _cmd = HooksCommand::new(action);
102 assert!(true);
104 }
105
106 #[test]
107 fn test_hooks_enable_action() {
108 let action = HooksAction::Enable {
109 id: "hook1".to_string(),
110 };
111 let _cmd = HooksCommand::new(action);
112 assert!(true);
114 }
115
116 #[test]
117 fn test_hooks_disable_action() {
118 let action = HooksAction::Disable {
119 id: "hook1".to_string(),
120 };
121 let _cmd = HooksCommand::new(action);
122 assert!(true);
124 }
125
126 #[test]
127 fn test_hooks_delete_action() {
128 let action = HooksAction::Delete {
129 id: "hook1".to_string(),
130 };
131 let _cmd = HooksCommand::new(action);
132 assert!(true);
134 }
135}