dotfiles/src/main.rs

80 lines
1.9 KiB
Rust
Raw Normal View History

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,
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 {
MainMenu::Install => "Install files",
2023-01-20 16:21:47 +00:00
MainMenu::Collect => "Collect files",
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-12 22:30:26 +00:00
if let Some(version) = option_env!("GIT_COMMIT") {
2023-01-25 12:25:12 +00:00
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;
}
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 {
MainMenu::Install => operations::install(&mods),
2023-01-20 16:21:47 +00:00
MainMenu::Collect => operations::collect(&mods),
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
}
}
}