Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No field labels #130

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions commands/core/outputformat.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function outputformat_drush_engine_type_info() {
'description' => 'In nested lists of lists, specify how the outer lists ("lines") should be separated.',
'hidden' => TRUE,
),
'no-field-labels' => array(
'description' => 'Leave off the field labels.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Show values without labels. For example, omits table headers, CSV headers, and labels in lists.".

Perhaps add an Example to a command that key-value and another to one that uses table.

),
),
// Allow output formats to declare their
// "output data type" instead of their
Expand Down Expand Up @@ -278,12 +281,14 @@ function outputformat_drush_help_alter(&$command) {
if (isset($outputformat['require-engine-capability']) && is_array($outputformat['require-engine-capability'])) {
if (!in_array('format-table', $outputformat['require-engine-capability'])) {
unset($command['options']['fields']);
unset($command['options']['no-field-labels']);
}
}
// If the command does define output formats, but does not
// define fields, then just hide the help for the --fields option.
else {
$command['options']['fields']['hidden'] = TRUE;
$command['options']['no-field-labels']['hidden'] = TRUE;
}
}

Expand Down
3 changes: 3 additions & 0 deletions commands/core/outputformat/key_value.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class drush_outputformat_key_value extends drush_outputformat {
if ((!isset($kv_metadata['key-value-item'])) && (isset($metadata['field-labels']))) {
$input = drush_select_output_fields($input, $metadata['field-labels'], $metadata['field-mappings']);
}
if (isset($metadata['no-field-labels'])) {
$kv_metadata['no-field-labels'] = $metadata['no-field-labels'];
}
$formatted_table = drush_key_value_to_array_table($input, $kv_metadata);
if ($formatted_table === FALSE) {
return FALSE;
Expand Down
7 changes: 6 additions & 1 deletion commands/core/outputformat/table.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class drush_outputformat_table extends drush_outputformat {
}
++$col;
}
return drush_format_table(drush_rows_of_key_value_to_array_table($input, $field_list, $metadata), TRUE, $widths);
$rows = drush_rows_of_key_value_to_array_table($input, $field_list, $metadata);
$field_labels = !array_key_exists('no-field-labels', $metadata);
if (!$field_labels) {
array_shift($rows);
}
return drush_format_table($rows, $field_labels, $widths);
}
}
5 changes: 5 additions & 0 deletions includes/output.inc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ function drush_key_value_to_array_table($keyvalue_table, $metadata = array()) {
if (is_array($value)) {
$value = drush_format($value, $metadata, 'list');
}
}
if (isset($metadata['no-field-labels'])) {
$table[] = array(isset($value) ? $value : '');
}
elseif (isset($value)) {
$table[] = array($key, ' :', $value);
}
else {
Expand Down