Creating a custom Drush command
Throughout this book, we have used Drush to perform operations on a Drupal site from the command line. Custom commands for Drush can be provided by modules. This allows developers to create commands that help them manage their Drupal sites. Drush requires modules to provide a composer.json
file that instructs them where to load a services file that will register Drush commands.
In this recipe, we will create a new Drush command for a custom module that prints the location of where Drupal is installed.
How to do it…
- Drush provides a command to generate the required files for creating a command file for custom commands. To begin, run the following command:
php vendor/bin/drush generate drush-command-file
- You will be prompted to provide a value for the
Module
machine name; typemymodule
for the name of our module. - Next, press Enter to skip converting a legacy Drush command file.
- The command output will display the files that...