1
0
Fork 0
mirror of https://git.sr.ht/~nixgoat/vento synced 2025-11-22 08:33:37 +00:00

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

View file

@ -27,6 +27,7 @@ pub fn list(slot: &str) { // Lists files in inventory
let ventodir: PathBuf = env_config(); let ventodir: PathBuf = env_config();
let slotdir: PathBuf = [ventodir.to_path_buf(), Path::new(slot).to_path_buf()].iter().collect(); let slotdir: PathBuf = [ventodir.to_path_buf(), Path::new(slot).to_path_buf()].iter().collect();
if slotdir.is_dir() { // Checks if inventory selected exists
println!("🗃️ {}", format!("Files in {} inventory:", match slot { println!("🗃️ {}", format!("Files in {} inventory:", match slot {
"active" => format!("{}", slot).bold(), "active" => format!("{}", slot).bold(),
"inactive" | _ => format!("{}", slot).blue().bold() "inactive" | _ => format!("{}", slot).blue().bold()
@ -34,6 +35,9 @@ pub fn list(slot: &str) { // Lists files in inventory
for file in fs::read_dir(&slotdir).unwrap() { for file in fs::read_dir(&slotdir).unwrap() {
println!("- {}", file.unwrap().path().file_name().unwrap().to_os_string().into_string().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 pub fn switch() { // Switches between inventory slots