Skip to content

Commit

Permalink
Handle @topic and @topics annotations in adapter. (#2483)
Browse files Browse the repository at this point in the history
* Handle @topic and @topics annotations in adapter. Port core-global_options topic.

* Fix test expectation.
  • Loading branch information
weitzman committed Dec 3, 2016
1 parent a402a84 commit 8be0cfb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
20 changes: 0 additions & 20 deletions commands/core/core.drush.inc
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 5 additions & 6 deletions includes/annotationcommand_adapter.inc
Expand Up @@ -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')) {
Expand All @@ -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(),
Expand Down
26 changes: 26 additions & 0 deletions lib/Drush/Commands/core/CoreCommands.php
Expand Up @@ -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);
}


}
3 changes: 2 additions & 1 deletion lib/Drush/Commands/core/StatusCommands.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/shellAliasTest.php
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit 8be0cfb

Please sign in to comment.