ricecoder_hooks/cli/
commands.rs

1//! Hook management commands
2
3/// Hook management commands
4#[derive(Debug, Clone)]
5pub enum HookCommand {
6    /// List all hooks
7    List {
8        /// Output format (table or json)
9        format: Option<String>,
10    },
11
12    /// Inspect a specific hook
13    Inspect {
14        /// Hook ID
15        id: String,
16
17        /// Output format (table or json)
18        format: Option<String>,
19    },
20
21    /// Enable a hook
22    Enable {
23        /// Hook ID
24        id: String,
25    },
26
27    /// Disable a hook
28    Disable {
29        /// Hook ID
30        id: String,
31    },
32
33    /// Delete a hook
34    Delete {
35        /// Hook ID
36        id: String,
37    },
38}
39
40/// List all hooks
41pub fn list_hooks() -> HookCommand {
42    HookCommand::List { format: None }
43}
44
45/// List all hooks with JSON format
46pub fn list_hooks_json() -> HookCommand {
47    HookCommand::List {
48        format: Some("json".to_string()),
49    }
50}
51
52/// Inspect a hook
53pub fn inspect_hook(id: impl Into<String>) -> HookCommand {
54    HookCommand::Inspect {
55        id: id.into(),
56        format: None,
57    }
58}
59
60/// Inspect a hook with JSON format
61pub fn inspect_hook_json(id: impl Into<String>) -> HookCommand {
62    HookCommand::Inspect {
63        id: id.into(),
64        format: Some("json".to_string()),
65    }
66}
67
68/// Enable a hook
69pub fn enable_hook(id: impl Into<String>) -> HookCommand {
70    HookCommand::Enable { id: id.into() }
71}
72
73/// Disable a hook
74pub fn disable_hook(id: impl Into<String>) -> HookCommand {
75    HookCommand::Disable { id: id.into() }
76}
77
78/// Delete a hook
79pub fn delete_hook(id: impl Into<String>) -> HookCommand {
80    HookCommand::Delete { id: id.into() }
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    #[test]
88    fn test_list_hooks_command() {
89        let cmd = list_hooks();
90        match cmd {
91            HookCommand::List { format } => {
92                assert!(format.is_none());
93            }
94            _ => panic!("Expected List command"),
95        }
96    }
97
98    #[test]
99    fn test_list_hooks_json_command() {
100        let cmd = list_hooks_json();
101        match cmd {
102            HookCommand::List { format } => {
103                assert_eq!(format, Some("json".to_string()));
104            }
105            _ => panic!("Expected List command"),
106        }
107    }
108
109    #[test]
110    fn test_inspect_hook_command() {
111        let cmd = inspect_hook("hook1");
112        match cmd {
113            HookCommand::Inspect { id, format } => {
114                assert_eq!(id, "hook1");
115                assert!(format.is_none());
116            }
117            _ => panic!("Expected Inspect command"),
118        }
119    }
120
121    #[test]
122    fn test_enable_hook_command() {
123        let cmd = enable_hook("hook1");
124        match cmd {
125            HookCommand::Enable { id } => {
126                assert_eq!(id, "hook1");
127            }
128            _ => panic!("Expected Enable command"),
129        }
130    }
131
132    #[test]
133    fn test_disable_hook_command() {
134        let cmd = disable_hook("hook1");
135        match cmd {
136            HookCommand::Disable { id } => {
137                assert_eq!(id, "hook1");
138            }
139            _ => panic!("Expected Disable command"),
140        }
141    }
142
143    #[test]
144    fn test_delete_hook_command() {
145        let cmd = delete_hook("hook1");
146        match cmd {
147            HookCommand::Delete { id } => {
148                assert_eq!(id, "hook1");
149            }
150            _ => panic!("Expected Delete command"),
151        }
152    }
153}