Drush offers a very broad list of hooks to interact with existing commands. We can modify, react and extend them however we need it. We are going to demonstrate this by first describing each hook and then writing and testing an example that uses some of them. Following is the full list of hooks sorted by the order in which they are called with a short description of each one:
hook_drush_init()
is executed before any command is run.drush_COMMAND_init()
is called before a command is validated.drush_hook_COMMAND_validate()
validates a command. We used it in our custom command example in the previous section (drush_userblocker_user_blocker_validate()).drush_hook_pre_COMMAND()
operates before a command is going to be executed.drush_hook_COMMAND()
is the default callback implementation of a defined command athook_drush_command()
.drush_hook_post_COMMAND()
runs after a command has been executed.hook_drush_exit()
is called after any command...