Commands calling commands in Drupal Console

DrupalConsole is under heavy development and we are constantly adding new features based on project needs and user feedback.

One of the most recent feature is the capability for commands to call other commands.

The need for it became clear when we were executing commands like "generate:controller" and needed to execute another command by hand such as "router:rebuild" to rebuild the routing system. 

The initial idea was to chain command execution.  In order to do that in code you need to obtain the ChainCommandHelper and call the addCommand method passing the required arguments.

This is the added code to the "generate:controller" command:


You can take a look at the class helper source code here ChainCommandHelper.php

This is the result of executing the "generate:controller"

As you can see below the generated/updated file list, two messages are showing the routing routing system was rebuilt.

The "chain" command

When that functionality was completed I had a discussion with the other project maintainers and we came up with the idea to create a command that could read a configuration file containing a queue and execute several commands based on the sequence defined in the configuration file.

We decide to use a standard YAML file extension and not go with something like chain extension because we did not want to add a new Drupalism to the project.

I will be recording a video in detail of how to take advantage of this command, in the meantime you can take a look a this demostration of how to use it: 

If interested you can see how the code looks like:

  • Command class source code at ChainCommand file.
  • YAML file containing the commands to be executed at chain.yml file.

How this command can help me?

You can create your own chain command and define the common Drupal 8 features you use while writing a Drupal 8 module and execute one command to have those features generated, as example:

$ drupal chain --file=~/.console/chain/project-start.yml

NOTE: This a partial cross post from BlinkReaction site Drupal Console release 0.7.5