modify default_config_paths to respect XDG_CONFIG_HOME; remove unnecessary comments; fmt

This commit is contained in:
2026-03-19 18:18:15 +03:00
parent 48ef5cb3b8
commit 63209cefc2

View File

@@ -5,7 +5,7 @@ use std::path::PathBuf;
const CONFIG_FILENAME: &str = "bot.yml";
const APP_NAME: &str = "deltachat-remotecontrol-bot";
const APP_DIR: &str = APP_NAME;
const APP_CONFIG_DIR: &str = APP_NAME;
/// Delta Chat bot for remote control of local network machines.
#[derive(Parser)]
@@ -19,21 +19,25 @@ struct Args {
config: Option<PathBuf>,
}
/// Returns the ordered list of default config paths to try when `-c` is not given.
/// The home-directory entry is omitted if $HOME is not set.
fn default_config_paths() -> Vec<PathBuf> {
let mut paths = vec![PathBuf::from(CONFIG_FILENAME)];
if let Ok(home) = std::env::var("HOME") {
if let Ok(config_home) = std::env::var("XDG_CONFIG_HOME")
.map(|c| PathBuf::from(c))
.or(std::env::var("HOME").map(|home| PathBuf::from(home).join(".config")))
{
paths.push(
PathBuf::from(home)
.join(".config")
.join(APP_DIR)
PathBuf::from(config_home)
.join(APP_CONFIG_DIR)
.join(CONFIG_FILENAME),
);
}
paths.push(PathBuf::from("/etc").join(APP_DIR).join(CONFIG_FILENAME));
paths.push(
PathBuf::from("/etc")
.join(APP_CONFIG_DIR)
.join(CONFIG_FILENAME),
);
paths
}