From 8be0cfbfc52662bed5ea3894d74b8e1d2e0a09be Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Sat, 3 Dec 2016 10:14:01 -0500 Subject: [PATCH] Handle @topic and @topics annotations in adapter. (#2483) * Handle @topic and @topics annotations in adapter. Port core-global_options topic. * Fix test expectation. --- commands/core/core.drush.inc | 20 ----------------- includes/annotationcommand_adapter.inc | 11 +++++---- lib/Drush/Commands/core/CoreCommands.php | 26 ++++++++++++++++++++++ lib/Drush/Commands/core/StatusCommands.php | 3 ++- tests/shellAliasTest.php | 2 +- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/commands/core/core.drush.inc b/commands/core/core.drush.inc index 96c4086411..bbe9ad98ba 100644 --- a/commands/core/core.drush.inc +++ b/commands/core/core.drush.inc @@ -225,18 +225,6 @@ function core_drush_command() { // Therefore we bootstrap to _FULL in commands/core/drupal/update.inc. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION, ); - $items['core-global-options'] = array( - 'description' => 'All global options', - 'hidden' => TRUE, - 'topic' => TRUE, - 'bootstrap' => DRUSH_BOOTSTRAP_NONE, - 'outputformat' => array( - 'default' => 'table', - 'pipe-format' => 'csv', - 'field-labels' => array('label' => 'Label', 'description' => 'Description'), - 'output-data-type' => 'format-table', - ), - ); $items['core-quick-drupal'] = array( 'description' => 'Download, install, serve and login to Drupal with minimal configuration and dependencies.', 'bootstrap' => DRUSH_BOOTSTRAP_NONE, @@ -549,14 +537,6 @@ function _drush_core_status_format_table_data($output, $metadata) { return $output; } -// Command callback. Show all global options. Exposed via topic command. -function drush_core_global_options() { - drush_print(dt('These options are applicable to most drush commands. Most options can be disabled by using --no-option (i.e. --no-debug to disable --debug.)')); - drush_print(); - $fake = drush_global_options_command(FALSE); - return drush_format_help_section($fake, 'options'); -} - function _drush_core_is_named_in_array($key, $the_array) { $is_named = FALSE; diff --git a/includes/annotationcommand_adapter.inc b/includes/annotationcommand_adapter.inc index 275e95dfc4..6f170c35e7 100644 --- a/includes/annotationcommand_adapter.inc +++ b/includes/annotationcommand_adapter.inc @@ -388,9 +388,6 @@ function annotationcommand_adapter_get_commands_for_commandhandler($commandhandl if ($command_name != $standard_alias) { $aliases[] = $standard_alias; } - $handle_remote_commands = $commandinfo->hasAnnotation('handle-remote-commands'); - $strict_option_handling = $commandinfo->hasAnnotation('strict-option-handling'); - $hidden = $commandinfo->hasAnnotation('hidden'); // If there is no 'bootstrap' annotation, default to NONE. $bootstrap = DRUSH_BOOTSTRAP_NONE; if ($bootstrap = $commandinfo->getAnnotation('bootstrap')) { @@ -408,10 +405,12 @@ function annotationcommand_adapter_get_commands_for_commandhandler($commandhandl 'description' => $commandinfo->getDescription(), 'examples' => $commandinfo->getExampleUsages(), 'bootstrap' => $bootstrap, - 'handle-remote-commands' => $handle_remote_commands, - 'strict_option_handling' => $strict_option_handling, - 'hidden' => $hidden, + 'handle-remote-commands' => $commandinfo->hasAnnotation('handle-remote-commands'), + 'strict_option_handling' => $commandinfo->hasAnnotation('strict-option-handling'), + 'hidden' => $commandinfo->hasAnnotation('hidden'), 'aliases' => $aliases, + 'topic' => $commandinfo->hasAnnotation('topic'), + 'topics' => _convert_csv_to_array($commandinfo->getAnnotation('topics')), 'add-options-to-arguments' => TRUE, 'consolidation-output-formatters' => TRUE, 'consolidation-option-defaults' => $commandinfo->options()->getValues(), diff --git a/lib/Drush/Commands/core/CoreCommands.php b/lib/Drush/Commands/core/CoreCommands.php index 177bc200f1..05f5bab116 100644 --- a/lib/Drush/Commands/core/CoreCommands.php +++ b/lib/Drush/Commands/core/CoreCommands.php @@ -220,5 +220,31 @@ function _drush_core_directory($target = 'root', $component = 'path', $local_onl } } + /** + * All global options. + * + * @command core-global-options + * @hidden + * @topic + * @bootstrap DRUSH_BOOTSTRAP_NONE + * + * @field-labels + * name: Name + * description: Description + * @default-fields name,description + */ + public function global_options($options = ['format' => 'table', 'fields' => '', 'include-field-labels' => FALSE]) { + drush_print(dt('These options are applicable to most Drush commands. Most options can be disabled by using --no-option (i.e. --no-debug to disable --debug.)')); + drush_print(); + $fake = drush_global_options_command(FALSE); + foreach ($fake['options'] as $key => $values) { + $rows[] = [ + 'name' => '--'. $key, + 'description' => $values['description'], + ]; + } + return new RowsOfFields($rows); + } + } \ No newline at end of file diff --git a/lib/Drush/Commands/core/StatusCommands.php b/lib/Drush/Commands/core/StatusCommands.php index b742cdbee1..d19d9784d3 100644 --- a/lib/Drush/Commands/core/StatusCommands.php +++ b/lib/Drush/Commands/core/StatusCommands.php @@ -3,13 +3,14 @@ namespace Drush\Commands\core; use Consolidation\AnnotatedCommand\AnnotationData; +use Drush\Commands\DrushCommands; use Symfony\Component\Console\Input\InputInterface; use Consolidation\OutputFormatters\StructuredData\AssociativeList; use Consolidation\OutputFormatters\Options\FormatterOptions; use Consolidation\AnnotatedCommand\CommandData; -class StatusCommands { +class StatusCommands extends DrushCommands { /** * @command core-status diff --git a/tests/shellAliasTest.php b/tests/shellAliasTest.php index fb48876b7d..e0a30f52e4 100644 --- a/tests/shellAliasTest.php +++ b/tests/shellAliasTest.php @@ -59,7 +59,7 @@ public function testShellAliasDrushLocal() { ); $this->drush('glopts', array(), $options); $output = $this->getOutput(); - $this->assertContains('These options are applicable to most drush commands.', $output, 'Successfully executed local shell alias to drush command'); + $this->assertContains('These options are applicable to most Drush commands.', $output, 'Successfully executed local shell alias to drush command'); } /**