my code is so goddamn jank
This commit is contained in:
parent
d9b34538c1
commit
2fec70e307
12
src/lib.rs
12
src/lib.rs
|
@ -42,18 +42,22 @@ pub fn create_config(file: &String) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_config(file: &String) -> Config {
|
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")
|
serde_json::from_str(&read[..]).expect("couldn't parse json")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_exists(path: String) {
|
pub fn ensure_exists(path: &String) {
|
||||||
let p = Path::new(&path);
|
let replaced = path.replace('~', &get_home()[..]); // replace ~ with $HOME
|
||||||
|
let p = Path::new(&replaced);
|
||||||
|
println!("{}", replaced);
|
||||||
|
println!("{:?}", p.exists());
|
||||||
if !p.exists() {
|
if !p.exists() {
|
||||||
fs::create_dir_all(p).expect("couldn't create folder")
|
fs::create_dir_all(p).expect("couldn't create folder")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub latest_date: String,
|
pub latest_date: String,
|
||||||
pub cache_folder: String,
|
pub cache_folder: String,
|
||||||
|
|
|
@ -11,8 +11,10 @@ fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let config_file = args.config_file;
|
let config_file = args.config_file;
|
||||||
|
println!("{}", config_file);
|
||||||
ggg::create_config(&config_file);
|
ggg::create_config(&config_file);
|
||||||
let config = ggg::read_config(&config_file);
|
let config = ggg::read_config(&config_file);
|
||||||
ggg::ensure_exists(config.cache_folder)
|
ggg::ensure_exists(&config.cache_folder);
|
||||||
|
|
||||||
|
println!("{:?}", &config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue