Skip to content

Commit

Permalink
Show command help for missing argument and required option (backdrop-…
Browse files Browse the repository at this point in the history
…contrib#427)

* Show command help for missing argument and required option
* Add info message before help text to give context.
  • Loading branch information
yorkshire-pudding authored and bugfolder committed Sep 7, 2024
1 parent 0ac36fd commit 01f77d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions commands/user.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function user_create_bee_callback($arguments, $options) {
}
if (!isset($options['mail'])) {
bee_message(bt("Mail option missing."), 'error');
bee_command_show_help();
return;
}
if (!valid_email_address($options['mail'])) {
Expand Down
22 changes: 22 additions & 0 deletions includes/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ function bee_validate_command(array $descriptor) {
bee_message(bt("Argument '!name' is required.", array(
'!name' => $name,
)), 'error');
bee_command_show_help();
return FALSE;
}
}
Expand Down Expand Up @@ -327,3 +328,24 @@ function bee_validate_command(array $descriptor) {

return TRUE;
}

/**
* Show the help text for a command.
*/
function bee_command_show_help() {
global $_bee_command, $_bee_output;

// Show a message to give context to the following help.
bee_message(bt('To help you get it right, here is the help text for this command:'), 'info');

// Get the command descriptor.
$commands = bee_all_commands();
$command_descriptor = $commands[$_bee_command];

// The help function we call expects the command key to exist within the
// descriptor containing the command.
$command_descriptor['command'] = $_bee_command;

// Set the output to be the help text for the command.
$_bee_output = help_bee_command_help($command_descriptor);
}

0 comments on commit 01f77d0

Please sign in to comment.