Skip to content

Commit

Permalink
feat: save config if no config file was found
Browse files Browse the repository at this point in the history
`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 <j.h.m.t.v.10@gmail.com>
Reviewed-by: David Tadokoro <davidbtadokoro@usp.br>
Signed-off-by: David Tadokoro <davidbtadokoro@usp.br>
  • Loading branch information
OJarrisonn authored and davidbtadokoro committed Oct 2, 2024
1 parent d47c771 commit 3856796
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 3856796

Please sign in to comment.