4 * Output formatter 'table'
7 * The $data parameter is expected to be an array (keys ignored) of
8 * rows; each row, in turn, is an array of key / value pairs. Every
9 * row is expected to have the same set of keys. The data is rendered
10 * as a formatted word-wrapped table with rows of data cells aligned in
13 * 'field-labels' - If present, contains an array of key / value pairs
14 * that map from the keys in the row columns to the label for the
16 * 'column-widths' - If present, contains an array of key / value pairs,
17 * where the key is the integer column number, and the value is the
18 * width that column should be formatted to.
23 * "a" => array("b" => 2, "c" => 3),
24 * "d" => array("b" => 5, "c" => 6)
27 * Output with --format=table:
33 class drush_outputformat_table extends drush_outputformat {
34 function format($input, $metadata) {
35 $field_list = isset($metadata['field-labels']) ? $metadata['field-labels'] : array();
38 foreach($field_list as $key => $label) {
39 if (isset($metadata['column-widths'][$key])) {
40 $widths[$col] = $metadata['column-widths'][$key];
44 $rows = drush_rows_of_key_value_to_array_table($input, $field_list, $metadata);
45 $field_labels = array_key_exists('include-field-labels', $metadata) && $metadata['include-field-labels'];
49 return drush_format_table($rows, $field_labels, $widths);