use serde_json::json;
use serde_json::{Map, Value};
use std::fs::read_to_string;
use std::fs::File;
use crate::dir;
pub fn get_gut_config() -> Value {
let file_name = format!("{}/gut.json", dir::get_gut_dir());
let conf_str = match read_to_string(file_name) {
Ok(val) => val,
Err(_) => return json!({}),
};
let conf: Value = serde_json::from_str(&conf_str).expect("Failed to parse gut conf");
conf
}
pub fn set_gut_config(key: String, value: Value) {
let conf = get_gut_config();
let mut map: Map<String, Value> =
serde_json::from_value(conf).expect("Failed to convert gut conf");
map.insert(key, value);
write_gut_config(map);
}
fn write_gut_config(json: Map<String, Value>) {
let file_name = format!("{}/gut.json", dir::get_gut_dir());
let gut_config = File::create(&file_name).expect("Failed to create gut config");
serde_json::ser::to_writer(&gut_config, &json).expect("Failed to write file");
}