| 64 | } |
| 65 | |
| 66 | fn parse_maestro_flow_yaml(raw: &str) -> anyhow::Result<YamlValue> { |
| 67 | let mut documents = Vec::new(); |
| 68 | for document in serde_yaml::Deserializer::from_str(raw) { |
| 69 | documents.push(YamlValue::deserialize(document)?); |
| 70 | } |
| 71 | match documents.len() { |
| 72 | 0 => Err(anyhow::anyhow!("Maestro flow is empty.")), |
| 73 | 1 => Ok(documents.remove(0)), |
| 74 | _ => { |
| 75 | let app_id = documents |
| 76 | .first() |
| 77 | .and_then(|value| yaml_string_or_field(value, "appId")); |
| 78 | let mut commands = documents |
| 79 | .pop() |
| 80 | .ok_or_else(|| anyhow::anyhow!("Maestro flow is empty."))?; |
| 81 | if let Some(app_id) = app_id { |
| 82 | fill_empty_launch_app_commands(&mut commands, &app_id); |
| 83 | } |
| 84 | Ok(commands) |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | fn fill_empty_launch_app_commands(commands: &mut YamlValue, app_id: &str) { |
| 90 | let Some(commands) = commands.as_sequence_mut() else { |