Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

drush_confirm

Definition

drush_confirm($msg, $indent = 0)
contributions/drush/drush.inc, line 173

Description

Ask the user a basic yes/no question.

Parameters

$msg The question to ask

Return value

TRUE if the user entered 'y', FALSE if he entered 'n'

Code

<?php
function drush_confirm($msg, $indent = 0) {
  print str_repeat(' ', $indent) . (string)$msg . " (y/n): ";

  if (DRUSH_AFFIRMATIVE) {
    print "y\n";
    return TRUE;
  }
  while ($line = trim(fgets(STDIN))) {
    if ($line == 'y') {
      return TRUE;
    }
    if ($line == 'n') {
      return FALSE;
    }
    print str_repeat(' ', $indent) . (string)$msg . " (y/n): ";
  }

}
?>