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("repo/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").current_dir("repo").spawn().unwrap().wait().unwrap(); }, MainMenu::Upload => operations::upload(&repo), MainMenu::Quit => break 'main_loop } } }