1. Create a new custom module. In this example, the module name is eureka_drush.
2. Create the eureka_drush.info.
eureka_drush.info
name = Eureka Drush description = Custom drush command example. core = 7.x package = Eureka
3. Create the eureka_drush.module. Even if you do not have any implementation, leave it with just the PHP open tag.
eureka_drush.module
<?php
4. Create the eureka_drush.drush.inc.
eureka_drush.drush.inc
<?php /** * Implementation of hook_drush_command(). */ function eureka_drush_drush_command() { $items = array(); $items['say-hello-world'] = array( 'description' => 'Say Hello world', 'drupal dependencies' => array('eureka_drush'), ); return $items; } /** * Callback function for say-hello-world. * The function name is drush_<module_name>_<command_in_underscore> */ function drush_eureka_drush_say_hello_world() { $msg = 'Hello World'; drush_print("\n" . $msg . "\n"); }
5. Enable the module and clear the Drupal cache.
drush en eureka_drush drush cc all
6. Run drush help and check if your command is available.
drush help | grep say-hello-world
7. Try it out!
drush say-hello-world
Done =)
References: