| 478 | } |
| 479 | |
| 480 | fn add_hook_to_groups( |
| 481 | groups: &mut Vec<Value>, |
| 482 | command: &str, |
| 483 | status_message: Option<&str>, |
| 484 | timeout_sec: Option<u64>, |
| 485 | ) -> bool { |
| 486 | if groups.iter().any(|group| group_has_command(group, command)) { |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | let mut entry = Map::new(); |
| 491 | entry.insert("type".to_string(), Value::String("command".to_string())); |
| 492 | entry.insert("command".to_string(), Value::String(command.to_string())); |
| 493 | if let Some(message) = status_message { |
| 494 | entry.insert( |
| 495 | "statusMessage".to_string(), |
| 496 | Value::String(message.to_string()), |
| 497 | ); |
| 498 | } |
| 499 | if let Some(timeout) = timeout_sec { |
| 500 | entry.insert("timeout".to_string(), Value::Number(timeout.into())); |
| 501 | } |
| 502 | |
| 503 | let mut group = Map::new(); |
| 504 | group.insert( |
| 505 | "hooks".to_string(), |
| 506 | Value::Array(vec![Value::Object(entry)]), |
| 507 | ); |
| 508 | groups.push(Value::Object(group)); |
| 509 | true |
| 510 | } |
| 511 | |
| 512 | fn group_has_command(group: &Value, command: &str) -> bool { |
| 513 | group |