nextest_runner/user_config/
discovery.rs1use crate::errors::UserConfigError;
7use camino::Utf8PathBuf;
8use etcetera::{BaseStrategy, HomeDirError, base_strategy::Xdg};
9
10pub fn user_config_paths() -> Result<Vec<Utf8PathBuf>, UserConfigError> {
22 let mut paths = Vec::new();
23
24 #[cfg(windows)]
26 if let Some(path) = native_config_path()? {
27 paths.push(path);
28 }
29
30 if let Some(path) = xdg_config_path()? {
32 paths.push(path);
33 }
34
35 Ok(paths)
36}
37
38fn xdg_config_path() -> Result<Option<Utf8PathBuf>, UserConfigError> {
44 let strategy = match Xdg::new() {
45 Ok(s) => s,
46 Err(HomeDirError) => return Ok(None),
47 };
48
49 let config_dir = strategy.config_dir().join("nextest");
50 let config_path = config_dir.join("config.toml");
51
52 Utf8PathBuf::try_from(config_path)
53 .map(Some)
54 .map_err(|error| UserConfigError::NonUtf8Path { error })
55}
56
57#[cfg(windows)]
59fn native_config_path() -> Result<Option<Utf8PathBuf>, UserConfigError> {
60 use etcetera::base_strategy::Windows;
61
62 let strategy = match Windows::new() {
63 Ok(s) => s,
64 Err(HomeDirError) => return Ok(None),
65 };
66
67 let config_dir = strategy.config_dir().join("nextest");
68 let config_path = config_dir.join("config.toml");
69
70 Utf8PathBuf::try_from(config_path)
71 .map(Some)
72 .map_err(|error| UserConfigError::NonUtf8Path { error })
73}