table.html

  1. 8.0.x commands/core/outputformat/topics/table.html
  2. 6.x commands/core/outputformat/topics/table.html
  3. 7.x commands/core/outputformat/topics/table.html
  4. master commands/core/outputformat/topics/table.html

File

commands/core/outputformat/topics/table.html
View source
The 'table' formatter will convert an associative array into a formatted,
word-wrapped table.  Each item in the associative array represents one row
in the table.  Each row is similarly composed of associative arrays, with
the key of each item indicating the column, and the value indicating the
contents of the cell.  See below for an example source array.
<p>
The command core-requirements is an example of a command that produces output
in a tabular format.
<p>
<i>$ drush core-requirements</i>
<pre>
 Title                 Severity  Description
 Cron maintenance      Error     Last run 2 weeks ago
 tasks                           Cron has not run recently. For more
                                 information, see the online handbook entry for
                                 configuring cron jobs. You can run cron
                                 manually.
 Drupal                Info      7.19
</pre>
(Note: the output above has been shortened for clarity; the actual output
of core-requirements contains additional rows not shown here.)
<p>
It is possible to determine the available fields by consulting <i>drush
help core requirements</i>:
<pre>
 --fields=&lt;title, severity, description&gt;   Fields to output. All
                                           available fields are:
                                           title, severity, sid,
                                           description, value,
                                           reason, weight.
</pre>
It is possible to control the fields that appear in the table, and their
order, by naming the desired fields in the --fields option.  The space
between items is optional, so `--fields=title,sid` is valid.
<p>
Code:
<pre>
return array (
  'cron' =>
  array (
    'title' => 'Cron maintenance tasks',
    'severity' => 2,
    'value' => 'Last run 2 weeks ago',
    'description' => 'Cron has not run recently. For more information, see the online handbook entry for <a href="http://drupal.org/cron">configuring cron jobs</a>. You can <a href="/admin/reports/status/run-cron">run cron manually</a>.',
    'severity-label' => 'Error',
  ),
  'drupal' =>
  array (
    'title' => 'Drupal',
    'value' => '7.19',
    'severity' => -1,
    'weight' => -10,
    'severity-label' => 'Info',
  ),
)
</pre>