refact(main): extract load_default_config
This commit is contained in:
+13
-8
@@ -15,6 +15,7 @@ Main program for `pacdef`. All internal logic happens in [`pacdef_core`].
|
|||||||
missing_docs
|
missing_docs
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
use std::process::{ExitCode, Termination};
|
use std::process::{ExitCode, Termination};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
@@ -49,14 +50,7 @@ fn main_inner() -> Result<()> {
|
|||||||
let config_file = get_config_path().context("getting config file")?;
|
let config_file = get_config_path().context("getting config file")?;
|
||||||
|
|
||||||
let config = Config::load(&config_file)
|
let config = Config::load(&config_file)
|
||||||
.or_else(|_| {
|
.or_else(|_| load_default_config(&config_file))
|
||||||
get_config_path_old_version()?
|
|
||||||
.exists()
|
|
||||||
.then(show_transition_link);
|
|
||||||
let default = Config::default();
|
|
||||||
default.save(&config_file)?;
|
|
||||||
Ok::<Config, anyhow::Error>(default)
|
|
||||||
})
|
|
||||||
.context("loading config")?;
|
.context("loading config")?;
|
||||||
|
|
||||||
let group_dir = get_group_dir().context("resolving group dir")?;
|
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")
|
pacdef.run_action_from_arg().context("running action")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load_default_config(config_file: &Path) -> Result<Config> {
|
||||||
|
if get_config_path_old_version()?.exists() {
|
||||||
|
show_transition_link();
|
||||||
|
}
|
||||||
|
|
||||||
|
let default = Config::default();
|
||||||
|
default.save(config_file)?;
|
||||||
|
|
||||||
|
Ok(default)
|
||||||
|
}
|
||||||
|
|
||||||
fn show_transition_link() {
|
fn show_transition_link() {
|
||||||
println!("VERSION UPGRADE");
|
println!("VERSION UPGRADE");
|
||||||
println!("You seem to have used version 0.x of pacdef before.");
|
println!("You seem to have used version 0.x of pacdef before.");
|
||||||
|
|||||||
Reference in New Issue
Block a user