use std::env;
use std::fs;
use std::path::Path;
use lazy_static::lazy_static;
static CONFIG_FILENAME: &str = "config.toml";
lazy_static! {
static ref PARENT_PATH: String = {
if cfg!(windows) {
format!("{}/sisterm/", env::var("LOCALAPPDATA").unwrap())
} else {
format!("{}/.config/sisterm/", env::var("HOME").unwrap())
}
};
}
fn main() {
match generate() {
Ok(None) => (), Ok(Some(path)) => println!("Generated config file --> {}", path),
Err(e) => {
eprintln!("{}", e);
std::process::exit(1);
},
}
}
fn generate() -> Result<Option<String>, std::io::Error> {
let config_file_path = format!("{}{}", *PARENT_PATH, CONFIG_FILENAME);
if Path::new(&config_file_path).exists() {
return Ok(None);
}
fs::create_dir_all(&*PARENT_PATH)?;
fs::copy(CONFIG_FILENAME, &config_file_path)?;
Ok(Some(config_file_path))
}