Support XDG_CONFIG_HOME on macOS for config directory resolution (#478)

This commit is contained in:
Thierry Delafontaine 2025-07-23 02:19:18 +02:00 committed by GitHub
parent ec88f4441e
commit 963ce3c7c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use std::env;
use std::fmt; use std::fmt;
use std::fs::File; use std::fs::File;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
@ -837,14 +838,22 @@ pub struct ApplicationSettings {
} }
impl ApplicationSettings { impl ApplicationSettings {
fn get_xdg_config_home() -> Option<PathBuf> {
env::var("XDG_CONFIG_HOME").ok().map(PathBuf::from)
}
pub fn load(cli: Iamb) -> Result<Self, Box<dyn std::error::Error>> { pub fn load(cli: Iamb) -> Result<Self, Box<dyn std::error::Error>> {
let mut config_dir = cli.config_directory.or_else(dirs::config_dir).unwrap_or_else(|| { let mut config_dir = cli
usage!( .config_directory
"No user configuration directory found;\ .or_else(Self::get_xdg_config_home)
please specify one via -C.\n\n .or_else(dirs::config_dir)
For more information try '--help'" .unwrap_or_else(|| {
); usage!(
}); "No user configuration directory found;\
please specify one via -C.\n\n
For more information try '--help'"
);
});
config_dir.push("iamb"); config_dir.push("iamb");
let config_json = config_dir.join("config.json"); let config_json = config_dir.join("config.json");