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:
45
src/context/local.rs
Normal file
45
src/context/local.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user