Skip to content

Commit

Permalink
drush-ops#8: Insure that cache-get and config-get help only shows out…
Browse files Browse the repository at this point in the history
…put formats that are usable by these commands.
  • Loading branch information
greg-1-anderson authored and mradcliffe committed Sep 12, 2013
1 parent 1b00478 commit 755193a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions commands/core/cache.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function cache_drush_command() {
'outputformat' => array(
'default' => 'print-r',
'pipe-format' => 'var_export',
'output-data-type' => TRUE,
),
'aliases' => array('cg'),
);
Expand Down
1 change: 1 addition & 0 deletions commands/core/config.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function config_drush_command() {
'outputformat' => array(
'default' => 'yaml',
'pipe-format' => 'var_export',
'output-data-type' => TRUE,
),
'aliases' => array('cget'),
'core' => array('8+'),
Expand Down
6 changes: 3 additions & 3 deletions commands/core/outputformat.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function outputformat_drush_help_alter(&$command) {
// If the command does not define specific field labels,
// then hide the help for --fields unless the command
// works with output format engines that format tables.
if (isset($outputformat['require-engine-capability'])) {
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']);
}
Expand Down Expand Up @@ -355,10 +355,10 @@ class drush_outputformat {
return ($this->formatter_type() == 'list') && ($this->sub_engine->supports_single_only());
}
function data_type($metadata) {
if (isset($metadata['metameta']['require-engine-capability'])) {
if (isset($metadata['metameta']['require-engine-capability']) && is_array($metadata['metameta']['require-engine-capability'])) {
return $metadata['metameta']['require-engine-capability'][0];
}
if (isset($metadata['require-engine-capability'])) {
if (isset($metadata['require-engine-capability']) && is_array($metadata['require-engine-capability'])) {
return $metadata['require-engine-capability'][0];
}
return 'unspecified';
Expand Down
19 changes: 12 additions & 7 deletions includes/engines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ function drush_merge_engine_data(&$command) {
unset($config[$engine_option_alias_name]);
}
}
// Make sure that 'require-engine-capability' is always an array.
if (isset($config['require-engine-capability']) && !is_array($config['require-engine-capability'])) {
// Convert single string values of 'require-engine-capability' to an array.
if (isset($config['require-engine-capability']) && is_string($config['require-engine-capability'])) {
$config['require-engine-capability'] = array($config['require-engine-capability']);
}
$command['engines'][$engine_type] = $config;
Expand Down Expand Up @@ -239,10 +239,15 @@ function drush_merge_engine_data(&$command) {
// it is assumed that the engine can satisfy all requirements.
if (array_key_exists('engine-capabilities', $data)) {
$engine_is_usable = FALSE;
foreach ($config['require-engine-capability'] as $required) {
// We need an engine that provides any one of the requirements.
if (in_array($required, $data['engine-capabilities'])) {
$engine_is_usable = TRUE;
// If 'require-engine-capability' is TRUE instead of an array,
// then only engines that are universal (do not declare any
// particular capabilities) are usable.
if (is_array($config['require-engine-capability'])) {
foreach ($config['require-engine-capability'] as $required) {
// We need an engine that provides any one of the requirements.
if (in_array($required, $data['engine-capabilities'])) {
$engine_is_usable = TRUE;
}
}
}
}
Expand All @@ -254,7 +259,7 @@ function drush_merge_engine_data(&$command) {
$engine_data['options'][$option]['description'] = array_key_exists('description', $data) ? $data['description'] : NULL;
if ($combine_help) {
$engine_data['options'][$option]['hidden'] = TRUE;
if (drush_get_context('DRUSH_VERBOSE') || !isset($data['verbose-only'])) {
if (drush_get_context('DRUSH_VERBOSE') || ($default == $engine) || !isset($data['verbose-only'])) {
$combine_help_data[$engine] = $engine . ': ' . $data['description'];
}
}
Expand Down

0 comments on commit 755193a

Please sign in to comment.