use crate::backup;
use crate::commands::validator::is_valid_path_entry;
use crate::utils;
use std::path::PathBuf;
pub fn execute() {
if let Err(e) = backup::create_backup() {
eprintln!("Error creating backup: {}", e);
return;
}
let current_entries = utils::get_path_entries();
let original_count = current_entries.len();
let valid_entries: Vec<PathBuf> = current_entries
.into_iter()
.filter(|path| {
if is_valid_path_entry(path) {
true
} else {
println!("Removing invalid path: {}", path.display());
false
}
})
.collect();
let removed_count = original_count - valid_entries.len();
if removed_count == 0 {
println!("No invalid paths found in PATH.");
return;
}
utils::set_path_entries(&valid_entries);
match utils::update_shell_config(&valid_entries) {
Ok(_) => {
println!(
"Successfully removed {} invalid path(s) and updated shell configuration.",
removed_count
);
}
Err(e) => {
eprintln!("Error updating shell configuration: {}", e);
println!("Warning: PATH environment variable was updated for current session only.");
println!("To make changes permanent, you'll need to manually update your shell configuration.");
}
}
}