2023-01-20 15:43:17 +00:00
|
|
|
mod prompt;
|
|
|
|
mod repository;
|
|
|
|
mod config;
|
|
|
|
mod operations;
|
|
|
|
mod utils;
|
2023-01-25 12:25:12 +00:00
|
|
|
mod update;
|
2023-01-20 15:43:17 +00:00
|
|
|
|
2023-01-25 12:25:12 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2023-01-20 15:43:17 +00:00
|
|
|
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-02-13 19:05:20 +00:00
|
|
|
if let (Some(version), Some(name)) = (option_env!("BUILD_ID"), option_env!("JOB_BASE_NAME")) {
|
|
|
|
println!("Starting installer version {name}-{version}");
|
|
|
|
update::check_for_updates(version.parse().unwrap(), name);
|
2023-01-25 12:25:12 +00:00
|
|
|
} else {
|
|
|
|
println!("Starting installer version unknown");
|
|
|
|
}
|
|
|
|
|
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 {
|
2023-01-25 12:25:12 +00:00
|
|
|
let res = prompt::select(
|
|
|
|
Some("What do you want to do?"),
|
|
|
|
vec![
|
|
|
|
MainMenu::Install,
|
|
|
|
MainMenu::Collect,
|
|
|
|
MainMenu::Pull,
|
|
|
|
MainMenu::Diff,
|
|
|
|
MainMenu::Upload,
|
|
|
|
MainMenu::Quit
|
|
|
|
]
|
|
|
|
);
|
2023-01-20 15:43:17 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|