mirror of https://git.sr.ht/~nixgoat/vento
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:
parent
88d07f5014
commit
9d24f51b1c
18
src/inv.rs
18
src/inv.rs
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue