parser: fix config file creation and remove panic

This commit is contained in:
k
2024-07-15 19:43:37 +02:00
parent 1be22713f9
commit 0c899b2c16
2 changed files with 5 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
use std::fs::{self, File};
use std::fs::{self};
use clap::Parser;
use serde::{Deserialize, Serialize};
@@ -27,14 +27,13 @@ impl Config {
const PATH: &'static str = "config.toml";
pub fn read() -> Self {
fs::write(Self::PATH, "").unwrap();
let string = fs::read_to_string(Self::PATH).unwrap();
let mut config_saved = fs::read_to_string(Self::PATH)
.map_or(Config::default(), |contents| {
toml::from_str(&contents).unwrap_or_default()
});
let config_args = Config::parse();
let mut config_saved: Config = toml::from_str(&string).unwrap_or_default();
if let Some(datadir) = config_args.datadir {
config_saved.datadir = Some(datadir);
}