Slightly better way of finding the config file

It now also looks in the current working directory.

Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
Jacob Kiers 2023-08-25 22:53:46 +02:00
parent 6349fc6502
commit 483c058105

View File

@ -7,10 +7,10 @@ use crate::servers::Server;
use log::{debug, error}; use log::{debug, error};
use std::env; use std::env;
use std::path::Path;
fn main() { fn main() {
let config_path = let config_path = find_config();
env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string());
let config = match Config::new(&config_path) { let config = match Config::new(&config_path) {
Ok(config) => config, Ok(config) => config,
@ -27,3 +27,18 @@ fn main() {
let _ = server.run(); let _ = server.run();
error!("Server ended with errors"); 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("")
}