From 483c0581051aa53655b5f2a6d5c1a23e05746aa4 Mon Sep 17 00:00:00 2001 From: Jacob Kiers Date: Fri, 25 Aug 2023 22:53:46 +0200 Subject: [PATCH] Slightly better way of finding the config file It now also looks in the current working directory. Signed-off-by: Jacob Kiers --- src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7d4d9b3..c223887 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,10 +7,10 @@ use crate::servers::Server; use log::{debug, error}; use std::env; +use std::path::Path; fn main() { - let config_path = - env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string()); + let config_path = find_config(); let config = match Config::new(&config_path) { Ok(config) => config, @@ -27,3 +27,18 @@ fn main() { let _ = server.run(); error!("Server ended with errors"); } + +fn find_config() -> String { + let config_path = + env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string()); + + if Path::new(&config_path).exists() { + return config_path; + } + + if Path::new("config.yaml").exists() { + return String::from("config.yaml"); + } + + String::from("") +}