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
1 changed files with 16 additions and 1 deletions

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()
}
}