Improve help command
This commit is contained in:
parent
eba728f194
commit
c4f376b9c3
@ -118,13 +118,24 @@ trait Command {
|
||||
struct HelpCommand;
|
||||
impl Command for HelpCommand {
|
||||
fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) {
|
||||
let mut keys = cli.commands.keys().cloned().collect::<Vec<_>>();
|
||||
keys.sort();
|
||||
for key in keys {
|
||||
cli.publish_message(
|
||||
format!("\t- {}: {}", key, cli.commands.get(&key).unwrap().help()),
|
||||
CliColor::Regular,
|
||||
);
|
||||
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<_>>();
|
||||
keys.sort();
|
||||
for key in keys {
|
||||
cli.publish_message(
|
||||
format!("\t- {}: {}", key, cli.commands.get(&key).unwrap().help()),
|
||||
CliColor::Regular,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user