Don't complain if the configuration directory does not exist
This commit is contained in:
@@ -147,13 +147,19 @@ pub struct ConfigFile {
|
|||||||
vagrant: Option<Vagrant>,
|
vagrant: Option<Vagrant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn config_directory(base_dirs: &BaseDirs) -> PathBuf {
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
return base_dirs.config_dir().to_owned();
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
return base_dirs.home_dir().join(".config");
|
||||||
|
}
|
||||||
|
|
||||||
impl ConfigFile {
|
impl ConfigFile {
|
||||||
fn ensure(base_dirs: &BaseDirs) -> Result<PathBuf> {
|
fn ensure(base_dirs: &BaseDirs) -> Result<PathBuf> {
|
||||||
#[cfg(not(target_os = "macos"))]
|
let config_directory = config_directory(base_dirs);
|
||||||
let config_path = base_dirs.config_dir().join("topgrade.toml");
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
let config_path = config_directory.join("topgrade.toml");
|
||||||
let config_path = base_dirs.home_dir().join(".config/topgrade.toml");
|
|
||||||
|
|
||||||
if !config_path.exists() {
|
if !config_path.exists() {
|
||||||
debug!("No configuration exists");
|
debug!("No configuration exists");
|
||||||
@@ -309,12 +315,18 @@ impl Config {
|
|||||||
|
|
||||||
builder.init();
|
builder.init();
|
||||||
|
|
||||||
let config_file = ConfigFile::read(base_dirs, opt.config.clone()).unwrap_or_else(|e| {
|
let config_directory = config_directory(base_dirs);
|
||||||
// Inform the user about errors when loading the configuration,
|
let config_file = if config_directory.is_dir() {
|
||||||
// but fallback to the default config to at least attempt to do something
|
ConfigFile::read(base_dirs, opt.config.clone()).unwrap_or_else(|e| {
|
||||||
log::error!("failed to load configuration: {}", e);
|
// Inform the user about errors when loading the configuration,
|
||||||
|
// but fallback to the default config to at least attempt to do something
|
||||||
|
log::error!("failed to load configuration: {}", e);
|
||||||
|
ConfigFile::default()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log::debug!("Configuration directory {} does not exist", config_directory.display());
|
||||||
ConfigFile::default()
|
ConfigFile::default()
|
||||||
});
|
};
|
||||||
|
|
||||||
check_deprecated!(config_file, git_arguments, git, arguments);
|
check_deprecated!(config_file, git_arguments, git, arguments);
|
||||||
check_deprecated!(config_file, git_repos, git, repos);
|
check_deprecated!(config_file, git_repos, git, repos);
|
||||||
|
|||||||
Reference in New Issue
Block a user