function drush_confirm

8.0.x drush.inc drush_confirm($msg, $indent = 0)
6.x drush.inc drush_confirm($msg, $indent = 0)
7.x drush.inc drush_confirm($msg, $indent = 0)
3.x drush.inc drush_confirm($msg, $indent = 0)
5.x drush.inc drush_confirm($msg, $indent = 0)
master drush.inc drush_confirm($msg, $indent = 0)

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'

17 calls to drush_confirm()

File

includes/drush.inc, line 852
The drush API implementation and helpers.

Code

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

  // Automatically accept confirmations if the --yes argument was supplied.
  if (drush_get_context('DRUSH_AFFIRMATIVE')) {
    print "y\n";
    return TRUE;
  }
  // Automatically cancel confirmations if the --no argument was supplied.
  elseif (drush_get_context('DRUSH_NEGATIVE')) {
    print "n\n";
    return FALSE;
  }
  // See http://drupal.org/node/499758 before changing this.
  $stdin = fopen("php://stdin", "r");

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