dotfiles/src/main.rs

72 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;
use strum::{EnumIter, IntoEnumIterator};
#[derive(Debug, Clone, EnumIter)]
enum MainMenu {
2023-01-20 16:21:47 +00:00
Install,
Collect,
Diff,
Upload,
Quit
2023-01-20 15:43:17 +00:00
}
impl ToString for MainMenu {
fn to_string(&self) -> String {
match self {
2023-01-20 16:21:47 +00:00
MainMenu::Install => "Pull and install files",
MainMenu::Collect => "Collect files",
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() {
let repo = match repository::open_repo() {
Ok(v) => v,
Err(err) => {
println!("Failed to open/clone repo!");
println!("{}", err);
return;
}
};
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-20 16:21:47 +00:00
MainMenu::Install => {
2023-01-20 15:43:17 +00:00
if let Err(err) = repository::pull_repo(&repo) {
println!("Failed to pull repo!");
println!("{}", err);
return;
}
operations::install(&mods);
},
2023-01-20 16:21:47 +00:00
MainMenu::Collect => operations::collect(&mods),
MainMenu::Diff => { std::process::Command::new("git").arg("diff").current_dir("repo").spawn().unwrap().wait().unwrap(); },
MainMenu::Upload => operations::upload(&repo),
MainMenu::Quit => break 'main_loop
2023-01-20 15:43:17 +00:00
}
}
}