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

31 calls to drush_confirm()
drush_config_edit in commands/core/config.drush.inc
Edit command callback.
drush_config_import in commands/core/config.drush.inc
Command callback. Import from specified config directory (defaults to sync).
drush_config_set in commands/core/config.drush.inc
Config set command callback.
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
A command callback.

... See full list

File

includes/drush.inc, line 394
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);
  }
}