my code is so goddamn jank

This commit is contained in:
SadlyNotSappho 2023-06-23 09:31:44 -07:00
parent d9b34538c1
commit 2fec70e307
2 changed files with 12 additions and 6 deletions

View File

@ -42,18 +42,22 @@ pub fn create_config(file: &String) -> bool {
}
pub fn read_config(file: &String) -> Config {
let read = fs::read_to_string(file).expect("couldn't read config file");
let replaced = file.replace('~', &get_home()[..]); // replace ~ with $HOME
let read = fs::read_to_string(replaced).expect("couldn't read config file");
serde_json::from_str(&read[..]).expect("couldn't parse json")
}
pub fn ensure_exists(path: String) {
let p = Path::new(&path);
pub fn ensure_exists(path: &String) {
let replaced = path.replace('~', &get_home()[..]); // replace ~ with $HOME
let p = Path::new(&replaced);
println!("{}", replaced);
println!("{:?}", p.exists());
if !p.exists() {
fs::create_dir_all(p).expect("couldn't create folder")
}
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub latest_date: String,
pub cache_folder: String,

View File

@ -11,8 +11,10 @@ fn main() {
let args = Args::parse();
let config_file = args.config_file;
println!("{}", config_file);
ggg::create_config(&config_file);
let config = ggg::read_config(&config_file);
ggg::ensure_exists(config.cache_folder)
ggg::ensure_exists(&config.cache_folder);
println!("{:?}", &config);
}