projectinfo.pm.inc

  1. 8.0.x commands/pm/projectinfo.pm.inc
  2. master commands/pm/projectinfo.pm.inc

Functions

File

commands/pm/projectinfo.pm.inc
View source
  1. <?php
  2. use Drush\Log\LogLevel;
  3. /**
  4. * Implementation of drush_hook_COMMAND_validate().
  5. */
  6. function drush_pm_projectinfo_validate() {
  7. $status = drush_get_option('status');
  8. if (!empty($status)) {
  9. if (!in_array($status, array('enabled', 'disabled'), TRUE)) {
  10. return drush_set_error('DRUSH_PM_INVALID_PROJECT_STATUS', dt('!status is not a valid project status.', array('!status' => $status)));
  11. }
  12. }
  13. }
  14. /**
  15. * Implementation of drush_hook_COMMAND().
  16. */
  17. function drush_pm_projectinfo() {
  18. // Get specific requests.
  19. $requests = pm_parse_arguments(func_get_args(), FALSE);
  20. // Get installed extensions and projects.
  21. $extensions = drush_get_extensions();
  22. $projects = drush_get_projects($extensions);
  23. // If user did not specify any projects, return them all
  24. if (empty($requests)) {
  25. $result = $projects;
  26. }
  27. else {
  28. $result = array();
  29. foreach ($requests as $name) {
  30. if (array_key_exists($name, $projects)) {
  31. $result[$name] = $projects[$name];
  32. }
  33. else {
  34. drush_log(dt('!project was not found.', array('!project' => $name)), LogLevel::WARNING);
  35. continue;
  36. }
  37. }
  38. }
  39. // Find the Drush commands that belong with each project.
  40. foreach ($result as $name => $project) {
  41. $drush_commands = pm_projectinfo_commands_in_project($project);
  42. if (!empty($drush_commands)) {
  43. $result[$name]['drush'] = $drush_commands;
  44. }
  45. }
  46. // If user specified --drush, remove projects with no drush extensions
  47. if (drush_get_option('drush')) {
  48. foreach ($result as $name => $project) {
  49. if (!array_key_exists('drush', $project)) {
  50. unset($result[$name]);
  51. }
  52. }
  53. }
  54. // If user specified --status=1|0, remove projects with a distinct status.
  55. if (($status = drush_get_option('status', FALSE)) !== FALSE) {
  56. $status_code = ($status == 'enabled') ? 1 : 0;
  57. foreach ($result as $name => $project) {
  58. if ($project['status'] != $status_code) {
  59. unset($result[$name]);
  60. }
  61. }
  62. }
  63. return $result;
  64. }
  65. function pm_projectinfo_commands_in_project($project) {
  66. $drush_commands = array();
  67. if (array_key_exists('path', $project)) {
  68. $commands = drush_get_commands();
  69. foreach ($commands as $commandname => $command) {
  70. if (!array_key_exists("is_alias", $command) && ($command['path'] == $project['path'])) {
  71. $drush_commands[] = $commandname;
  72. }
  73. }
  74. }
  75. return $drush_commands;
  76. }