2022-08-10 16:46:56 +02:00
|
|
|
use std::{
|
|
|
|
io::{BufRead, BufReader},
|
|
|
|
process::{Command, Stdio},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct ShellAction {
|
|
|
|
path: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShellAction {
|
|
|
|
pub fn new(path: String) -> Self {
|
|
|
|
Self { path }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn execute(self) -> 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
|
|
|
"
|
|
|
|
===
|
|
|
|
Starting running shell action: {}
|
|
|
|
===
|
|
|
|
",
|
|
|
|
self.path.clone()
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut process = Command::new(self.path)
|
|
|
|
.current_dir(".")
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.stderr(Stdio::piped())
|
|
|
|
.spawn()?;
|
|
|
|
|
|
|
|
{
|
|
|
|
let stdout = process.stdout.as_mut().unwrap();
|
|
|
|
let stdout_reader = BufReader::new(stdout);
|
|
|
|
let mut stdout_lines = stdout_reader.lines();
|
|
|
|
while let Some(Ok(line)) = stdout_lines.next() {
|
2022-08-10 17:33:31 +02:00
|
|
|
log::info!("{}", line)
|
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
|
|
|
"
|
|
|
|
===
|
|
|
|
Finished running shell action
|
|
|
|
===
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|