use crate::errors::UserConfigError;
use camino::Utf8PathBuf;
use etcetera::{BaseStrategy, HomeDirError, base_strategy::Xdg};
pub fn user_config_paths() -> Result<Vec<Utf8PathBuf>, UserConfigError> {
let mut paths = Vec::new();
#[cfg(windows)]
if let Some(path) = native_config_path()? {
paths.push(path);
}
if let Some(path) = xdg_config_path()? {
paths.push(path);
}
Ok(paths)
}
fn xdg_config_path() -> Result<Option<Utf8PathBuf>, UserConfigError> {
let strategy = match Xdg::new() {
Ok(s) => s,
Err(HomeDirError) => return Ok(None),
};
let config_dir = strategy.config_dir().join("nextest");
let config_path = config_dir.join("config.toml");
Utf8PathBuf::try_from(config_path)
.map(Some)
.map_err(|error| UserConfigError::NonUtf8Path { error })
}
#[cfg(windows)]
fn native_config_path() -> Result<Option<Utf8PathBuf>, UserConfigError> {
use etcetera::base_strategy::Windows;
let strategy = match Windows::new() {
Ok(s) => s,
Err(HomeDirError) => return Ok(None),
};
let config_dir = strategy.config_dir().join("nextest");
let config_path = config_dir.join("config.toml");
Utf8PathBuf::try_from(config_path)
.map(Some)
.map_err(|error| UserConfigError::NonUtf8Path { error })
}