2023-01-20 15:43:17 +00:00
|
|
|
mod prompt;
|
|
|
|
mod repository;
|
|
|
|
mod config;
|
|
|
|
mod operations;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
use strum::{EnumIter, IntoEnumIterator};
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, EnumIter)]
|
|
|
|
enum MainMenu {
|
2023-01-20 16:21:47 +00:00
|
|
|
Install,
|
|
|
|
Collect,
|
2023-01-25 11:39:31 +00:00
|
|
|
Pull,
|
2023-01-20 16:21:47 +00:00
|
|
|
Diff,
|
|
|
|
Upload,
|
|
|
|
Quit
|
2023-01-20 15:43:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for MainMenu {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
2023-01-25 11:39:31 +00:00
|
|
|
MainMenu::Install => "Install files",
|
2023-01-20 16:21:47 +00:00
|
|
|
MainMenu::Collect => "Collect files",
|
2023-01-25 11:39:31 +00:00
|
|
|
MainMenu::Pull => "Pull from git",
|
2023-01-20 16:21:47 +00:00
|
|
|
MainMenu::Diff => "View git diff",
|
|
|
|
MainMenu::Upload => "(Commit) and push to git",
|
|
|
|
MainMenu::Quit => "Exit"
|
2023-01-20 15:43:17 +00:00
|
|
|
}.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2023-01-25 11:39:31 +00:00
|
|
|
if !repository::open_repo() {
|
|
|
|
println!("Failed to open/clone repo!");
|
|
|
|
return;
|
|
|
|
}
|
2023-01-20 15:43:17 +00:00
|
|
|
|
2023-01-20 16:21:47 +00:00
|
|
|
if !std::path::Path::new("repo/mod.toml").exists() {
|
2023-01-20 15:43:17 +00:00
|
|
|
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 {
|
2023-01-25 11:39:31 +00:00
|
|
|
MainMenu::Install => operations::install(&mods),
|
2023-01-20 16:21:47 +00:00
|
|
|
MainMenu::Collect => operations::collect(&mods),
|
2023-01-25 11:39:31 +00:00
|
|
|
MainMenu::Pull => repository::pull_repo(),
|
|
|
|
MainMenu::Diff => repository::diff(),
|
|
|
|
MainMenu::Upload => operations::upload(),
|
2023-01-20 16:21:47 +00:00
|
|
|
MainMenu::Quit => break 'main_loop
|
2023-01-20 15:43:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|