shrub_rs/models/
commands.rs1use crate::models::builtin::BuiltInCommand;
8use crate::models::params::ParamValue;
9use serde::{Deserialize, Serialize};
10use std::collections::HashMap;
11
12#[derive(Debug, Serialize, Deserialize, Clone)]
13pub struct FunctionCall {
14 pub func: String,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub vars: Option<HashMap<String, ParamValue>>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub timeout_secs: Option<u64>,
19}
20
21#[derive(Debug, Serialize, Deserialize, Clone)]
22#[serde(untagged)]
23pub enum EvgCommand {
24 Function(FunctionCall),
25 BuiltIn(BuiltInCommand),
26}
27
28pub fn fn_call(name: &str) -> EvgCommand {
29 EvgCommand::Function(FunctionCall {
30 func: name.to_string(),
31 vars: None,
32 timeout_secs: None,
33 })
34}
35
36pub fn fn_call_with_params(name: &str, vars: HashMap<String, ParamValue>) -> EvgCommand {
37 EvgCommand::Function(FunctionCall {
38 func: String::from(name),
39 vars: Some(vars),
40 timeout_secs: None,
41 })
42}
43
44impl From<&str> for EvgCommand {
45 fn from(item: &str) -> EvgCommand {
46 fn_call(item)
47 }
48}