| 1 |
<?php
|
| 2 |
// $Id: example.drush.inc,v 1.4 2009/09/21 00:53:24 weitzman Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Example drush command.
|
| 7 |
*
|
| 8 |
* Shows how to make your own drush command.
|
| 9 |
*
|
| 10 |
* You can copy this file to any of the following
|
| 11 |
* 1. A .drush folder in your HOME folder.
|
| 12 |
* 2. Anywhere in a folder tree below an active module on your site.
|
| 13 |
* 3. In an arbitrary folder specified with the --include option.
|
| 14 |
*/
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_drush_command().
|
| 18 |
*
|
| 19 |
* In this hook, you specify which commands your
|
| 20 |
* drush module makes available, what it does and
|
| 21 |
* description.
|
| 22 |
*
|
| 23 |
* Notice how this structure closely resembles how
|
| 24 |
* you define menu hooks.
|
| 25 |
*
|
| 26 |
* @See drush_parse_command() for a list of recognized keys.
|
| 27 |
*
|
| 28 |
* @return
|
| 29 |
* An associative array describing your command(s).
|
| 30 |
*/
|
| 31 |
function example_drush_command() {
|
| 32 |
$items = array();
|
| 33 |
|
| 34 |
// the key in the $items array is the name of the command.
|
| 35 |
$items['example'] = array(
|
| 36 |
// the name of the function implementing your command.
|
| 37 |
'callback' => 'example_callback',
|
| 38 |
// a short description of your command
|
| 39 |
'description' => "Drush example command. It doesn't do a lot",
|
| 40 |
);
|
| 41 |
|
| 42 |
// more commands here ...
|
| 43 |
|
| 44 |
return $items;
|
| 45 |
}
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Implementation of hook_drush_help().
|
| 49 |
*
|
| 50 |
* This function is called whenever a drush user calls
|
| 51 |
* 'drush help <name-of-your-command>'
|
| 52 |
*
|
| 53 |
* @param
|
| 54 |
* A string with the help section (prepend with 'drush:')
|
| 55 |
*
|
| 56 |
* @return
|
| 57 |
* A string with the help text for your command.
|
| 58 |
*/
|
| 59 |
function example_drush_help($section) {
|
| 60 |
switch ($section) {
|
| 61 |
case 'drush:example':
|
| 62 |
return dt("Prints the amount of time since january 1st, 1970, in years and weeks.");
|
| 63 |
}
|
| 64 |
}
|
| 65 |
|
| 66 |
/**
|
| 67 |
* Example drush command callback.
|
| 68 |
*
|
| 69 |
* This is where the action takes place.
|
| 70 |
*
|
| 71 |
* In this function, all of Drupals API is (usually) available, including
|
| 72 |
* any functions you have added in your own modules/themes.
|
| 73 |
*
|
| 74 |
* To print something to the terminal window, use drush_print().
|
| 75 |
*
|
| 76 |
*/
|
| 77 |
function example_callback() {
|
| 78 |
$args = func_get_args();
|
| 79 |
|
| 80 |
// Using the Drupal API function 'format_interval()'
|
| 81 |
// and Drush API function 'drush_print'
|
| 82 |
drush_print(format_interval(time()));
|
| 83 |
}
|