function drush_sandwich_make_me_a_sandwich

8.0.x sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')
6.x sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')
7.x sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')
3.x sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')
4.x sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')
5.x sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')
master sandwich.drush.inc drush_sandwich_make_me_a_sandwich($filling = 'ascii')

Example drush command callback. This is where the action takes place.

The function name should be same as command name but with dashes turned to underscores and 'drush_commandfile_' prepended, where 'commandfile' is taken from the file 'commandfile.drush.inc', which in this case is 'sandwich'. Note also that a simplification step is also done in instances where the commandfile name is the same as the beginning of the command name, "drush_example_example_foo" is simplified to just "drush_example_foo". To also implement a hook that is called before your command, implement "drush_hook_pre_example_foo". For a list of all available hooks for a given command, run drush in --debug mode.

If for some reason you do not want your hook function to be named after your command, you may define a 'callback' item in your command object that specifies the exact name of the function that should be called.

In this function, all of Drupal's API is (usually) available, including any functions you have added in your own modules/themes.

See also

drush_invoke()

drush.api.php

File

examples/sandwich.drush.inc, line 218
Example drush command.

Code

function drush_sandwich_make_me_a_sandwich($filling = 'ascii') {
  $str_spreads = '';
  // Read options with drush_get_option. Note that the options _must_
  // be documented in the $items structure for this command in the 'command' hook.
  // See `drush topic docs-commands` for more information.
  if ($spreads = drush_get_option('spreads')) {
    $list = implode(' and ', explode(',', $spreads));
    $str_spreads = ' with just a dash of ' . $list;
  }
  $msg = dt('Okay. Enjoy this !filling sandwich!str_spreads.', array('!filling' => $filling, '!str_spreads' => $str_spreads));
  drush_print("\n" . $msg . "\n");

  if (drush_get_context('DRUSH_NOCOLOR')) {
    $filename = dirname(__FILE__) . '/sandwich-nocolor.txt';
  }
  else {
    $filename = dirname(__FILE__) . '/sandwich.txt';
  }
  drush_print(file_get_contents($filename));
  // Find out how many sandwiches have been served, and set
  // the cached value to one greater.
  $served = drush_sandwich_sandwiches_served();
  drush_cache_set(drush_get_cid('sandwiches-served'), $served + 1);
}