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)

Asks the user a basic yes/no question.

Parameters

string $msg: The question to ask.

int $indent: The number of spaces to indent the message.

Return value

bool TRUE if the user enters "y" or FALSE if "n".

Related topics

26 calls to drush_confirm()
drush_core_pre_site_install in commands/core/site_install.drush.inc
Perform setup tasks for installation.
drush_core_rsync in commands/core/rsync.core.inc
Entrypoint for drush rsync.
drush_core_watchdog_delete in commands/core/watchdog.drush.inc
Command callback.
drush_do_multiple_command in includes/drush.inc
Used by functions that operate on lists of sites, moving information from the source to the destination. Currenlty this includes 'drush rsync' and 'drush sql sync'.
drush_field_delete in commands/core/field.drush.inc

... See full list

File

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

Code

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

  // Automatically accept confirmations if the --yes argument was supplied.
  if (drush_get_context('DRUSH_AFFIRMATIVE')) {
    drush_print("y");
    return TRUE;
  }
  // Automatically cancel confirmations if the --no argument was supplied.
  elseif (drush_get_context('DRUSH_NEGATIVE')) {
    drush_print("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;
    }
    drush_print_prompt((string) $msg . " (y/n): ", $indent);
  }
}