dotfiles/src/main.rs
2023-01-25 14:56:26 +01:00

80 lines
1.9 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) = option_env!("CI_COMMIT_SHA") {
println!("Starting installer version {}", version);
update::check_for_updates(version);
} 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
}
}
}