summaryrefslogtreecommitdiff
path: root/src/cfg
diff options
context:
space:
mode:
Diffstat (limited to 'src/cfg')
-rw-r--r--src/cfg/config.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index 08cdbd9..750296d 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -1,4 +1,4 @@
-use serde::{Deserialize, Serialize};
+use serde::{de::Error as DeError, Deserialize, Serialize};
use std::fs;
use toml;
@@ -55,8 +55,19 @@ impl Config {
/// Parse the /etc/mesk.toml file and return the Config object.
///
/// This function reads the /etc/mesk.toml file, parses it and returns the Config object.
+ /// If the file is not available, it falls back to the `MESK_CONFIG_TOML` environment
+ /// variable containing the full TOML configuration.
pub fn parse() -> Result<Config, toml::de::Error> {
- let contents = fs::read_to_string("/etc/mesk/mesk.toml").unwrap();
+ let contents = match fs::read_to_string("/etc/mesk/mesk.toml") {
+ Ok(c) => c,
+ Err(_e) => std::env::var("MESK_CONFIG_TOML").map_err(|env_err| {
+ DeError::custom(format!(
+ "Failed to read /etc/mesk/mesk.toml and MESK_CONFIG_TOML is not set: {}",
+ env_err
+ ))
+ })?,
+ };
+
let result: Config = toml::from_str(&contents)?;
Ok(result)
}