From a2331a257562f2123482a4f86c832bf073b45b5e Mon Sep 17 00:00:00 2001 From: PolpOnline <53786619+PolpOnline@users.noreply.github.com> Date: Wed, 3 May 2023 21:53:52 +0200 Subject: [PATCH] Add the ability to have the config file in $XDG_CONFIG_HOME/topgrade/topgrade.toml (#418) --- src/config.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 278345e3..04579a5d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -353,8 +353,15 @@ impl ConfigFile { let config_directory = config_directory(); let config_path = config_directory.join("topgrade.toml"); + let alt_config_path = config_directory.join("topgrade/topgrade.toml"); - if !config_path.exists() { + if config_path.exists() { + debug!("Configuration at {}", config_path.display()); + Ok(config_path) + } else if alt_config_path.exists() { + debug!("Configuration at {}", alt_config_path.display()); + Ok(alt_config_path) + } else { debug!("No configuration exists"); write(&config_path, EXAMPLE_CONFIG).map_err(|e| { debug!( @@ -364,11 +371,8 @@ impl ConfigFile { ); e })?; - } else { - debug!("Configuration at {}", config_path.display()); + Ok(config_path) } - - Ok(config_path) } /// Read the configuration file.