? includes/table.inc
Index: drush.info
===================================================================
RCS file: drush.info
diff -N drush.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ drush.info	20 Jan 2010 05:54:57 -0000
@@ -0,0 +1 @@
+version=3.0-dev
Index: commands/core/core.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/core.drush.inc,v
retrieving revision 1.69
diff -u -p -r1.69 core.drush.inc
--- commands/core/core.drush.inc	12 Jan 2010 14:45:09 -0000	1.69
+++ commands/core/core.drush.inc	20 Jan 2010 05:54:58 -0000
@@ -50,6 +50,13 @@ function core_drush_command() {
     'description' => 'Provides a birds-eye view of the current Drupal installation, if any.',
     'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
     'aliases' => array('st'),
+    'examples' => array(
+      'drush status version' => 'Show all status lines that contain version information.',
+      'drush status --pipe' => 'A space delimited list of status values with no labels.',
+    ),
+    'arguments' => array(
+      'item' => 'Optional.  The status item line to display.',
+    ),
   );
   $items['script'] = array(
     'description' => "Run php script(s).",
@@ -305,40 +312,57 @@ function core_drush_help($section) {
 
 // TODO: consolidate with SQL commands?
 function _core_site_credentials() {
-  $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE');
-  if (function_exists('php_ini_loaded_file')) {
-    // Function available on PHP >= 5.2.4, but we use it if available to help
-    // users figure out their php.ini issues.
-    $credentials = sprintf("  %-18s: %s\n", 'PHP configuration', php_ini_loaded_file());
+  $status_table = _core_site_status_table();
+  return _core_site_credential_table($status_table);
+}
+
+function _core_site_credential_table($status_table) {
+  $credentials = '';
+  foreach ($status_table as $key => $value) {
+      $credentials .= sprintf("  %-18s: %s\n", $key, $value);
   }
+  return $credentials;
+}
+
+function _core_site_credential_list($status_table) {
+  return implode(' ', $status_table);
+}
+
+function _core_site_status_table() {
+  $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE');
   if ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT')) {
-    $credentials .= sprintf("  %-18s: %s\n", 'Drupal Root', $drupal_root);
-    $credentials .= sprintf("  %-18s: %s\n", 'Drupal version', drush_drupal_version());
+    $status_table['Drupal Root'] = $drupal_root;
+    $status_table['Drupal Version'] = drush_drupal_version();
     if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
-      $credentials .= sprintf("  %-18s: %s\n", 'Site Path', $site_root);
-      $credentials .= sprintf("  %-18s: %s\n", 'Site URI', drush_get_context('DRUSH_URI'));
+      $status_table['Site Path'] = $site_root;
+      $status_table['Site URI'] = drush_get_context('DRUSH_URI');
       if ($creds = drush_get_context('DRUSH_DB_CREDENTIALS')) {
-        $credentials .= sprintf("  %-18s: %s\n", 'Database Driver', $creds['driver']);
-        $credentials .= sprintf("  %-18s: %s\n", 'Database Hostname', $creds['host']);
-        $credentials .= sprintf("  %-18s: %s\n", 'Database Username', $creds['user']);
-        $credentials .= sprintf("  %-18s: %s\n", 'Database Name', $creds['name']);
-        $credentials .= sprintf("  %-18s: %s\n", 'Database Password', $creds['pass']);
+        $status_table['Database Driver'] = $creds['driver'];
+        $status_table['Database Hostname'] = $creds['host'];
+        $status_table['Database Username'] = $creds['user'];
+        $status_table['Database Name'] = $creds['name'];
+        $status_table['Database Password'] = $creds['pass'];
         if ($phase > DRUSH_BOOTSTRAP_DRUPAL_DATABASE) {
-          $credentials .= sprintf("  %-18s: %s\n", 'Database', dt('Connected'));
+          $status_table['Database'] = dt('Connected');
           if ($phase > DRUSH_BOOTSTRAP_DRUPAL_FULL) {
-            $credentials .= sprintf("  %-18s: %s\n", 'Drupal Bootstrap', dt('Successful'));
+            $status_table['Drupal Bootstrap'] = dt('Successful');
             if ($phase == DRUSH_BOOTSTRAP_DRUPAL_LOGIN) {
               global $user;
               $username =  ($user->uid) ? $user->name : dt('Anonymous');
-              $credentials .= sprintf("  %-18s: %s\n", 'Drupal User', $username);
+              $status_table['Drupal User'] = $username;
             }
           }
         }
       }
     }
-    return $credentials;
   }
-  return dt("Could not find a valid Drupal installation\n");
+  if (function_exists('php_ini_loaded_file')) {
+    // Function available on PHP >= 5.2.4, but we use it if available to help
+    // users figure out their php.ini issues.
+    $status_table['PHP configuration'] = php_ini_loaded_file();
+  }
+  $status_table['Drush Version'] = DRUSH_VERSION;
+  return $status_table;
 }
 
 /**
@@ -367,10 +391,42 @@ function drush_core_cron() {
  */
 function drush_core_status() {
   drush_bootstrap_max();
-  print _core_site_credentials();
+  $status_table = _core_site_status_table();
+  // If args are specified, filter out any entry that is not named
+  // (in other words, only show lines named by one of the arg values)
+  $args = func_get_args();
+  if (!empty($args)) {
+    foreach ($status_table as $key => $value) {
+      if (!_drush_core_is_named_in_array($key, $args)) {
+        unset($status_table[$key]);
+      }
+    }
+  }
+  // Print either an ini-format list or a formatted ASCII table
+  if (drush_get_option('pipe')) {
+    drush_print_pipe(_core_site_credential_list($status_table));
+  }
+  else {
+    // print _core_site_credential_table($status_table);
+    drush_print_table($status_table);
+  }
   return;
 }
 
+function _drush_core_is_named_in_array($key, $the_array) {
+  $is_named = FALSE;
+  
+  $simplified_key = str_replace(array(' ', '_', '-'), array('', '', ''), $key);
+  
+  foreach ($the_array as $name) {
+    if (stristr($simplified_key, str_replace(array(' ', '_', '-'), array('', '', ''), $name))) {
+      $is_named = TRUE;
+    }
+  }
+  
+  return $is_named;
+}
+
 /**
  * Command callback. Runs "naked" php scripts.
  */
Index: includes/drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/drush.inc,v
retrieving revision 1.77
diff -u -p -r1.77 drush.inc
--- includes/drush.inc	15 Jan 2010 00:44:59 -0000	1.77
+++ includes/drush.inc	20 Jan 2010 05:54:58 -0000
@@ -631,6 +631,9 @@ function drush_print_table($rows, $heade
   // Do wordwrap on all cells.
   $newrows = array();
   foreach ($rows as $rowkey => $row) {
+    if (!is_array($row)) {
+      $row = array($rowkey, $row);
+    }
     foreach ($row as $col_num => $cell) {
       $newrows[$rowkey][$col_num] = wordwrap($cell, $auto_widths[$col_num], "\n", TRUE);
       if (isset($widths[$col_num])) {
@@ -665,6 +668,9 @@ function drush_table_column_autowidth($r
   // of rows where that character column is present.
   $col_dist = array();
   foreach ($rows as $rowkey => $row) {
+    if (!is_array($row)) {
+      $row = array($rowkey, $row);
+    }
     foreach ($row as $col_num => $cell) {
       if (empty($widths[$col_num])) {
         $length = strlen($cell);
Index: includes/environment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/environment.inc,v
retrieving revision 1.67
diff -u -p -r1.67 environment.inc
--- includes/environment.inc	18 Jan 2010 20:58:39 -0000	1.67
+++ includes/environment.inc	20 Jan 2010 05:54:59 -0000
@@ -392,7 +392,10 @@ function _drush_bootstrap_drush() {
 
   // statically define a way to call drush again
   define('DRUSH_COMMAND', drush_find_drush());
-
+  
+  $drush_info = drush_read_drush_info();
+  define('DRUSH_VERSION', $drush_info['version']);
+  
   // Load a drushrc.php file in the drush.php's directory.
   drush_load_config('drush');
 
@@ -974,6 +977,15 @@ function drush_find_drush() {
 }
 
 /**
+ * Read the drush info file.
+ */
+function drush_read_drush_info() {
+  $drush_info_file = dirname(__FILE__) . '/../drush.info';
+  
+  return parse_ini_file($drush_info_file);
+}
+
+/**
  * Get module information for all installed modules. Wrapper for _drush_get_modules().
  *
  * @return
