Drush is a very powerful command line tool to manage Drupal site.
Other than core Drush command, we can also write our own custom drush command to perform some task like cron setup, etc, ...
we can do it by using below 3 steps.
Steps :
1) Write hook_drush_help.
2) Write hook_drush_command.
3) Write drush_hook_command.
1) hook_drush_help.
2) hook_drush_command.
3) drush_hook_command.
Now Goto drush command line interface and try > drush test-import or > drush ti
Other than core Drush command, we can also write our own custom drush command to perform some task like cron setup, etc, ...
we can do it by using below 3 steps.
Steps :
1) Write hook_drush_help.
2) Write hook_drush_command.
3) Write drush_hook_command.
1) hook_drush_help.
/** * Implements hook_drush_help(). */ function my_module_drush_help($command) { switch ($command) { case 'drush:test-import': return dt('Import test contents.'); } }
2) hook_drush_command.
/** * Implements hook_drush_command(). */ function my_module_drush_command() { $items = array(); $items['test-import'] = array( 'description' => dt('Import test contents.'), 'arguments' => array( 'arg1' => dt('An optional example argument'), ), 'examples' => array( 'Standard example' => 'drush test-import', 'Argument example' => 'drush test-import 5', ), 'aliases' => array('ti'), ); return $items; }
3) drush_hook_command.
/** * Implements drush_hook_command(). */ function drush_my_module_test_import($arg = NULL) { // print arg if any. if (isset($arg)) { drush_print($arg); } drush_log('importing test contents...', 'ok'); }
Now Goto drush command line interface and try > drush test-import or > drush ti
No comments:
Post a Comment