Skip to content

Instantly share code, notes, and snippets.

@stylesuxx
Created February 23, 2018 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stylesuxx/e404a2c52bf9c62e640b315732cf83a3 to your computer and use it in GitHub Desktop.
Save stylesuxx/e404a2c52bf9c62e640b315732cf83a3 to your computer and use it in GitHub Desktop.
Drupal drush template with argument and options
<?php
/**
* Implements hook_drush_command
*/
function custom_module_drush_command() {
$items['drush-command'] = array(
'description' => "This is a drush command.",
'aliases' => array('dc'),
'arguments' => array(
'type' => 'Arguments need to be provided',
),
'options' => array(
'repeat' => 'Options do not need to be provided',
),
'examples' => array(
'drush drush-command' => 'Prints an error message',
'drush drush-command success' => 'Prints a success message',
'drush drush-command success --repeat=5' => 'Prints 5 success messages',
),
);
return $items;
}
function drush_custom_module_drush_command($type = 'error') {
$validArgs = array('error', 'success');
$repeat = drush_get_option('repeat', 1);
if(is_numeric($repeat) && $repeat > 0) {
for($i = 0; $i < $repeat; $i += 1) {
drupal_set_message(t('Hello world! '), $type);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment