From 120fea2a62cd669e67267a61cb249ef880132fe3 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 5 Oct 2020 18:14:23 +0100 Subject: [PATCH] Add helper methods for running commands inside the project directory --- src/compose.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/compose.rs b/src/compose.rs index ffccbd5..587f488 100644 --- a/src/compose.rs +++ b/src/compose.rs @@ -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 { + Command::new(command) + .current_dir(self.working_directory()) + .args(arguments) + .output() + } }