mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 15:19:58 -07:00
parser: fix config file creation and remove panic
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user