3 use Drush\Log\LogLevel;
6 * Implementation of drush_hook_COMMAND_validate().
8 function drush_pm_projectinfo_validate() {
9 $status = drush_get_option('status');
10 if (!empty($status)) {
11 if (!in_array($status, array('enabled', 'disabled'), TRUE)) {
12 return drush_set_error('DRUSH_PM_INVALID_PROJECT_STATUS', dt('!status is not a valid project status.', array('!status' => $status)));
18 * Implementation of drush_hook_COMMAND().
20 function drush_pm_projectinfo() {
21 // Get specific requests.
22 $requests = pm_parse_arguments(func_get_args(), FALSE);
24 // Get installed extensions and projects.
25 $extensions = drush_get_extensions();
26 $projects = drush_get_projects($extensions);
28 // If user did not specify any projects, return them all
29 if (empty($requests)) {
34 foreach ($requests as $name) {
35 if (array_key_exists($name, $projects)) {
36 $result[$name] = $projects[$name];
39 drush_log(dt('!project was not found.', array('!project' => $name)), LogLevel::WARNING);
45 // Find the Drush commands that belong with each project.
46 foreach ($result as $name => $project) {
47 $drush_commands = pm_projectinfo_commands_in_project($project);
48 if (!empty($drush_commands)) {
49 $result[$name]['drush'] = $drush_commands;
53 // If user specified --drush, remove projects with no drush extensions
54 if (drush_get_option('drush')) {
55 foreach ($result as $name => $project) {
56 if (!array_key_exists('drush', $project)) {
57 unset($result[$name]);
62 // If user specified --status=1|0, remove projects with a distinct status.
63 if (($status = drush_get_option('status', FALSE)) !== FALSE) {
64 $status_code = ($status == 'enabled') ? 1 : 0;
65 foreach ($result as $name => $project) {
66 if ($project['status'] != $status_code) {
67 unset($result[$name]);
75 function pm_projectinfo_commands_in_project($project) {
76 $drush_commands = array();
77 if (array_key_exists('path', $project)) {
78 $commands = drush_get_commands();
79 foreach ($commands as $commandname => $command) {
80 if (!array_key_exists("is_alias", $command) && ($command['path'] == $project['path'])) {
81 $drush_commands[] = $commandname;
85 return $drush_commands;