1use std::path::PathBuf;
5
6const CONFIG_DIR_ENV: &str = "SQUIGIT_CONFIG_DIR";
7
8#[cfg(target_os = "linux")]
9const APP_DIR_NAME: &str = "squigit";
10
11#[cfg(not(target_os = "linux"))]
12const APP_DIR_NAME: &str = "Squigit";
13
14pub fn base_config_dir() -> Option<PathBuf> {
19 resolve_base_config_dir(
20 std::env::var_os(CONFIG_DIR_ENV).map(PathBuf::from),
21 dirs::config_dir(),
22 )
23}
24
25fn resolve_base_config_dir(
26 override_dir: Option<PathBuf>,
27 system_config_dir: Option<PathBuf>,
28) -> Option<PathBuf> {
29 override_dir
30 .filter(|path| !path.as_os_str().is_empty())
31 .or_else(|| system_config_dir.map(|path| path.join(APP_DIR_NAME)))
32}