Skip to main content

lmn_core/command/
mod.rs

1use crate::execution::RunStats;
2use crate::http::BodyFormat;
3
4pub mod configure_template;
5pub mod method;
6pub mod run;
7
8pub use method::HttpMethod;
9
10pub use configure_template::ConfigureTemplateCommand;
11
12#[allow(async_fn_in_trait)]
13pub trait Command {
14    async fn execute(self) -> Result<Option<RunStats>, Box<dyn std::error::Error>>;
15}
16
17pub enum Body {
18    Formatted { content: String, format: BodyFormat },
19}
20
21impl From<Body> for String {
22    fn from(body: Body) -> String {
23        match body {
24            Body::Formatted { content, format: _ } => content,
25        }
26    }
27}
28
29pub enum Commands {
30    Run(run::RunCommand),
31    ConfigureRequest(ConfigureTemplateCommand),
32    ConfigureResponse(ConfigureTemplateCommand),
33}
34
35impl Command for Commands {
36    async fn execute(self) -> Result<Option<RunStats>, Box<dyn std::error::Error>> {
37        match self {
38            Commands::Run(cmd) => cmd.execute().await,
39            Commands::ConfigureRequest(cmd) => cmd.execute().await,
40            Commands::ConfigureResponse(cmd) => cmd.execute().await,
41        }
42    }
43}