function drush_pm_list

8.0.x pm.drush.inc drush_pm_list()
6.x pm.drush.inc drush_pm_list()
7.x pm.drush.inc drush_pm_list()
3.x pm.drush.inc drush_pm_list()
4.x pm.drush.inc drush_pm_list()
5.x pm.drush.inc drush_pm_list()
master pm.drush.inc drush_pm_list()

Command callback. Show a list of modules and status.

File

commands/pm/pm.drush.inc, line 212
The drush Package Manager

Code

function drush_pm_list() {
  //--package
  $package_filter = array();
  $package = strtolower(drush_get_option('package'));
  if (!empty($package)) {
    $package_filter = explode(',', $package);
  }
  if (empty($package_filter) || count($package_filter) > 1) {
    $header[] = dt('Package');
  }

  $header[] = dt('Name');

  //--type
  $all_types = array('module', 'theme');
  $type_filter = strtolower(drush_get_option('type'));
  if (!empty($type_filter)) {
    $type_filter = explode(',', $type_filter);
  }
  else {
    $type_filter = $all_types;
  }

  if (count($type_filter) > 1) {
    $header[] = dt('Type');
  }
  foreach ($type_filter as $type) {
    if (!in_array($type, $all_types)) { //TODO: this kind of chck can be implemented drush-wide
      return drush_set_error('DRUSH_PM_INVALID_PROJECT_TYPE', dt('!type is not a valid project type.', array('!type' => $type)));
    }
  }

  //--status
  $all_status = array('enabled', 'disabled', 'not installed');
  $status_filter = strtolower(drush_get_option('status'));
  if (!empty($status_filter)) {
    $status_filter = explode(',', $status_filter);
  }
  else {
    $status_filter = $all_status;
  }
  if (count($status_filter) > 1) {
    $header[] = dt('Status');
  }

  foreach ($status_filter as $status) {
    if (!in_array($status, $status_filter)) { //TODO: this kind of chck can be implemented drush-wide
      return drush_set_error('DRUSH_PM_INVALID_PROJECT_TYPE', dt('!status is not a valid project status.', array('!status' => $status)));
    }
  }

  $header[] = dt('Version');
  $rows[] = $header;

  $projects = drush_pm_get_projects();
  uasort($projects, '_drush_pm_sort_projects');

  $major_version = drush_drupal_major_version();
  foreach ($projects as $project) {
    if (!in_array($project->type, $type_filter)) {
      continue;
    }
    $status = drush_get_project_status($project);
    if (!in_array($status, $status_filter)) {
      continue;
    }
    if (($major_version >= 7) and (isset($project->info['hidden']))) {
      continue;
    }

    // filter by package
    if (!empty($package_filter)) {
      if (!in_array(strtolower($project->info['package']), $package_filter)) {
        continue;
      }
    }

    if (empty($package_filter) || count($package_filter) > 1) {
      $row[] = $project->info['package'];
    }

    if (($major_version >= 6) || ($project->type == 'module')) {
      $row[] = $project->info['name'] . ' (' . $project->name . ')';
    }
    else {
      $row[] = $project->name;
    }
    if (count($type_filter) > 1) {
      $row[] = ucfirst($project->type);
    }
    if (count($status_filter) > 1) {
      $row[] = ucfirst($status);
    }
    if (($major_version >= 6) || ($project->type == 'module')) {
      $row[] = $project->info['version'];
    }

    $rows[] = $row;
    $pipe[] = $project->name;
    unset($row);
  }
  drush_print_table($rows, TRUE);

  if (isset($pipe)) {
    // Newline-delimited list for use by other scripts. Set the --pipe option.
    drush_print_pipe($pipe);
  }
}