Created
February 23, 2018 13:13
-
-
Save stylesuxx/e404a2c52bf9c62e640b315732cf83a3 to your computer and use it in GitHub Desktop.
Drupal drush template with argument and options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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