mod prompt; mod repository; mod config; mod operations; mod utils; use strum::{EnumIter, IntoEnumIterator}; #[derive(Debug, Clone, EnumIter)] enum MainMenu { INSTALL, COLLECT, DIFF, UPLOAD, QUIT } impl ToString for MainMenu { fn to_string(&self) -> String { match self { MainMenu::INSTALL => "Pull and install files", MainMenu::COLLECT => "Collect files", MainMenu::DIFF => "View git diff", MainMenu::UPLOAD => "(Commit) and push to git", MainMenu::QUIT => "Exit" }.to_string() } } fn main() { let repo = match repository::open_repo() { Ok(v) => v, Err(err) => { println!("Failed to open/clone repo!"); println!("{}", err); return; } }; if !std::path::Path::new("mod.toml").exists() { println!("'mod.toml' doesn't exist!"); return; } let mods = match config::parse() { Ok(v) => v, Err(err) => { println!("Failed to process mod.toml!"); println!("{}", err); return; } }; 'main_loop: loop { let res = prompt::select(Some("What do you want to do?"), MainMenu::iter().collect()); match res { MainMenu::INSTALL => { if let Err(err) = repository::pull_repo(&repo) { println!("Failed to pull repo!"); println!("{}", err); return; } operations::install(&mods); }, MainMenu::COLLECT => operations::collect(&mods), MainMenu::DIFF => { std::process::Command::new("git").arg("diff").spawn().unwrap().wait().unwrap(); }, MainMenu::UPLOAD => operations::upload(&repo), MainMenu::QUIT => break 'main_loop } } }