Add a handler to a direct handler list (`PreInvocation`, `Stop`, ...). Returns `true` if the handler was added (i.e., no Atomic handler with the same command was already present).
(group: &mut Value, event: &str, command: &str)
| 1149 | /// Returns `true` if the handler was added (i.e., no Atomic handler with the |
| 1150 | /// same command was already present). |
| 1151 | fn add_direct_handler(group: &mut Value, event: &str, command: &str) -> bool { |
| 1152 | let Some(obj) = group.as_object_mut() else { |
| 1153 | return false; |
| 1154 | }; |
| 1155 | |
| 1156 | let entry = obj |
| 1157 | .entry(event.to_string()) |
| 1158 | .or_insert_with(|| Value::Array(Vec::new())); |
| 1159 | let Some(list) = entry.as_array_mut() else { |
| 1160 | return false; |
| 1161 | }; |
| 1162 | |
| 1163 | if event_list_has_atomic(list) { |
| 1164 | return false; |
| 1165 | } |
| 1166 | |
| 1167 | let mut handler = Map::new(); |
| 1168 | handler.insert("type".to_string(), Value::String("command".to_string())); |
| 1169 | handler.insert("command".to_string(), Value::String(command.to_string())); |
| 1170 | list.push(Value::Object(handler)); |
| 1171 | true |
| 1172 | } |
| 1173 | |
| 1174 | /// Add a handler inside a matcher group (`PreToolUse`, `PostToolUse`). |
| 1175 | /// |
no test coverage detected