function outputformat_drush_engine_outputformat

8.0.x outputformat.drush.inc outputformat_drush_engine_outputformat()
6.x outputformat.drush.inc outputformat_drush_engine_outputformat()
7.x outputformat.drush.inc outputformat_drush_engine_outputformat()
master outputformat.drush.inc outputformat_drush_engine_outputformat()

Implements hook_drush_engine_ENGINE_TYPE().

The output format types supported are represented by the 'engine-capabilities' of the output format engine. The different capabilities include:

format-single: A simple string.

format-list: An associative array where the key is usually the row label, and the value is a simple string. Some list formatters render the label, and others (like "list" and "csv") throw it away.

format-table: An associative array, where the key is the row id, and the value is the column data. The column data is also an associative array where the key is the column id and the value is the cell data. The cell data should usually be a simple string; however, some formatters can recursively format their cell contents before rendering (e.g. if a cell contains a list of items in an array).

These definitions align with the declared 'output-data-type' declared in command records. Any output format that does not declare any engine capabilities is expected to be able to render any php data structure that is passed to it.

See also

drush_parse_command().

File

commands/core/outputformat.drush.inc, line 116
Core drush output formats.

Code

function outputformat_drush_engine_outputformat() {
  $common_topic_example = array(
    "a" => array(
      "b" => 2,
      "c" => 3,
    ),
    "d" => array(
      "e" => 5,
      "f" => 6,
    ),
  );

  $engines = array();
  $engines['table'] = array(
    'description' => 'A formatted, word-wrapped table.',
    'engine-capabilities' => array('format-table'),
  );
  $engines['key-value'] = array(
    'description' => 'A formatted list of key-value pairs.',
    'engine-capabilities' => array('format-single', 'format-list', 'format-table'),
    'hidden' => TRUE,
  );
  $engines['key-value-list'] = array(
    'implemented-by' => 'list',
    'list-item-type' => 'key-value',
    'description' => 'A list of formatted lists of key-value pairs.',
    'list-field-selection-control' => 1,
    'engine-capabilities' => array('format-table'),
    'hidden' => TRUE,
  );
  $engines['json'] = array(
    'machine-parsable' => TRUE,
    'description' => 'Javascript Object Notation.',
    'topic-example' => $common_topic_example,
  );
  $engines['string'] = array(
    'machine-parsable' => TRUE,
    'description' => 'A simple string.',
    'engine-capabilities' => array('format-single'),
  );
  $engines['message'] = array(
    'machine-parsable' => FALSE, // depends on the label....
    'hidden' => TRUE,
  );
  $engines['print-r'] = array(
    'machine-parsable' => TRUE,
    'description' => 'Output via php print_r function.',
    'verbose-only' => TRUE,
    'topic-example' => $common_topic_example,
  );
  $engines['var_export'] = array(
    'machine-parsable' => TRUE,
    'description' => 'An array in executable php format.',
    'topic-example' => $common_topic_example,
  );
  $engines['yaml'] = array(
    'machine-parsable' => TRUE,
    'description' => 'Yaml output format.',
    'topic-example' => $common_topic_example,
  );
  $engines['php'] = array(
    'machine-parsable' => TRUE,
    'description' => 'A serialized php string.',
    'verbose-only' => TRUE,
    'topic-example' => $common_topic_example,
  );
  $engines['config'] = array(
    'machine-parsable' => TRUE,
    'implemented-by' => 'list',
    'list-item-type' => 'var_export',
    'description' => "A configuration file in executable php format. The variable name is \"config\", and the variable keys are taken from the output data array's keys.",
    'metadata' => array(
      'variable-name' => 'config',
    ),
    'list-field-selection-control' => -1,
    'engine-capabilities' => array('format-list', 'format-table'),
    'verbose-only' => TRUE,
  );
  $engines['list'] = array(
    'machine-parsable' => TRUE,
    'list-item-type' => 'string',
    'description' => 'A simple list of values.',
    
    // When a table is printed as a list, only the array keys of the rows will print.
    'engine-capabilities' => array('format-list', 'format-table'),
    'topic-example' => array('a', 'b', 'c'),
  );
  $engines['nested-csv'] = array(
    'machine-parsable' => TRUE,
    'implemented-by' => 'list',
    'list-separator' => ',',
    'list-item-type' => 'csv-or-string',
    'hidden' => TRUE,
  );
  $engines['csv-or-string'] = array(
    'machine-parsable' => TRUE,
    'hidden' => TRUE,
  );
  $engines['csv'] = array(
    'machine-parsable' => TRUE,
    'implemented-by' => 'list',
    'list-item-type' => 'nested-csv',
    'labeled-list' => TRUE,
    'description' => 'A list of values, one per row, each of which is a comma-separated list of values.',
    'engine-capabilities' => array('format-table'),
    'topic-example' => array(array('a', 12, 'a@one.com'), array('b', 17, 'b@two.com')),
  );
  $engines['variables'] = array(
    'machine-parsable' => TRUE,
    'description' => 'A list of php variable assignments.',
    'engine-capabilities' => array('format-table'),
    'verbose-only' => TRUE,
    'list-field-selection-control' => -1,
    'topic-example' => $common_topic_example,
  );
  $engines['labeled-export'] = array(
    'machine-parsable' => TRUE,
    'description' => 'A list of php exports, labeled with a name.',
    'engine-capabilities' => array('format-table'),
    'verbose-only' => TRUE,
    'implemented-by' => 'list',
    'list-item-type' => 'var_export',
    'metadata' => array(
      'label-template' => '!label: !value',
    ),
    'list-field-selection-control' => -1,
    'topic-example' => $common_topic_example,
  );
  return $engines;
}