Skip to content

Commit

Permalink
Add an attribute for formatter options (#5805)
Browse files Browse the repository at this point in the history
* Add an attribute for formatter options

* Revert changed to QueueCommands
  • Loading branch information
weitzman authored Nov 5, 2023
1 parent 25b4b82 commit 0175517
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
35 changes: 35 additions & 0 deletions src/Attributes/Format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Drush\Attributes;

use Attribute;
use Consolidation\AnnotatedCommand\Parser\CommandInfo;
use Consolidation\OutputFormatters\Options\FormatterOptions;
use Drush\Boot\Kernels;
use JetBrains\PhpStorm\ExpectedValues;

#[Attribute(Attribute::TARGET_METHOD)]
class Format
{
/**
* @param ?string $listDelimiter
* The delimiter between fields
* @param ?string $tableStyle
* The table style.
*/
public function __construct(
public ?string $listDelimiter,
# Sadly, \Symfony\Component\Console\Helper\Table::initStyles is private.
#[ExpectedValues(['box', 'box-double', 'borderless', 'compact', 'consolidation'])] public ?string $tableStyle
) {
}

public static function handle(\ReflectionAttribute $attribute, CommandInfo $commandInfo)
{
$instance = $attribute->newInstance();
$commandInfo->addAnnotation(FormatterOptions::LIST_DELIMITER, $instance->listDelimiter);
$commandInfo->addAnnotation(FormatterOptions::TABLE_STYLE, $instance->tableStyle);
}
}
2 changes: 1 addition & 1 deletion src/Attributes/Obsolete.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Mark commands as obsolete. These commands are omitted from help list and when
* user tries to run one the commmand's description is shown. Example usage at https://github.com/drush-ops/drush/blob/12.x/src/Commands/LegacyCommands.php
* user tries to run one, the command's description is shown. Example usage at https://github.com/drush-ops/drush/blob/12.x/src/Commands/LegacyCommands.php
*/
#[Attribute(Attribute::TARGET_METHOD)]
class Obsolete extends NoArgumentsBase
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/core/CoreCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public function globalOptions($options = ['format' => 'table']): RowsOfFields
* Show Drush version.
*/
#[CLI\Command(name: self::VERSION)]
#[CLI\HookSelector(name: 'table-style', value: 'compact')]
#[CLI\HookSelector(name: 'list-delimiter', value: ':')]
#[CLI\Format(listDelimiter: ':', tableStyle: 'compact')]
#[CLI\FieldLabels(labels: ['drush-version' => 'Drush version'])]
public function version($options = ['format' => 'table']): PropertyList
{
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/core/StatusCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ final class StatusCommands extends DrushCommands implements SiteAliasManagerAwar
#[CLI\Option(name: 'project', description: 'A comma delimited list of projects. Their paths will be added to path-aliases section.')]
#[CLI\Usage(name: 'drush core-status --field=files', description: 'Emit just one field, not all the default fields.')]
#[CLI\Usage(name: 'drush core-status --fields=*', description: 'Emit all fields, not just the default ones.')]
#[CLI\HookSelector(name: 'table-style', value: 'compact')]
#[CLI\HookSelector(name: 'list-delimiter', value: ':')]
#[CLI\Format(listDelimiter: ':', tableStyle: 'compact')]
#[CLI\FieldLabels(labels: [
'drupal-version' => 'Drupal version',
'uri' => 'Site URI',
Expand Down

0 comments on commit 0175517

Please sign in to comment.