context: add context
All checks were successful
CI / build (push) Successful in 1m50s

pkh context allows to manage contexts (local, ssh) and run contextualized commands (deb)

in other words, this allows building binary packages over ssh
This commit is contained in:
2025-12-15 20:48:44 +01:00
parent ad98d9c1ab
commit 1d65d1ce31
9 changed files with 789 additions and 12 deletions

45
src/context/local.rs Normal file
View File

@@ -0,0 +1,45 @@
use super::api::{CommandRunner, ContextDriver};
/// Local context: execute commands locally
/// Context driver: Does nothing
/// Command runner: Wrapper around 'std::process::Command'
use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
pub struct LocalDriver;
impl ContextDriver for LocalDriver {
fn ensure_available(&self, src: &Path, _dest_root: &str) -> io::Result<PathBuf> {
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> {
Ok(".".to_string())
}
}
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 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()
}
}