1
Fork 0

Add helper methods for running commands inside the project directory

This commit is contained in:
Jake Howard 2020-10-05 18:14:23 +01:00
parent b83ec11e97
commit 120fea2a62
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,4 +1,6 @@
use std::path::PathBuf;
use std::io::Result;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
pub struct ComposeProject {
compose_file: PathBuf,
@ -10,4 +12,17 @@ impl ComposeProject {
compose_file: compose_file.to_owned(),
}
}
fn working_directory(&self) -> &Path {
self.compose_file
.parent()
.expect("Failed to get parent of compose file")
}
fn execute_in_dir(&self, command: &str, arguments: &[&str]) -> Result<Output> {
Command::new(command)
.current_dir(self.working_directory())
.args(arguments)
.output()
}
}