Skip to main content
Submitted by admin on 14 February 2023

Step 1: Create a module

Create a .info.yml file

Custom-Drush.png

Step 2: Create a service using services.yml

Create a .services.yml file

Services YML

 

Step 3: Create a Drush service class

Now let’s extend the DrushCommands base class.

Use Drush

 

Path to the class file should be: 

<module>/src/Commands/BatchCommands.php

Batch Command

 

Under this class, each method can be a command function if it is properly annotated.

Step 4: Create annotated methods

Print Info

 

Here are a few of the common annotated commands:

@option 
@usage 
@command 
@param 
@process
@aliases 
@status
@extract

Step 5: Clear cache

Now let’s clear the cache to flush all caches with this command:

drush cr

Start using the new custom command you just created:

drush custom-message <message>

Custom Message