From b5f7120deb3481a6614a50c1de69d51e1f87db6e Mon Sep 17 00:00:00 2001
From: Greg Anderson <greg.1.anderson@greenknowe.org>
Date: Fri, 30 Nov 2012 19:31:43 -0800
Subject:  Greg Anderson: Generated with Drush iq

---
 commands/core/core.drush.inc |   29 ++++-------------------
 commands/pm/info.pm.inc      |   52 ++++++++++++++++++++++++++--------------
 commands/pm/pm.drush.inc     |    5 ++++
 includes/output.inc          |   54 ++++++++++++++++++++++++++++++++++++++++++
 tests/COVERAGE.txt           |    2 +-
 tests/pmEnDisUnListTest.php  |   18 +++++++++++---
 6 files changed, 113 insertions(+), 47 deletions(-)

diff --git a/commands/core/core.drush.inc b/commands/core/core.drush.inc
index 2e4fe06..842c4ef 100644
--- a/commands/core/core.drush.inc
+++ b/commands/core/core.drush.inc
@@ -457,16 +457,6 @@ function _core_site_credential_table($status_table) {
   return $credentials;
 }
 
-function _core_site_credential_list($status_table) {
-  $credentials = '';
-  foreach ($status_table as $key => $value) {
-    if (isset($value)) {
-      $credentials .= sprintf("%s=%s\n", strtolower(str_replace(' ', '_', $key)), $value);
-    }
-  }
-  return $credentials;
-}
-
 function _core_path_aliases($project = '') {
   $paths = array();
   if ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT')) {
@@ -774,21 +764,10 @@ function drush_core_status() {
   }
   $return = $status_table;
   unset($status_table['%paths']);
-  // Print either an ini-format list or a formatted ASCII table
-  if (drush_get_option('pipe')) {
-    if (count($status_table) == 1) {
-      $first_value = array_shift($status_table);
-      drush_print_pipe($first_value);
-    }
-    else {
-      drush_print_pipe(_core_site_credential_list($status_table));
-    }
-  }
-  else {
-    unset($status_table['Modules path']);
-    unset($status_table['Themes path']);
-    drush_print_table(drush_key_value_to_array_table($status_table));
-  }
+  unset($status_table['Modules path']);
+  unset($status_table['Themes path']);
+  drush_print_table(drush_key_value_to_array_table($status_table));
+  drush_print_pipe(drush_format($return, NULL, 'ini-or-single'));
   return $return;
 }
 
diff --git a/commands/pm/info.pm.inc b/commands/pm/info.pm.inc
index 0b92771..26786ca 100644
--- a/commands/pm/info.pm.inc
+++ b/commands/pm/info.pm.inc
@@ -4,6 +4,7 @@
  * Command callback. Show detailed info for one or more extensions.
  */
 function drush_pm_info() {
+  $result = array();
   $args = pm_parse_arguments(func_get_args());
 
   $extension_info = drush_get_extensions(FALSE);
@@ -27,9 +28,28 @@ function drush_pm_info() {
     else {
       $data = _drush_pm_info_theme($info);
     }
-    drush_print_table(drush_key_value_to_array_table($data));
+    $result[$extension] = $data;
+    drush_print_table(drush_key_value_to_array_table(_drush_pm_info_format_table_data($data)));
     print "\n";
   }
+  drush_print_pipe(drush_format($result, NULL, 'ini-list'));
+  return $result;
+}
+
+function _drush_pm_info_format_table_data($data) {
+  $result = array();
+  foreach( $data as $key => $value) {
+    if (is_array($value)) {
+      if (empty($value)) {
+        $value = 'none';
+      }
+      else {
+        $value = implode(', ', $value);
+      }
+    }
+    $result[$key] = $value;
+  }
+  return $result;
 }
 
 /**
@@ -74,24 +94,21 @@ function _drush_pm_info_module($info) {
   }
   $data['Schema version'] = $schema_version;
   if ($major_version == 7) {
-    $data['Files'] = implode(', ', $info->info['files']);
-  }
-  if (count($info->info['dependencies']) > 0) {
-    $requires = implode(', ', $info->info['dependencies']);
+    $data['Files'] = $info->info['files'];
   }
-  else {
-    $requires = "none";
-  }
-  $data['Requires'] = $requires;
+  $data['Requires'] = $info->info['dependencies'];
 
   if ($major_version == 6) {
-    $requiredby = !empty($info->info['dependents'])?$info->info['dependents']:array("none");
+    $requiredby = $info->info['dependents'];
   }
   else {
-    $requiredby = !empty($info->required_by)?array_keys($info->required_by):array("none");
+    $requiredby = array_keys($info->required_by);
+  }
+  $data['Required by'] = $requiredby;
+  if ($info->status == 1) {
+    $role = drush_role_get_class();
+    $data['Permissions'] = $role->getModulePerms($info->name);
   }
-  $data['Required by'] = implode(', ', $requiredby);
-
   return $data;
 }
 
@@ -107,21 +124,20 @@ function _drush_pm_info_theme($info) {
   $data['PHP'] = $info->info['php'];
   $data['Engine'] = $info->info['engine'];
   $data['Base theme'] = isset($info->base_themes) ? implode($info->base_themes, ', ') : '';
-  $regions = implode(', ', $info->info['regions']);
+  $regions = $info->info['regions'];
   $data['Regions'] = $regions;
-  $features = implode(', ', $info->info['features']);
+  $features = $info->info['features'];
   $data['Features'] = $features;
   if (count($info->info['stylesheets']) > 0) {
     $data['Stylesheets'] = '';
     foreach ($info->info['stylesheets'] as $media => $files) {
-      $files = implode(', ', array_keys($files));
+      $files = array_keys($files);
       $data['Media '.$media] = $files;
     }
   }
   if (count($info->info['scripts']) > 0) {
-    $scripts = implode(', ', array_keys($info->info['scripts']));
+    $scripts = array_keys($info->info['scripts']);
     $data['Scripts'] = $scripts;
   }
   return $data;
 }
-
diff --git a/commands/pm/pm.drush.inc b/commands/pm/pm.drush.inc
index af4784f..ba183fe 100644
--- a/commands/pm/pm.drush.inc
+++ b/commands/pm/pm.drush.inc
@@ -892,9 +892,14 @@ function drush_pm_enable() {
   // Inform the user of final status.
   $result_extensions = drush_get_named_extensions_list($extensions);
   $problem_extensions = array();
+  $role = drush_role_get_class();
   foreach ($result_extensions as $name => $extension) {
     if ($extension->status) {
       drush_log(dt('!extension was enabled successfully.', array('!extension' => $extension->name)), 'ok');
+      $perms = $role->getModulePerms($extension->name);
+      if (!empty($perms)) {
+        drush_print(dt('!extension defines the following permissions: !perms', array('!extension' => $extension->name, '!perms' => implode(', ', $perms))));
+      }
     }
     else {
       $problem_extensions[] = $extension->name;
diff --git a/includes/output.inc b/includes/output.inc
index 8b21664..8249a7c 100644
--- a/includes/output.inc
+++ b/includes/output.inc
@@ -77,6 +77,23 @@ function drush_print_r($array, $handle = NULL, $newline = TRUE) {
  *   A variable.
  * @param string $label
  *   Optional prefix. Not used by JSON format.
+ * @param string $format
+ *   Optional format; defaults to print_r.
+ *     print_r: output with print_r function
+ *     export: output with var_export. Prefix with "$variables['label'] = "
+ *       if label is given.
+ *     config: output with var_export. Prefix with "$config['label'] = "
+ *       if label is given.
+ *     json: output with drush_json_encode
+ *     ini: output data that could be parsed by parse_ini_string
+ *     ini-or-single: output a single string if there is only
+ *       one item in the input; otherwise, output in ini format.
+ *     ini-list: input contains an associative array where
+ *       the key is the ini section, and the value is an array
+ *       of data to output in ini format.
+ *     export-list, config-list: An array of items to be output
+ *       with var_export; the array key is used as the label.
+ *     list: Print a list of key: value items.
  * @return string
  *   The variable formatted according to specified format. Ready for drush_print().
  */
