Improve CLI
+ Add repository URL as valid input for dotfiles + Add regex, chrono crates + Add custom error types for Kot + Add uninstallation of dotfiles to revert changes when error is encountered + Update README, help text
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -6,7 +6,7 @@
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
|
||||
use std::path::PathBuf;
|
||||
use crate::kot::kerror::ErrorKind;
|
||||
|
||||
mod kot;
|
||||
|
||||
@@ -18,29 +18,10 @@ mod kot;
|
||||
|
||||
fn main() -> kot::Result<()> {
|
||||
// Call augmented kot::cli::from_args() to parse CLI arguments
|
||||
let args = kot::kcli::from_args()?;
|
||||
let mut args = kot::kcli::from_args()?;
|
||||
// At this point all paths exist and have been converted to absolute paths
|
||||
println!("args: {:?}\n", args);
|
||||
|
||||
// Attempt to install the configurations, checking for collisions
|
||||
match kot::install_configs(&args) {
|
||||
Err(e) => {
|
||||
// If there was an error, show the error type and run settings
|
||||
println!(
|
||||
"Error: {:?}\n+ Configs used: {:?}\n+ Install directory: {:?}\n",
|
||||
e, args.dotfiles_dir, args.install_dir
|
||||
);
|
||||
|
||||
// If we were forcing a backup and met some error, revert backups to last good state
|
||||
// TODO: Isolate this to limit error scope to backup related functions
|
||||
if args.force {
|
||||
let mut temp_path : PathBuf = kot::kfs::Path::new("/tmp/").to_path_buf();
|
||||
temp_path.push(args.backup_dir.file_name().unwrap());
|
||||
kot::kfs::move_dir(&temp_path, &args.backup_dir, None)?;
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
// Configurations installed successfully
|
||||
Ok(())
|
||||
// Apply CLI arguments and attempt to install dotfiles
|
||||
return kot::handle_args(&mut args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user