From 38567966845a0cb87d7c9ce9d1ca71eeb53aa3cb Mon Sep 17 00:00:00 2001 From: OJarrisonn Date: Wed, 25 Sep 2024 14:23:22 -0300 Subject: [PATCH] feat: save config if no config file was found `patch-hub` relies on configurations to work properly. These can be determined by (1) default values, (2) configuration file, and (3) env variables. In case there is no configuration file detected, save the default one. [Maintainers edits] - Add TODO comment for better handle error when saving config file. - Add commit message body. Signed-off-by: OJarrisonn Reviewed-by: David Tadokoro Signed-off-by: David Tadokoro --- src/app/config.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/config.rs b/src/app/config.rs index d083a06..96c608b 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -88,11 +88,12 @@ impl Config { } pub fn build() -> Self { - let mut config = Self::default(); - - if let Some(config_from_file) = Self::detect_patch_hub_config_file() { - config = config_from_file; - } + let mut config = Self::detect_patch_hub_config_file().unwrap_or_else(|| { + let config = Self::default(); + // TODO: Better handle this error + let _ = config.save_patch_hub_config(); + config + }); config.override_with_env_vars();