2022-08-11 02:03:19 +02:00
|
|
|
use std::process::Command;
|
2022-08-10 16:46:56 +02:00
|
|
|
|
2022-08-11 02:03:19 +02:00
|
|
|
use crate::cli::CuddleVariable;
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2022-08-10 16:46:56 +02:00
|
|
|
pub struct ShellAction {
|
|
|
|
path: String,
|
2022-08-10 17:55:56 +02:00
|
|
|
name: String,
|
2022-08-10 16:46:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ShellAction {
|
2022-08-10 17:55:56 +02:00
|
|
|
pub fn new(name: String, path: String) -> Self {
|
|
|
|
Self { path, name }
|
2022-08-10 16:46:56 +02:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:03:19 +02:00
|
|
|
pub fn execute(self, variables: Vec<CuddleVariable>) -> anyhow::Result<()> {
|
2022-08-10 17:33:31 +02:00
|
|
|
log::debug!("executing shell action: {}", self.path.clone());
|
2022-08-10 16:46:56 +02:00
|
|
|
|
2022-08-10 17:33:31 +02:00
|
|
|
log::info!(
|
2022-08-10 16:46:56 +02:00
|
|
|
"
|
2022-08-10 17:55:56 +02:00
|
|
|
|
2022-08-10 16:46:56 +02:00
|
|
|
===
|
|
|
|
Starting running shell action: {}
|
|
|
|
===
|
|
|
|
",
|
|
|
|
self.path.clone()
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut process = Command::new(self.path)
|
|
|
|
.current_dir(".")
|
2022-08-11 02:03:19 +02:00
|
|
|
.envs(variables.iter().map(|v| {
|
|
|
|
log::trace!("{:?}", v);
|
2022-08-10 16:46:56 +02:00
|
|
|
|
2022-08-11 02:03:19 +02:00
|
|
|
(v.name.to_uppercase(), v.value.clone())
|
|
|
|
}))
|
|
|
|
.spawn()?;
|
2022-08-10 16:46:56 +02:00
|
|
|
|
|
|
|
process.wait()?;
|
|
|
|
|
2022-08-10 17:33:31 +02:00
|
|
|
log::info!(
|
2022-08-10 16:46:56 +02:00
|
|
|
"
|
2022-08-10 17:55:56 +02:00
|
|
|
|
2022-08-10 16:46:56 +02:00
|
|
|
===
|
|
|
|
Finished running shell action
|
|
|
|
===
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|