@@ -84,6 +101,18 @@ function drush_format($input, $label = NULL, $format = NULL) {
   if (is_null(($format))) {
     $format = drush_get_option('format', 'print_r');
   }
+  // Handle FORMAT-list, an array of items to be output in FORMAT
+  if (substr($format, -4) == "list") {
+    $format = substr($format, 0, -5);
+    $result = '';
+    if (is_array($input)) {
+      foreach ($input as $label => $data) {
+        $result .= drush_format($data, $label, $format);
+        $result .= "\n";
+      }
+    }
+    return $result;
+  }
   if ($format != 'export' && $format != 'config') {
     if ($input === TRUE) {
       $input = 'TRUE';
@@ -113,6 +142,31 @@ function drush_format($input, $label = NULL, $format = NULL) {
     case 'json':
       $output = drush_json_encode($input);
       break;
+    case 'ini-or-single':
+    case 'ini':
+      if (is_array($input)) {
+        $output = '';
+        if (isset($label)) {
+          $output = "[$label]\n";
+        }
+        if (($format == 'ini-or-single') && (count($input) == 1)) {
+          $output = array_shift($input);
+        }
+        else {
+          foreach ($input as $key => $value) {
+            if (isset($value)) {
+              if (is_array($value)) {
+                $value = implode(', ', $value);
+              }
+              $output .= sprintf("%s=%s\n", strtolower(str_replace(' ', '_', $key)), $value);
+            }
+          }
+        }
+      }
+      else {
+        $output = drush_format($input, $label, 'print_r');
+      }
+      break;
     case 'print_r':
     default:
       if (is_string($input)) {
diff --git a/tests/COVERAGE.txt b/tests/COVERAGE.txt
index 959190f..543a6f6 100644
--- a/tests/COVERAGE.txt
+++ b/tests/COVERAGE.txt
@@ -10,7 +10,7 @@ pm-enable: GOOD. testEnDisUnList().
 pm-disable: GOOD. testEnDisUnList().
 pm-uninstall: GOOD. testEnDisUnList().
 pm-list: GOOD. testEnDisUnList().
-pm-info:
+pm-info: GOOD. testEnDisUnList().
 pm-refresh:
 version-control: FAIR. See updatecode. To be deprecated all git workflow after git.drupal.org?
 package-hander:
diff --git a/tests/pmEnDisUnListTest.php b/tests/pmEnDisUnListTest.php
index df6d3ed..a34daaa 100644
--- a/tests/pmEnDisUnListTest.php
+++ b/tests/pmEnDisUnListTest.php
@@ -13,21 +13,33 @@ class EnDisUnListCase extends Drush_CommandTestCase {
 
   public function testEnDisUnList() {
     $sites = $this->setUpDrupal(1, TRUE);
-    $options = array(
+    $options_no_pipe = array(
       'yes' => NULL,
-      'pipe' => NULL,
       'root' => $this->webroot(),
       'uri' => key($sites),
       'cache' => NULL,
       'skip' => NULL, // No FirePHP
       'invoke' => NULL, // Don't validate options
     );
+    $options = $options_no_pipe + array(
+      'pipe' => NULL,
+    );
     $this->drush('pm-download', array('devel'), $options);
     $this->drush('pm-list', array(), $options + array('no-core' => NULL, 'status' => 'not installed'));
     $list = $this->getOutputAsList();
     $this->assertTrue(in_array('devel', $list));
 
-    $this->drush('pm-enable', array('devel'), $options);
+    $this->drush('pm-enable', array('devel'), $options_no_pipe);
+    $output = $this->getOutput();
+    $this->assertContains('access devel information', $output);
+    $this->drush('pm-info', array('devel'), $options);
+    $output = $this->getOutput();
+    $this->assertContains('extension=devel', $output);
+    $this->assertContains('project=devel', $output);
+    $this->assertContains('type=module', $output);
+    $this->assertContains('title=Devel', $output);
+    $this->assertContains('status=enabled', $output);
+    $this->assertContains('access devel information', $output);
     $this->drush('pm-list', array(), $options + array('status' => 'enabled'));
     $list = $this->getOutputAsList();
     $this->assertTrue(in_array('devel', $list));
-- 
1.7.9.5

