Repository navigation
Register annotated commands in Drupal Console. - #2081
greg-1-anderson wants to merge 8 commits into
Conversation
… instantiate them via an AnnotationCommandFactory.
423c5f6 to
0aaf2d7
Compare
|
Replaced old technique with something better. No longer overloads the "*Command.php" namespace, and instead looks for command files following their own rules. Untested, but on the right track. |
|
The latest commit (12daaa6) works great with the sample cli command I wrote (ported) for the default_content module. Search paths and naming conventions still need to be discussed and finalized. I am not set on (or even very happy with) the placeholder "CliTools" folder name that I am using now; just picked something quickly to get started. Does not work with Drush yet, but it will only be a small effort to fix up the PR there as well; I'm not going to do that tonight, but will have it working in short order. |
|
Now also works with Drush. |
|
Discussion on search paths and naming conventions for command files at consolidation/annotated-command#12 |
|
Just for fun, I added a generate:meme example command. We can take this out prior to merge if desired; in the interim, it is useful to have a test command bundled with the PR. Uses Impact font on a Mac. If running on some other platform, download Anton.ttf from https://googlefontdirectory.googlecode.com/hg/ofl/anton/ and place Anton.ttf in ~/.fonts. |
|
@greg-1-anderson Nice usage of annotations, we have been discussing using them before as you can see on issue Use annotations in Commands and the related PR Annotations in Drupal Commands. Our proposal for using annotation was for other purpose. We wanted annotations to define any behavior not related to Symfony/Console Command and make our commands as much as close to the official standard. Creating a basic Command - Symfony documentation As stated on issue definition
With that said, after discussing with the other project maintainers we don’t agree with creating a new Drupalisim or a new Drupal way to write Symfony/Console based Commands when there is a well accepted and defined standard provided and supported by the community. We really like the idea about decouple code create components to reuse between different Drupal CLI tools. |
|
I have an idea on how we could configure Symfony/Console commands without diverging from the Symfony API. Re-opening so I can push another commit here to demonstrate. |
d9f0906 to
c9b44a9
Compare
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| class MemeCommand extends Command |
There was a problem hiding this comment.
Commands extend Drupal\Console\Command\Command, just as always. These are Symfony commands.
|
As you can see from the diffs in this PR, the code now conforms to the Symfony/Console command API exactly, with annotations being used only as an optional configuration method. Having this in place also gets us one step closer to being able to use annotations to specify dependencies, as referenced in the comments above. The importance of this PR extends beyond the simple application of annotations for configuration. Using a common base class from Consolidation-org will allow us to do things such as share the output formatters library between Drush and Drupal Console. Drupal Console has a similar feature, but the consolidation output formatters are more complete, and using a common implementation will allow us to present a uniform interface for Drupal modules to use. I hope that you will find this new implementation more palatable than the previous one. Using annotations in Drupal Console core is not required; accepting this PR would allow module developers to use or not use them as they saw fit. |
|
Looking at this, thanks for the update @greg-1-anderson |
|
Support for annotations merged on PR #2642 |
This PR adds annotation command support to DrupalConsole.
Any command file
FooCommand.phpmay now contain either a DrupalConsole Symfony Console Command implementation, in which case it works as it always has, or, alternately, if the class FooCommand does not extend Drupal\Console\Command\Command, then it is presumed that the instance is an annotation command, and all of its public methods are registered as DrupalConsole commands.The purpose of this is to allow Drupal modules to implement simple, loosely-coupled commandline tool interfaces. These commands might be implemented by extending Robo, although this is not required.
I was planning on converting the DrupalConsole InitCommand into an annotation class, simply to demonstrate how that is done; however, since this command is already tightly coupled with Drupal\Console\Command\Command helpers,
getModule(), etc., doing this would be counterproductive; in general, it is a non-goal to convert core DrupalConsole commands into annotation commands. For a typical simple Drupal module, though, whose main purpose is to provide a CLI interface that simply calls a method or two in the module, the annotation class will be a win.Follow development in Drush at drush-ops/drush#2103.
DrupalConsole checklist (to consider / discuss):