So far, we saw some hooks that Drush supports before and after running a command. In order to discover them, Drush offers a debugging mode to view all the hooks that we can implement for a given command and check whether they were executed or not on runtime.
In the following example, we will define a very simple command that we will use to test the handy option --show-invoke
, which prints all the function callbacks where Drush attempts to find a match. We will create this command under $HOME/.drush/testhooks.drush.inc
, which makes it available for us everywhere in the command-line interface for our user:
<?php /** * @file * Sample Drush command to test hook invocations. */ /** * Implements hook_drush_command(). */ function testhooks_drush_command() { $items = array(); $items['testhooks'] = array( 'description' => 'Dummy command to test command invocations.', // No bootstrap at all. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); return...