Added shell action
This commit is contained in:
54
cuddle_cli/src/actions/shell.rs
Normal file
54
cuddle_cli/src/actions/shell.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
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<()> {
|
||||
println!("executing shell action: {}", self.path.clone());
|
||||
|
||||
println!(
|
||||
"
|
||||
===
|
||||
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() {
|
||||
println!("{}", line);
|
||||
}
|
||||
}
|
||||
|
||||
process.wait()?;
|
||||
|
||||
println!(
|
||||
"
|
||||
===
|
||||
Finished running shell action
|
||||
===
|
||||
"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user