Add the ability to have the config file in $XDG_CONFIG_HOME/topgrade/topgrade.toml (#418)

This commit is contained in:
PolpOnline
2023-05-03 21:53:52 +02:00
committed by GitHub
parent 26a2c3c266
commit a2331a2575

View File

@@ -353,8 +353,15 @@ impl ConfigFile {
let config_directory = config_directory(); let config_directory = config_directory();
let config_path = config_directory.join("topgrade.toml"); 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"); debug!("No configuration exists");
write(&config_path, EXAMPLE_CONFIG).map_err(|e| { write(&config_path, EXAMPLE_CONFIG).map_err(|e| {
debug!( debug!(
@@ -364,12 +371,9 @@ impl ConfigFile {
); );
e e
})?; })?;
} else {
debug!("Configuration at {}", config_path.display());
}
Ok(config_path) Ok(config_path)
} }
}
/// Read the configuration file. /// Read the configuration file.
/// ///