From faa6b1451dbc0b6e0abb5db1e59e225529aca5e6 Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Mon, 8 May 2023 15:38:46 +0200 Subject: [PATCH] refact(main): extract load_default_config --- crates/main/main.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/main/main.rs b/crates/main/main.rs index 683dd68..0cce355 100644 --- a/crates/main/main.rs +++ b/crates/main/main.rs @@ -15,6 +15,7 @@ Main program for `pacdef`. All internal logic happens in [`pacdef_core`]. missing_docs )] +use std::path::Path; use std::process::{ExitCode, Termination}; use anyhow::{Context, Result}; @@ -49,14 +50,7 @@ fn main_inner() -> Result<()> { let config_file = get_config_path().context("getting config file")?; let config = Config::load(&config_file) - .or_else(|_| { - get_config_path_old_version()? - .exists() - .then(show_transition_link); - let default = Config::default(); - default.save(&config_file)?; - Ok::(default) - }) + .or_else(|_| load_default_config(&config_file)) .context("loading config")?; let group_dir = get_group_dir().context("resolving group dir")?; @@ -67,6 +61,17 @@ fn main_inner() -> Result<()> { pacdef.run_action_from_arg().context("running action") } +fn load_default_config(config_file: &Path) -> Result { + if get_config_path_old_version()?.exists() { + show_transition_link(); + } + + let default = Config::default(); + default.save(config_file)?; + + Ok(default) +} + fn show_transition_link() { println!("VERSION UPGRADE"); println!("You seem to have used version 0.x of pacdef before.");