inv: list: Add method to catch invalid slot

If you tried to type anything that isn't a valid slot, Vento would
panic. This commit should fix that.
This commit is contained in:
Lux Aliaga 2022-09-14 16:33:19 -03:00
parent 88d07f5014
commit 9d24f51b1c
1 changed files with 11 additions and 7 deletions

View File

@ -27,13 +27,17 @@ pub fn list(slot: &str) { // Lists files in inventory
let ventodir: PathBuf = env_config();
let slotdir: PathBuf = [ventodir.to_path_buf(), Path::new(slot).to_path_buf()].iter().collect();
println!("🗃️ {}", format!("Files in {} inventory:", match slot {
"active" => format!("{}", slot).bold(),
"inactive" | _ => format!("{}", slot).blue().bold()
}).green());
for file in fs::read_dir(&slotdir).unwrap() {
println!("- {}", file.unwrap().path().file_name().unwrap().to_os_string().into_string().unwrap());
};
if slotdir.is_dir() { // Checks if inventory selected exists
println!("🗃️ {}", format!("Files in {} inventory:", match slot {
"active" => format!("{}", slot).bold(),
"inactive" | _ => format!("{}", slot).blue().bold()
}).green());
for file in fs::read_dir(&slotdir).unwrap() {
println!("- {}", file.unwrap().path().file_name().unwrap().to_os_string().into_string().unwrap());
};
} else {
println!("{}", format!("Vento was unable to read that slot. Valid slots are {} and {}.", format!("active").green(), format!("inactive").blue()).red());
}
}
pub fn switch() { // Switches between inventory slots