function sandwich_drush_command

8.0.x sandwich.drush.inc sandwich_drush_command()
6.x sandwich.drush.inc sandwich_drush_command()
7.x sandwich.drush.inc sandwich_drush_command()
3.x sandwich.drush.inc sandwich_drush_command()
4.x sandwich.drush.inc sandwich_drush_command()
5.x sandwich.drush.inc sandwich_drush_command()
master sandwich.drush.inc sandwich_drush_command()

Implements hook_drush_command().

In this hook, you specify which commands your drush module makes available, what it does and description.

Notice how this structure closely resembles how you define menu hooks.

See `drush topic docs-commands` for a list of recognized keys.

File

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

Code

function sandwich_drush_command() {
  $items = array();

  // The 'make-me-a-sandwich' command.
  $items['make-me-a-sandwich'] = array(
    'description' => "Makes a delicious sandwich.",
    'arguments' => array(
      'filling' => 'The type of the sandwich (turkey, cheese, etc.). Defaults to ascii.',
    ),
    'options' => array(
      'spreads' => array(
        'description' => 'Comma delimited list of spreads.',
        'example-value' => 'mayonnaise,mustard',
      ),
    ),
    'examples' => array(
      'drush mmas turkey --spreads=ketchup,mustard' => 'Make a terrible-tasting sandwich that is lacking in pickles.',
    ),
    'aliases' => array('mmas'),
    
    // No bootstrap at all.
    'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  );

  // The 'sandwiches-served' command.  Informs how many 'mmas' commands
  // completed.
  $items['sandwiches-served'] = array(
    'description' => "Report how many sandwiches we have made.",
    'examples' => array(
      'drush sandwiches-served' => 'Show how many sandwiches we have served.',
    ),
    'aliases' => array('sws'),
    
    // Example output engine data:  command returns a single keyed
    // data item (e.g. array("served" => 1)) that can either be
    // printed with a label (e.g. "served: 1"), or output raw with
    // --pipe (e.g. "1").
    'engines' => array(
      'outputformat' => array(
        'default' => 'key-value',
        'pipe-format' => 'string',
        'label' => 'Sandwiches Served',
        'require-engine-capability' => array('format-single'),
      ),
    ),
    
    // No bootstrap at all.
    'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  );

  // The 'spreads-status' command.  Prints a table about available spreads.
  $items['spreads-status'] = array(
    'description' => "Show a table of information about available spreads.",
    'examples' => array(
      'drush spreads-status' => 'Show a table of spreads.',
    ),
    'aliases' => array('sps'),
    
    // Example output engine data:  command returns a deep array
    // that can either be printed in table format or as a json array.
    'engines' => array(
      'outputformat' => array(
        'default' => 'table',
        'pipe-format' => 'json',
        
        // Commands that return deep arrays will usually use
        // machine-ids for the column data.  A 'field-labels'
        // item maps from the machine-id to a human-readable label.
        'field-labels' => array(
          'name' => 'Name',
          'description' => 'Description',
          'available' => 'Num',
          'taste' => 'Taste',
        ),
        
        // In table format, the 'column-widths' item is consulted
        // to determine the default weights for any named column.
        'column-widths' => array(
          'name' => 10,
          'available' => 3,
        ),
        'require-engine-capability' => array('format-table'),
      ),
    ),
    
    // No bootstrap at all.
    'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  );

  // Commandfiles may also add topics.  These will appear in
  // the list of topics when `drush topic` is executed.
  // To view this topic, run `drush --include=/full/path/to/examples topic`
  $items['sandwich-exposition'] = array(
    'description' => 'Ruminations on the true meaning and philosophy of sandwiches.',
    'hidden' => TRUE,
    'topic' => TRUE,
    'bootstrap' => DRUSH_BOOTSTRAP_NONE,
    'callback' => 'drush_print_file',
    'callback arguments' => array(dirname(__FILE__) . '/sandwich-topic.txt'),
  );

  return $items;
}