feat: list commands when no command is called

This commit is contained in:
user0-07161 2025-03-21 22:16:47 +01:00
parent 182bf45172
commit 8774468d48
3 changed files with 12 additions and 2 deletions

View file

@ -3,7 +3,6 @@ use std::env;
use std::process::Command as stdCommand;
use std::io::{self, Write, ErrorKind};
use std::path::Path;
use std::fmt;
pub struct Ash;

View file

@ -13,6 +13,9 @@ impl Command for Boxcmd {
registry.execute(cmd);
return;
}
println!("No command provided.");
println!(
"No command provided. Included commands:\n{}",
registry.list().join(", ")
);
}
}

View file

@ -16,6 +16,14 @@ impl CommandRegistry {
self.commands.insert(name.to_string(), command);
}
pub fn list(&self) -> Vec<String> {
let mut bufvec = Vec::new();
for (key, _value) in self.commands.iter() {
bufvec.push(String::from(key))
}
bufvec
}
pub fn get(&self, name: &str) -> Option<&Box<dyn Command>> {
self.commands.get(name)
}