I have used hook_drush_command to create a new drush command. This is my custom code for creating drush command.
/**
* Implementation of hook_drush_command().
*/
function mymodule_drush_command() {
$items = array();
// Name of the drush command.
$items['list-site-users'] = array(
'description' => 'Print the list of users in the site',
'callback' => 'drush_get_site_users',
);
return $items;
}
function drush_get_site_users() {
$query = db_select('users', 'u');
$query->fields('u', array('name'));
$result = $query->execute();
while($record = $result->fetchAssoc()) {
print_r($record['name']);
}
}
After this I have exceuted drush cc all
and drush cc drush
for clearing drush. Then I have executed my custom drush command drush list-site-users
command, but it is throwing the below error.
The drush command 'list-site-users' could not be found. Run
drush cache-clear drush
to clear the commandfile cache if you have installed new extensions.
My drush version is 5.10.0