Step 1: Create a module
Create a .info.yml file
Step 2: Create a service using services.yml
Create a .services.yml file
Step 3: Create a Drush service class
Now let’s extend the DrushCommands base class.
Path to the class file should be:
<module>/src/Commands/BatchCommands.php
Under this class, each method can be a command function if it is properly annotated.
Step 4: Create annotated methods
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>