Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show command help for missing argument and required option #427

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading