From 59adf13b2251612af9b37fe69a9d8b61fa2804b1 Mon Sep 17 00:00:00 2001 From: Olexander Hofman Date: Tue, 6 Aug 2024 18:37:03 +0100 Subject: [PATCH] fix creating settings --- src/config.rs | 9 ++------- src/main.rs | 5 ++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1c2cb0d..9d329a6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,6 @@ use config::{Config as ConfigBuilder, File, FileFormat}; use serde::Deserialize; -use std::{ - error::Error, - fs, - io::{BufWriter, Write}, - path::Path, -}; +use std::{error::Error, fs, io::Write, path::Path}; #[derive(Debug, Deserialize)] pub struct Config { @@ -52,7 +47,7 @@ impl Config { fn create_config_file(config_path: &str) -> Result<(), Box> { //create config file if it doesn't exist if !Path::new(config_path).exists() { - let mut file = BufWriter::new(fs::File::create(config_path)?); + let mut file = fs::File::create(config_path)?; file.write_all( toml::toml! { diff --git a/src/main.rs b/src/main.rs index 649a017..74f0b4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use config::Config; use cred_store::{CredStore, Credentials}; use clap::{arg, command, value_parser, Arg, ArgMatches}; -use std::{env, panic, path::PathBuf}; +use std::{env, fs, panic, path::PathBuf}; pub struct CommandContext<'a, T: CredStore> { pub config: &'a Config, @@ -34,6 +34,9 @@ async fn main() -> Result<(), Box> { }; let mamoru_dir_path = home_dir.join(MAMORU_CONFIG_DIR); + if !mamoru_dir_path.exists() { + fs::create_dir_all(mamoru_dir_path.clone())?; + } let settings_file = mamoru_dir_path.join(CONFIG_NAME); let credentials_file = mamoru_dir_path.join(CREDENTIALS);