From 8e7fd6772d12b27bceba83044a698e205b78b576 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Sat, 7 May 2022 08:11:53 +0300 Subject: [PATCH] Add the --env flag (#926) #915 --- src/config.rs | 8 ++++++++ src/main.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/config.rs b/src/config.rs index 597e30ba..36e56055 100644 --- a/src/config.rs +++ b/src/config.rs @@ -396,6 +396,10 @@ pub struct CommandLineArgs { #[clap(long = "only", arg_enum)] only: Vec, + /// Set environment variables + #[clap(long = "env")] + env: Vec, + /// Output logs #[clap(short = 'v', long = "verbose")] pub verbose: bool, @@ -433,6 +437,10 @@ impl CommandLineArgs { pub fn show_config_reference(&self) -> bool { self.show_config_reference } + + pub fn env_variables(&self) -> &Vec { + &self.env + } } /// Represents the application configuration diff --git a/src/main.rs b/src/main.rs index 9d290ef9..96d7d4d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,14 @@ fn run() -> Result<()> { let base_dirs = directories::BaseDirs::new().ok_or_else(|| anyhow!("No base directories"))?; let opt = CommandLineArgs::parse(); + + for env in opt.env_variables() { + let mut splitted = env.split('='); + let var = splitted.next().unwrap(); + let value = splitted.next().unwrap(); + env::set_var(var, value); + } + let mut builder = formatted_timed_builder(); if opt.verbose {