mirror of
https://github.com/youwen5/iamb.git
synced 2025-08-04 11:38:28 -07:00
Support XDG_CONFIG_HOME
on macOS for config directory resolution (#478)
This commit is contained in:
parent
ec88f4441e
commit
963ce3c7c2
1 changed files with 16 additions and 7 deletions
|
@ -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,8 +838,16 @@ 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
|
||||||
|
.config_directory
|
||||||
|
.or_else(Self::get_xdg_config_home)
|
||||||
|
.or_else(dirs::config_dir)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
usage!(
|
usage!(
|
||||||
"No user configuration directory found;\
|
"No user configuration directory found;\
|
||||||
please specify one via -C.\n\n
|
please specify one via -C.\n\n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue