From 26207917ec6b1011eb8348c9a05d31be3a6a2d9f Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Mon, 1 Dec 2025 16:14:03 +0300 Subject: Added the ability to transfer config through an environment variable --- src/cfg/config.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/cfg') 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 { - 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) } -- cgit v1.2.3