Skip to content

Commit

Permalink
feat: log running command
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael DEMACON <[email protected]>
  • Loading branch information
quantumsheep committed Feb 21, 2024
1 parent b6f7074 commit 2c86d67
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ impl Host {
/// Will panic if the regex cannot be compiled.
pub fn run_command_template(&self, pattern: &str) -> Result<(), Box<dyn Error>> {
let handlebars = Handlebars::new();
let command = handlebars.render_template(pattern, &self)?;
let rendered_command = handlebars.render_template(pattern, &self)?;

let mut args = shlex::split(&command)
.ok_or(format!("Failed to parse command: {command}"))?
println!("Running command: {rendered_command}");

let mut args = shlex::split(&rendered_command)
.ok_or(format!("Failed to parse command: {rendered_command}"))?
.into_iter()
.collect::<VecDeque<String>>();
let command = args.pop_front().ok_or("Failed to get command")?;

Command::new(command).args(args).spawn()?.wait()?;
let status = Command::new(command).args(args).spawn()?.wait()?;
if !status.success() {
std::process::exit(status.code().unwrap_or(1));
}

Ok(())
}
Expand Down

0 comments on commit 2c86d67

Please sign in to comment.