From 43c76fa120b02ac3a89f9bfe0b763a05817748bc Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sat, 16 Oct 2021 17:34:27 +0200 Subject: [PATCH] Accept environment variables in configuration --- src/data/config.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/data/config.rs b/src/data/config.rs index ab6d21f..a4f5c78 100644 --- a/src/data/config.rs +++ b/src/data/config.rs @@ -60,7 +60,7 @@ static mut CONF: Option = None; impl Config { fn yaml_str(parsed: &Yaml, name: &str) -> String { - match &parsed[name] { + let val = match &parsed[name] { Yaml::Real(r) | Yaml::String(r) => r.to_string(), Yaml::Integer(i) => i.to_string(), Yaml::Boolean(true) => "true".to_string(), @@ -71,7 +71,14 @@ impl Config { Yaml::BadValue => { panic!("{} is missing", name); } - }.to_string() + }.to_string(); + + // Check if we have to get an environment variable + if val.starts_with("$") { + std::env::var(&val[1..]).unwrap() + } else { + val + } } fn yaml_u64(parsed: &Yaml, name: &str) -> u64 {