add --show-config-path argument

This commit is contained in:
alice pellerin
2026-04-13 11:29:09 -05:00
parent 3e24d00af4
commit 00bf25b5bd
3 changed files with 28 additions and 5 deletions
+7 -4
View File
@@ -34,7 +34,7 @@ pub struct Keypress {
impl Config {
#[cfg(unix)]
fn path() -> Option<PathBuf> {
fn default_path() -> Option<PathBuf> {
env::var_os("XDG_CONFIG_HOME")
.map(PathBuf::from)
.take_if(|xdg_config_home| xdg_config_home.is_absolute())
@@ -43,14 +43,17 @@ impl Config {
}
#[cfg(windows)]
fn path() -> Option<PathBuf> {
fn default_path() -> Option<PathBuf> {
// this isn't technically the right way but it should be good enough
home_dir().map(|home| home.join("AppData").join("Roaming"))
}
pub fn path(override_path: Option<PathBuf>) -> Option<PathBuf> {
override_path.or_else(Self::default_path)
}
pub fn init(override_path: Option<PathBuf>) -> Result<Self, ConfigInitError> {
let path = override_path
.or_else(Self::path)
let path = Self::path(override_path)
.ok_or(ConfigInitError::NoConfigPath)?;
let raw_config = read_to_string(path)?;