diff --git a/Cargo.toml b/Cargo.toml index 2b11e0c..3fd7447 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.3.3", features = ["derive"] } +iced = "0.9.0" +regex = "1.8.4" +reqwest = "0.11.18" +scraper = "0.16.0" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8c8c473 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,39 @@ +use std::fs; + +pub struct ConfigFile { + pub latest_date: String, + pub cache_folder: String, +} + +pub fn get_home() -> String { + let home = match std::env::consts::OS { + "linux" => std::env::var("HOME").expect("how is there not a $HOME"), + "windows" => std::env::var("userprofile").expect("yell at me if this doesn't work please i'm not going to touch windows"), + _ => std::env::var("HOME").expect("if this doesn't work, you're probably on macos, which i literally cannot test on"), + }; + // println!("{home}"); + home +} + +pub fn create_config(file: String) -> bool { + let replaced = file.replace('~', &get_home()[..]); + let mut paths = replaced.split('/').collect::>(); + let filename = paths.pop(); + let path = paths.join("/"); + let file_path = std::path::Path::new(&path); + let file_contents = "{\"latest_date\": \"20021104\",\"cache_folder\": \"~/.cache/ggg\"}"; + if let Some(p) = file_path.parent() { + fs::create_dir_all(p).expect("couldn't create needed folders") + }; + + let cfg_path = std::path::Path::new(format!("{}/{}", file_path.display(), filename.expect("filename somehow died, if you know how please tell me"))); + + if cfg_path.exists() { + false + } else { + + fs::write(cfg_path, file_contents).expect("couldn't write to config file"); + true + } + +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..ef81fe1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,16 @@ -fn main() { - println!("Hello, world!"); +use clap::Parser; + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + #[arg(short, long, default_value = "~/.config/ggg/config.json")] + config_file: String, +} + +fn main() { + let args = Args::parse(); + + let config_file = args.config_file; + + ggg::create_config(config_file); }