2025-10-11 14:35:29 -07:00
|
|
|
use crate::context::SproutContext;
|
|
|
|
|
use anyhow::{Result, bail};
|
2025-10-11 14:11:31 -07:00
|
|
|
use serde::{Deserialize, Serialize};
|
2025-10-04 23:12:01 -07:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
|
|
pub mod chainload;
|
2025-10-14 22:36:22 -07:00
|
|
|
pub mod edera;
|
2025-10-05 00:09:53 -07:00
|
|
|
pub mod print;
|
2025-10-04 23:12:01 -07:00
|
|
|
|
2025-10-05 03:12:00 -07:00
|
|
|
#[cfg(feature = "splash")]
|
|
|
|
|
pub mod splash;
|
|
|
|
|
|
2025-10-11 14:11:31 -07:00
|
|
|
#[derive(Serialize, Deserialize, Default, Clone)]
|
|
|
|
|
pub struct ActionDeclaration {
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub chainload: Option<chainload::ChainloadConfiguration>,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub print: Option<print::PrintConfiguration>,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
#[cfg(feature = "splash")]
|
|
|
|
|
pub splash: Option<splash::SplashConfiguration>,
|
2025-10-14 22:36:22 -07:00
|
|
|
#[serde(default, rename = "edera")]
|
|
|
|
|
pub edera: Option<edera::EderaConfiguration>,
|
2025-10-11 14:11:31 -07:00
|
|
|
}
|
|
|
|
|
|
2025-10-11 14:35:29 -07:00
|
|
|
pub fn execute(context: Rc<SproutContext>, name: impl AsRef<str>) -> Result<()> {
|
2025-10-05 00:09:53 -07:00
|
|
|
let Some(action) = context.root().actions().get(name.as_ref()) else {
|
2025-10-11 14:35:29 -07:00
|
|
|
bail!("unknown action '{}'", name.as_ref());
|
2025-10-05 00:09:53 -07:00
|
|
|
};
|
2025-10-04 23:12:01 -07:00
|
|
|
let context = context.finalize().freeze();
|
|
|
|
|
|
|
|
|
|
if let Some(chainload) = &action.chainload {
|
2025-10-11 14:35:29 -07:00
|
|
|
chainload::chainload(context.clone(), chainload)?;
|
|
|
|
|
return Ok(());
|
2025-10-05 00:09:53 -07:00
|
|
|
} else if let Some(print) = &action.print {
|
2025-10-11 14:35:29 -07:00
|
|
|
print::print(context.clone(), print)?;
|
|
|
|
|
return Ok(());
|
2025-10-14 22:36:22 -07:00
|
|
|
} else if let Some(edera) = &action.edera {
|
|
|
|
|
edera::edera(context.clone(), edera)?;
|
2025-10-05 03:12:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "splash")]
|
|
|
|
|
if let Some(splash) = &action.splash {
|
2025-10-11 14:35:29 -07:00
|
|
|
splash::splash(context.clone(), splash)?;
|
|
|
|
|
return Ok(());
|
2025-10-04 23:12:01 -07:00
|
|
|
}
|
2025-10-05 03:12:00 -07:00
|
|
|
|
2025-10-11 14:35:29 -07:00
|
|
|
bail!("unknown action configuration");
|
2025-10-04 23:12:01 -07:00
|
|
|
}
|