dotfiles/src/main.rs
Mutzi 208a4e9e79
Some checks failed
Gitea Organization/dotfiles/pipeline/head This commit looks good
Gitea Organization/dotfiles/pipeline/pr-installer There was a failure building this commit
Use Jenkins for updates
2023-02-13 20:05:20 +01:00

80 lines
2.0 KiB
Rust

mod prompt;
mod repository;
mod config;
mod operations;
mod utils;
mod update;
#[derive(Debug, Clone)]
enum MainMenu {
Install,
Collect,
Pull,
Diff,
Upload,
Quit
}
impl ToString for MainMenu {
fn to_string(&self) -> String {
match self {
MainMenu::Install => "Install files",
MainMenu::Collect => "Collect files",
MainMenu::Pull => "Pull from git",
MainMenu::Diff => "View git diff",
MainMenu::Upload => "(Commit) and push to git",
MainMenu::Quit => "Exit"
}.to_string()
}
}
fn main() {
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);
} else {
println!("Starting installer version unknown");
}
if !repository::open_repo() {
println!("Failed to open/clone repo!");
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?"),
vec![
MainMenu::Install,
MainMenu::Collect,
MainMenu::Pull,
MainMenu::Diff,
MainMenu::Upload,
MainMenu::Quit
]
);
match res {
MainMenu::Install => operations::install(&mods),
MainMenu::Collect => operations::collect(&mods),
MainMenu::Pull => repository::pull_repo(),
MainMenu::Diff => repository::diff(),
MainMenu::Upload => operations::upload(),
MainMenu::Quit => break 'main_loop
}
}
}