Drush is a command line shell and Unix scripting interface for Drupal, a
veritable Swiss Army knife designed to make life easier for those of us who
spend most of our working hours hacking away at the command prompt.
');
// Usage
$output .= '' . t('Usage') . '
';
$output .= 'drush.php [options] <command> <command> ...
';
// Options
$output .= '' . t('Options') . '
';
$options = drush_get_options();
$output .= "";
foreach ($options as $option => $description) {
$output .= '- ' . "
$option
" . ' ';
$output .= '- ' . $description . '
';
}
$output .= "
";
// Commands
$commands = drush_get_commands();
$output .= '' . t('Commands') . '
';
$output .= "";
foreach ($commands as $command => $info) {
$output .= '- ' . "
drush.php $command
" . ' ';
$output .= '- ' . $info["description"] . '
';
}
$output .= "
";
return $output;
}
}
/**
* Implementation of hook_drush_command().
*/
function drush_drush_command() {
$items['help'] = array(
'callback' => 'drush_callback_help',
'description' => 'View help. Run "drush help [command]" to view command-specific help.'
);
return $items;
}
/**
* Get the available options for Drush.
*
* @return
* An associative array containing the option definition as the key, and the description as the value,
* for each of the available options.
*/
function drush_get_options() {
// TODO: Add a hook for this, to allow other modules to add their options
$options['-r , --root='] = t("Drupal root directory to use (default: current directory)");
$options['-l , --uri='] = t('URI of the drupal site to use (only needed in multisite environments)');
$options['-v, --verbose'] = t('Display all available output');
$options['-y, --yes'] = t("Assume 'yes' as answer to all prompts");
$options['-s, --simulate'] = t("Simulate all relevant actions (don't actually change the system)");
$options['-c, --config'] = t("Specify a config file to use. See example.drushrc.php");
return $options;
}
/**
* Command callback. Display help.
*/
function drush_callback_help() {
$commands = func_get_args();
// Display general help text if no command is specified.
if (empty($commands)) {
drush_print(t('Usage: drush.php [options] ...'));
drush_print();
drush_print(t('Options: '));
foreach (drush_get_options() as $option => $description) {
$rows[] = array($option, $description);
}
drush_print_table($rows, 2);
drush_print();
drush_print('Commands: ');
$commands = drush_get_commands();
$rows = array();
foreach($commands as $key => $command) {
$rows[] = array($key, $commands[$key]['description']);
}
drush_print_table($rows, 2);
}
// Print command specific help.
else {
$commandstring = implode(" ", $commands);
if (!drush_is_command($commandstring)) {
return drush_error(t('Invalid command !command.', array('!command' => implode(" ", $commands))));
}
$help = module_invoke_all('help', 'drush:'. $commandstring);
if (!empty($help)) {
drush_print(implode("\n", $help));
}
else {
drush_print(t("No help available for command 'drush $commandstring'."));
}
}
}
/**
* This is called if no command or an unknown command is entered.
*/
function drush_usage() {
$commands = func_get_args();
if (drush_get_option('help') || empty($commands)) {
return drush_callback_help();
}
return drush_error(t('Invalid command !command.', array('!command' => implode(" ", $commands))));
}