Skip to content

Commit

Permalink
Rename and move GreetCommand (used in tests) (#5944)
Browse files Browse the repository at this point in the history
* Rename and move GreetCommand from Woot module

* Expand docs about authoring symfony console commands

* Fix URL to GreetCommands

* Delete the weird console+Annotated command
  • Loading branch information
weitzman committed Mar 29, 2024
1 parent e15ef3d commit 8aa7750
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
6 changes: 4 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Drush command info (annotations/attributes) can be altered from other modules. T

In the module that wants to alter a command info, add a class that:

1. The generator class namespace, relative to base namespace, should be `Drupal\<module-name>\Drush\CommandInfoAlterers` and the class file should be located under the `src/Drush/CommandInfoAlterers` directory.
1. The class namespace, relative to base namespace, should be `Drupal\<module-name>\Drush\CommandInfoAlterers` and the class file should be located under the `src/Drush/CommandInfoAlterers` directory.
1. The filename must have a name like FooCommandInfoAlterer.php. The prefix `Foo` can be whatever string you want. The file must end in `CommandInfoAlterer.php`.
1. The class must implement the `\Consolidation\AnnotatedCommand\CommandInfoAltererInterface`.
1. Implement the alteration logic in the `alterCommandInfo()` method.
Expand All @@ -72,7 +72,9 @@ In the module that wants to alter a command info, add a class that:
For an example, see [WootCommandInfoAlterer](https://github.com/drush-ops/drush/blob/13.x/sut/modules/unish/woot/src/Drush/CommandInfoAlterers/WootCommandInfoAlterer.php) provided by the testing 'woot' module.

## Symfony Console Commands
Drush lists and runs Symfony Console commands, in addition to more typical annotated commands. See [this test](https://github.com/drush-ops/drush/blob/eed106ae4510d5a2df89f8e7fd54b41ffb0aa5fa/tests/integration/AnnotatedCommandCase.php#L178-L180) and this [commandfile](https://github.com/drush-ops/drush/blob/13.x/sut/modules/unish/woot/src/Commands/GreetCommand.php).

Drush lists and runs Symfony Console commands, in addition to more typical annotated commands.
See [GreetCommands](https://github.com/drush-ops/drush/blob/13.x/sut/modules/unish/woot/src/Drush/Commands/GreetCommands.php) as an example. Note that these commands must conform to the usual class name and class namespace requirements. You might need to extend the Console class if you can't rename and move it.

## Auto-discovered commands (PSR4)

Expand Down
8 changes: 0 additions & 8 deletions sut/modules/unish/woot/drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ services:
arguments: ['%app.root%']
tags:
- { name: drush.command }
greet.command:
class: Drupal\woot\Commands\GreetCommand
tags:
- { name: console.command }
annotated_greet.command:
class: Drupal\woot\Commands\AnnotatedGreetCommand
tags:
- { name: console.command }
44 changes: 0 additions & 44 deletions sut/modules/unish/woot/src/Commands/AnnotatedGreetCommand.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Drupal\woot\Commands;
namespace Drupal\woot\Drush\Commands;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -16,7 +16,7 @@
*
* See: http://symfony.com/doc/2.7/components/console/introduction.html#creating-a-basic-command
*/
class GreetCommand extends Command
class GreetCommands extends Command
{
protected function configure(): void
{
Expand Down

0 comments on commit 8aa7750

Please sign in to comment.