#![allow(clippy::result_large_err)]
use serde::{Deserialize, Serialize};
use crate::{
action::{ActionError, Context},
action_impl::{spawn, ActionImpl},
};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Shell {
shell: String,
}
impl Shell {
pub fn new<S: Into<String>>(shell: S) -> Self {
let shell = shell.into();
Self { shell }
}
pub fn shell(&self) -> &str {
&self.shell
}
}
impl ActionImpl for Shell {
fn execute(&self, context: &mut Context) -> Result<(), ActionError> {
let snippet = bash_snippet(&self.shell);
spawn(context, &["bash", "-c", &snippet])?;
Ok(())
}
}
pub fn bash_snippet(snippet: &str) -> String {
format!("set -xeuo pipefail\n{snippet}\n")
}