
Writing custom drush commands in Drupal 8 is not exactly like Drupal 7 but it is similar. Here also, we are implementing hook_drush_command().
The only difference is in the file structure. As we all know In Drupal 8 ‘.module’ file is not mandatory in the module root folder. Hence In Drupal 8 for creating custom drush commands, we only need two files.
- MyModuleName.info.yml
- MyModuleName.drush.inc
Where,description will be listed under Other commands: (custom_drush_command)
'description' => 'Echo the name you type with Say hello commandSay hello.'

The command can be accessible in two ways by typing item_id say-hello' or using alias say:hello
drupal dependencies' => ['custom_drush_command'],
This tells to drupal that our drush command which has dependency, will work if we have our custom “custom_drush_command" installed.
In this way we can execute our custom new drush command using drush say:hello ‘your name’ or drush say-hello ‘your name’


How to enable and use:
- Install the module
- Open the terminal and ‘cd’ to your drupal root folder.
- drush cache-clear drush
- drush cr
- drush say:hello ‘your name’ or drush say-hello ‘your name’
Source Code: https://github.com/rakeshjames/custom_drush_command