1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
use serde::{Deserialize, Serialize}; use crate::commands::execution::{ActionExecution, ActionResult, ActionValue}; use crate::commands::Command; use crate::context::PicoContext; use crate::rules::PicoRules; use crate::runtime::PicoRuntime; #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum Action { Command(Command), Commands(Vec<Command>), } impl ActionExecution for Action { fn run_with_context( &self, pico_rules: &PicoRules, runtime: &mut PicoRuntime, ctx: &mut PicoContext, ) -> ActionResult { match self { Action::Command(command) => command.run_with_context(pico_rules, runtime, ctx), Action::Commands(commands) => { for command in commands { debug!("Running a command {:?}", command); let result = command.run_with_context(pico_rules, runtime, ctx)?; debug!("result: {:?}", result); match result { ActionValue::Stop(stopping_reason) => { info!("Action collection terminated {:?}", stopping_reason); return Ok(ActionValue::Stop(stopping_reason)); } ActionValue::Continue => {} ActionValue::Setting(_value) => {} ActionValue::BreakTo(breakto) => { info!("result breaks to {:?}", breakto); return Ok(ActionValue::BreakTo(breakto)); } } } Ok(ActionValue::Continue) } } } }