function drush_prompt

8.0.x drush.inc drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE)
6.x drush.inc drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE)
7.x drush.inc drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE)
3.x drush.inc drush_prompt($prompt, $default = NULL, $optional = FALSE)
4.x drush.inc drush_prompt($prompt, $default = NULL, $required = TRUE)
5.x drush.inc drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE)
master drush.inc drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE)

Prompt the user for input

The input can be anything that fits on a single line (not only y/n), so we can't use drush_confirm()

Parameters

$prompt: The text which is displayed to the user.

$default: The default value of the input.

$required: If TRUE, user may continue even when no value is in the input.

$password: If TRUE, surpress printing of the input.

See also

drush_confirm()

Related topics

2 calls to drush_prompt()
drush_field_create_wizard in commands/core/field.drush.inc
Prompt user enough to create basic field and instance.
drush_user_password in commands/user/user.drush.inc
Sets the password for the account with the given username

File

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

Code

function drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE) {
  if (isset($default)) {
    $prompt .= " [" . $default . "]";
  }
  $prompt .= ": ";

  drush_print_prompt($prompt);

  if (drush_get_context('DRUSH_AFFIRMATIVE')) {
    return $default;
  }

  $stdin = fopen('php://stdin', 'r');

  if ($password) {
    drush_shell_exec("stty -echo");
  }

  stream_set_blocking($stdin, TRUE);
  while (($line = fgets($stdin)) !== FALSE) {
    $line = trim($line);
    if ($line === "") {
      $line = $default;
    }
    if ($line || !$required) {
      break;
    }
    drush_print_prompt($prompt);
  }
  fclose($stdin);
  if ($password) {
    drush_shell_exec("stty echo");
    print "\n";
  }
  return $line;
}