feat: list commands when no command is called
This commit is contained in:
parent
182bf45172
commit
8774468d48
3 changed files with 12 additions and 2 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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(", ")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue