Last active
December 10, 2015 15:28
-
-
Save jonhattan/4454190 to your computer and use it in GitHub Desktop.
Example Drush commandfile. Place it in $HOME/.drush or /usr/share/drush/commands or any other valid location and clear drush cache afterwards.
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 | |
function mycommands_drush_command() { | |
$items = array(); | |
$items['one-command'] = array( | |
'description' => 'A command requiring two arguments.', | |
// Declare required arguments. | |
'arguments' => array( | |
'arg1' => 'arg1 description', | |
'arg2' => 'arg2 description', | |
), | |
); | |
$items['other-command'] = array( | |
'description' => 'Description for this command.', | |
// Declare options (as their name implies, are optional). | |
'options' => array( | |
'opt1' => 'opt1 description', | |
'opt2' => 'opt2 description', | |
), | |
); | |
return $items; | |
} | |
/** | |
* Callback for command one-command. | |
* | |
* Receive required command arguments as function parameters. | |
*/ | |
function drush_mycommands_one_command($arg1, $arg2) { | |
// ... | |
} | |
/** | |
* Callback for command other-command. | |
*/ | |
function drush_mycommands_other_command() { | |
// A command doesn't declare arguments but can receive a variable number of them. | |
$args = func_get_args(); | |
// Get option1. | |
$opt1 = drush_get_option('opt1', 'default-value'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment