ricecoder_cli/commands/
hooks.rs

1//! Hooks command handler
2
3use crate::error::{CliError, CliResult};
4use ricecoder_hooks::{HookCli, HookCommand, InMemoryHookRegistry};
5
6/// Hooks command action
7#[derive(Debug, Clone)]
8pub enum HooksAction {
9    /// List all hooks
10    List {
11        /// Output format (table or json)
12        format: Option<String>,
13    },
14
15    /// Inspect a specific hook
16    Inspect {
17        /// Hook ID
18        id: String,
19
20        /// Output format (table or json)
21        format: Option<String>,
22    },
23
24    /// Enable a hook
25    Enable {
26        /// Hook ID
27        id: String,
28    },
29
30    /// Disable a hook
31    Disable {
32        /// Hook ID
33        id: String,
34    },
35
36    /// Delete a hook
37    Delete {
38        /// Hook ID
39        id: String,
40    },
41}
42
43/// Hooks command handler
44pub struct HooksCommand {
45    action: HooksAction,
46}
47
48impl HooksCommand {
49    /// Create a new hooks command
50    pub fn new(action: HooksAction) -> Self {
51        Self { action }
52    }
53
54    /// Execute the hooks command
55    pub fn execute(&self) -> CliResult<()> {
56        // Create an in-memory registry for now
57        // In the future, this should load from configuration
58        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        // Just verify it can be created
92        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        // Just verify it can be created
103        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        // Just verify it can be created
113        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        // Just verify it can be created
123        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        // Just verify it can be created
133        assert!(true);
134    }
135}