Add the --env flag (#926)

#915
This commit is contained in:
Roey Darwish Dror
2022-05-07 08:11:53 +03:00
committed by GitHub
parent 84c3a0f4d1
commit 8e7fd6772d
2 changed files with 16 additions and 0 deletions

View File

@@ -396,6 +396,10 @@ pub struct CommandLineArgs {
#[clap(long = "only", arg_enum)] #[clap(long = "only", arg_enum)]
only: Vec<Step>, only: Vec<Step>,
/// Set environment variables
#[clap(long = "env")]
env: Vec<String>,
/// Output logs /// Output logs
#[clap(short = 'v', long = "verbose")] #[clap(short = 'v', long = "verbose")]
pub verbose: bool, pub verbose: bool,
@@ -433,6 +437,10 @@ impl CommandLineArgs {
pub fn show_config_reference(&self) -> bool { pub fn show_config_reference(&self) -> bool {
self.show_config_reference self.show_config_reference
} }
pub fn env_variables(&self) -> &Vec<String> {
&self.env
}
} }
/// Represents the application configuration /// Represents the application configuration

View File

@@ -39,6 +39,14 @@ fn run() -> Result<()> {
let base_dirs = directories::BaseDirs::new().ok_or_else(|| anyhow!("No base directories"))?; let base_dirs = directories::BaseDirs::new().ok_or_else(|| anyhow!("No base directories"))?;
let opt = CommandLineArgs::parse(); 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(); let mut builder = formatted_timed_builder();
if opt.verbose { if opt.verbose {