? includes/table.inc
Index: includes/drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/drush.inc,v
retrieving revision 1.174
diff -u -p -r1.174 drush.inc
--- includes/drush.inc	24 Dec 2010 05:10:29 -0000	1.174
+++ includes/drush.inc	25 Dec 2010 15:48:07 -0000
@@ -229,7 +229,8 @@ function drush_get_global_options() {
   $options['-d, --debug']              = dt('Display even more information, including internal messages.');
   $options['-q, --quiet']              = dt('Hide all output');
   $options['-y, --yes']                = dt("Assume 'yes' as answer to all prompts");
-  $options['-n, --no']                = dt("Assume 'no' as answer to all prompts");
+  $options['-n, --no']                 = dt("Assume 'no' as answer to all prompts");
+  $options['--choice']                 = dt("Provide an answer to a multiple-choice prompt.");
   $options['-s, --simulate']           = dt("Simulate all relevant actions (don't actually change the system)");
   $options['-i, --include']            = dt("A list of paths to search for drush commands");
   $options['-c, --config']             = dt("Specify a config file to use. See example.drushrc.php");
@@ -638,12 +639,23 @@ function drush_table_column_autowidth($r
  *   Full path to a file.
  */
 function drush_print_file($file) {
+  // Don't even bother to print the file in --no mode
+  if (drush_get_context('DRUSH_NEGATIVE')) {
+    return;
+  }
   if ((substr($file,-4) == ".htm") || (substr($file,-5) == ".html")) {
     $tmp_file = drush_tempnam(basename($file));
     file_put_contents($tmp_file, drush_html_to_text(file_get_contents($file)));
     $file = $tmp_file;
   }
-  if (drush_shell_exec_interactive("less %s", $file)) {
+  // Do not wait for user input in --yes or --pipe modes
+  if (drush_get_context('DRUSH_PIPE')) {
+    drush_print_pipe(file_get_contents($file));
+  }
+  elseif (drush_get_context('DRUSH_AFFIRMATIVE')) {
+    drush_print(file_get_contents($file));
+  }
+  elseif (drush_shell_exec_interactive("less %s", $file)) {
     return;
   }
   elseif (drush_shell_exec_interactive("more %s", $file)) {
@@ -753,11 +765,40 @@ function drush_choice($options, $prompt 
     }
   }
   drush_print_table($rows);
+  drush_print_pipe(array_keys($options));
   
-  while ($line = trim(fgets(STDIN))) {
-    if (array_key_exists($line, $selection_list)) {
-      return $selection_list[$line];
+  // We won't allow --yes to subvert the selection process,
+  // but in backend and modes we will return the first option.
+  // Hopefully this will always be the "best choice".  Prompting
+  // the user is undesirable in these modes, though, so we
+  // need to do something to pick a reasonable default.
+  if (($choice = drush_get_option('choice', FALSE)) !== FALSE) {
+    // First check to see if $choice is one of the symbolic options
+    if (array_key_exists($choice, $options)) {
+      return $choice;
+    }
+    // Next handle numeric selections
+    elseif (array_key_exists($choice, $selection_list)) {
+      return $selection_list[$choice];
     }
+    return FALSE;
+  }
+  
+  // If the user specified --no, then cancel; also avoid
+  // getting hung up waiting for user input in --pipe and
+  // backend modes.  If none of these apply, then wait,
+  // for user input and return the selected result.
+  if (!drush_get_context('DRUSH_NEGATIVE') && !drush_get_context('DRUSH_AFFIRMATIVE') && !drush_get_context('DRUSH_PIPE')) {
+    while ($line = trim(fgets(STDIN))) {
+      if (array_key_exists($line, $selection_list)) {
+	return $selection_list[$line];
+      }
+    }
+  }
+  // We will allow --yes to confirm input if there is only
+  // one choice; otherwise, --yes will cancel to avoid ambiguity
+  if (drush_get_context('DRUSH_AFFIRMATIVE')  && (count($options) == 1)) {
+    return $selection_list[1];
   }
   drush_print(dt('Cancelled'));
   return FALSE;
