Improve help command
This commit is contained in:
parent
eba728f194
commit
c4f376b9c3
@ -118,6 +118,16 @@ trait Command {
|
|||||||
struct HelpCommand;
|
struct HelpCommand;
|
||||||
impl Command for HelpCommand {
|
impl Command for HelpCommand {
|
||||||
fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) {
|
fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) {
|
||||||
|
if let Some(command_name) = params.first() {
|
||||||
|
if let Some(command) = cli.commands.get(*command_name) {
|
||||||
|
cli.publish_message(command.help().to_string(), CliColor::Regular);
|
||||||
|
} else {
|
||||||
|
cli.publish_message(
|
||||||
|
format!("Unknown command: {}", command_name),
|
||||||
|
CliColor::Regular,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
let mut keys = cli.commands.keys().cloned().collect::<Vec<_>>();
|
let mut keys = cli.commands.keys().cloned().collect::<Vec<_>>();
|
||||||
keys.sort();
|
keys.sort();
|
||||||
for key in keys {
|
for key in keys {
|
||||||
@ -127,6 +137,7 @@ impl Command for HelpCommand {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn help(&self) -> &str {
|
fn help(&self) -> &str {
|
||||||
"Shows this message"
|
"Shows this message"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user