Remove all Atomic hook commands from every event list in a group, dropping emptied matcher groups and empty event lists.
(group: &mut Value)
| 1218 | /// Remove all Atomic hook commands from every event list in a group, |
| 1219 | /// dropping emptied matcher groups and empty event lists. |
| 1220 | fn remove_atomic_commands(group: &mut Value) { |
| 1221 | let Some(obj) = group.as_object_mut() else { |
| 1222 | return; |
| 1223 | }; |
| 1224 | |
| 1225 | let events: Vec<String> = obj.keys().cloned().collect(); |
| 1226 | for event in events { |
| 1227 | let Some(list) = obj.get_mut(&event).and_then(Value::as_array_mut) else { |
| 1228 | continue; |
| 1229 | }; |
| 1230 | |
| 1231 | // Matcher-wrapped lists: clean each group's hooks. |
| 1232 | for item in list.iter_mut() { |
| 1233 | if let Some(hooks) = item.get_mut("hooks").and_then(Value::as_array_mut) { |
| 1234 | hooks.retain(|handler| { |
| 1235 | !handler |
| 1236 | .get("command") |
| 1237 | .and_then(Value::as_str) |
| 1238 | .is_some_and(is_atomic_command) |
| 1239 | }); |
| 1240 | } |
| 1241 | } |
| 1242 | // Drop emptied matcher groups. |
| 1243 | list.retain(|item| match item.get("hooks").and_then(Value::as_array) { |
| 1244 | Some(hooks) => !hooks.is_empty(), |
| 1245 | None => true, |
| 1246 | }); |
| 1247 | // Direct handler lists: drop Atomic handlers. |
| 1248 | list.retain(|handler| { |
| 1249 | // Keep matcher groups (handled above) and non-Atomic handlers. |
| 1250 | if handler.get("hooks").is_some() { |
| 1251 | return true; |
| 1252 | } |
| 1253 | !handler |
| 1254 | .get("command") |
| 1255 | .and_then(Value::as_str) |
| 1256 | .is_some_and(is_atomic_command) |
| 1257 | }); |
| 1258 | |
| 1259 | if list.is_empty() { |
| 1260 | obj.remove(&event); |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /// Returns `true` if the group has no remaining handlers and no keys other |
| 1266 | /// than `enabled` (a bare `enabled` flag on an empty group is meaningless). |
no test coverage detected