Last active
December 21, 2015 22:09
-
-
Save pfaocle/6372975 to your computer and use it in GitHub Desktop.
An example of how to create a new Drush command which wraps an existing command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* An example of how to create a new Drush command which wraps an existing command, allowing some customisation. | |
* | |
* Note any file containing this snippet should be suffixed '.drush.inc', not '.drush.inc.php'. | |
*/ | |
/* Implements COMMANDFILE_drush_command(). */ | |
function sql_sync_wrapper_drush_command() { | |
$items = array(); | |
/* Get the set of commands in which the one we wish to call resides. The function | |
* is named COMMANDFILE_drush_command() so using something like: | |
* | |
* - grep -RB500 "\['sql-sync'\] = array" /usr/share/php/drush/commands | grep function | tail -1 | |
* | |
* will help dig this out (if it's a core Drush command). | |
* | |
* @see http://drush.ws/docs/commands.html | |
*/ | |
$sql_commands = sql_drush_command(); | |
if (isset($sql_commands['sql-sync'])) { | |
// Set up our new command based on the existing one... | |
$items['sql-sync-wrapped'] = $sql_commands['sql-sync']; | |
// ...and overwrite any elements necessary. | |
$items['sql-sync-wrapped']['description'] = 'Do something then copy and import source database to target database. Transfers via rsync.'; | |
} | |
return $items; | |
} | |
/* Initialise function for the new 'sql-sync-wrapped' command. */ | |
function drush_sql_sync_wrapped_init($source = NULL, $destination = NULL) { | |
// We can implement drush_COMMANDFILE_init() to perform any other tasks or checks. | |
} | |
/* Callback function for the new 'sql-sync-wrapped' command. */ | |
function drush_sql_sync_wrapped($source = NULL, $destination = NULL) { | |
// Do whatever we need to... | |
// ... | |
// Then call the command we're wrapping. We pass the arguments directly, whilst | |
// the command options used will be the same as those passed on the command line. | |
drush_invoke('sql-sync', array($source, $destination)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment