use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct LocalShellExecAction {
#[serde(rename = "type")]
pub r#type: Type,
#[serde(rename = "command")]
pub command: Vec<String>,
#[serde(
rename = "timeout_ms",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub timeout_ms: Option<Option<i32>>,
#[serde(
rename = "working_directory",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub working_directory: Option<Option<String>>,
#[serde(rename = "env")]
pub env: std::collections::HashMap<String, String>,
#[serde(
rename = "user",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub user: Option<Option<String>>,
}
impl LocalShellExecAction {
pub fn new(
r#type: Type,
command: Vec<String>,
env: std::collections::HashMap<String, String>,
) -> LocalShellExecAction {
LocalShellExecAction {
r#type,
command,
timeout_ms: None,
working_directory: None,
env,
user: None,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "exec")]
Exec,
}
impl Default for Type {
fn default() -> Type {
Self::Exec
}
}
impl std::fmt::Display for LocalShellExecAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}