Improve help command

This commit is contained in:
Sofia 2026-07-15 20:32:20 +03:00
parent eba728f194
commit c4f376b9c3

View File

@ -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,
);
}
}
}