summaryrefslogtreecommitdiff
path: root/src/cfg
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-12-01 16:14:03 +0300
committerNamilskyy <alive6863@gmail.com>2025-12-01 16:14:03 +0300
commit26207917ec6b1011eb8348c9a05d31be3a6a2d9f (patch)
treec35a1f24df842357c7258788b0cb10cd9b791ceb /src/cfg
parentd979b6da3622b458922a7a57b3e7aaf18fcab291 (diff)
Added the ability to transfer config through an environment variable
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)
}