ricecoder_hooks/cli/
commands.rs1#[derive(Debug, Clone)]
5pub enum HookCommand {
6 List {
8 format: Option<String>,
10 },
11
12 Inspect {
14 id: String,
16
17 format: Option<String>,
19 },
20
21 Enable {
23 id: String,
25 },
26
27 Disable {
29 id: String,
31 },
32
33 Delete {
35 id: String,
37 },
38}
39
40pub fn list_hooks() -> HookCommand {
42 HookCommand::List { format: None }
43}
44
45pub fn list_hooks_json() -> HookCommand {
47 HookCommand::List {
48 format: Some("json".to_string()),
49 }
50}
51
52pub fn inspect_hook(id: impl Into<String>) -> HookCommand {
54 HookCommand::Inspect {
55 id: id.into(),
56 format: None,
57 }
58}
59
60pub 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
68pub fn enable_hook(id: impl Into<String>) -> HookCommand {
70 HookCommand::Enable { id: id.into() }
71}
72
73pub fn disable_hook(id: impl Into<String>) -> HookCommand {
75 HookCommand::Disable { id: id.into() }
76}
77
78pub 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}