Skip to content

Commit 2a8f3ea

Browse files
committed
Make it possible to use env. variables in config.
If there is an env. variable FOO=bar, then we replace $FOO with bar in the configuration.
1 parent 9f421a0 commit 2a8f3ea

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs;
1+
use std::{env, fs};
22

33
use anyhow::Result;
44
use serde::Deserialize;
@@ -83,6 +83,11 @@ impl Configuration {
8383
});
8484
}
8585

86+
// Replace environment variables in config.
87+
for (k, v) in env::vars() {
88+
content = content.replace(&format!("${}", k), &v);
89+
}
90+
8691
let config: Configuration = match toml::from_str(&content) {
8792
Ok(v) => v,
8893
Err(err) => return Err(anyhow!("parse config file error: {}", err)),

0 commit comments

Comments
 (0)