context: refactor context command running
All checks were successful
CI / build (push) Successful in 1m55s

This commit is contained in:
2025-12-17 10:05:47 +01:00
parent 35eaaaf93a
commit 106c61a096
4 changed files with 88 additions and 139 deletions

View File

@@ -1,7 +1,6 @@
use super::api::{CommandRunner, ContextDriver};
/// Local context: execute commands locally
/// Context driver: Does nothing
/// Command runner: Wrapper around 'std::process::Command'
use super::api::ContextDriver;
use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
@@ -13,13 +12,6 @@ impl ContextDriver for LocalDriver {
src.canonicalize()
}
fn create_runner(&self, program: String) -> Box<dyn CommandRunner> {
Box::new(LocalRunner {
program,
args: Vec::new(),
})
}
fn prepare_work_dir(&self) -> io::Result<String> {
// TODO: Fix that, we should not always use '..' as work directory locally
Ok("..".to_string())
@@ -37,23 +29,12 @@ impl ContextDriver for LocalDriver {
}
Ok(entries)
}
}
pub struct LocalRunner {
pub program: String,
pub args: Vec<String>,
}
impl CommandRunner for LocalRunner {
fn add_arg(&mut self, arg: String) {
self.args.push(arg);
fn run(&self, program: &str, args: &[String]) -> io::Result<std::process::ExitStatus> {
Command::new(program).args(args).status()
}
fn status(&mut self) -> io::Result<std::process::ExitStatus> {
Command::new(&self.program).args(&self.args).status()
}
fn output(&mut self) -> io::Result<std::process::Output> {
Command::new(&self.program).args(&self.args).output()
fn run_output(&self, program: &str, args: &[String]) -> io::Result<std::process::Output> {
Command::new(program).args(args).output()
}
}