function drush_choice

8.0.x drush_choice($options, $prompt = 'Enter a number.', $label = '!value', $widths = array())
6.x drush_choice($options, $prompt = 'Enter a number.', $label = '!value', $widths = array())
7.x drush_choice($options, $prompt = 'Enter a number.', $label = '!value', $widths = array())
3.x drush_choice($options, $prompt = 'Enter a number.', $label = '!value')
4.x drush_choice($options, $prompt = 'Enter a number.', $label = '!value')
5.x drush_choice($options, $prompt = 'Enter a number.', $label = '!value', $widths = array())
master drush_choice($options, $prompt = 'Enter a number.', $label = '!value', $widths = array())

Ask the user to select an item from a list. From a provided associative array, drush_choice will display all of the questions, numbered from 1 to N, and return the item the user selected. "0" is always cancel; entering a blank line is also interpreted as cancelling.


$options: A list of questions to display to the user. The KEYS of the array are the result codes to return to the caller; the VALUES are the messages to display on each line. Special keys of the form '-- something --' can be provided as separator between choices groups. Separator keys don't alter the numbering.

$prompt: The message to display to the user prompting for input.

$label: Controls the display of each line. Defaults to '!value', which displays the value of each item in the $options array to the user. Use '!key' to display the key instead. In some instances, it may be useful to display both the key and the value; for example, if the key is a user id and the value is the user name, use '!value (uid=!key)'.

4 calls to drush_choice()
drush_core_cache_clear in commands/core/
Command callback for drush cache-clear.
drush_core_watchdog_list in commands/core/
Command callback.
drush_variable_delete in commands/core/
Command callback. Delete a variable.
drush_variable_set in commands/core/
Command callback. Set a variable.


includes/, line 906
The drush API implementation and helpers.


function drush_choice($options, $prompt = 'Enter a number.', $label = '!value') {
  print dt($prompt) . "\n";

  drush_print('  [0] : Cancel');
  $selection_number = 0;
  foreach ($options as $key => $option) {
    if ((substr($key, 0, 3) == '-- ') && (substr($key, -3) == ' --')) {
      drush_print("  " . $option);
    $message = dt($label, array('!number' => $selection_number, '!key' => $key, '!value' => $option));
    drush_print(dt("  [!number] : !message", array('!number' => $selection_number, '!message' => $message)));
    $selection_list[$selection_number] = $key;

  while ($line = trim(fgets(STDIN))) {
    if (array_key_exists($line, $selection_list)) {
      return $selection_list[$line];
  return FALSE;