function drush_variable_delete

8.0.x variable.drush.inc drush_variable_delete()
6.x variable.drush.inc drush_variable_delete()
7.x variable.drush.inc drush_variable_delete()
3.x variable.drush.inc drush_variable_delete()
4.x variable.drush.inc drush_variable_delete()
5.x variable.drush.inc drush_variable_delete()
master variable.drush.inc drush_variable_delete()

Command callback. Delete a variable.

File

commands/core/variable.drush.inc, line 258

Code

function drush_variable_delete() {
  $args = func_get_args();
  $args[0] = drush_variable_name_adjust($args[0]);
  // Look for similar variable names.
  $result = drush_variable_like($args[0]);

  $options = array();
  while ($name = drush_db_result($result)) {
    $options[] = $name;
  }
  if (drush_get_option('exact', FALSE)) {
    $options = in_array($args[0], $options) ? array($args[0]) : array();
  }

  if (count($options) == 0) {
    drush_print(dt('!name not found.', array('!name' => $args[0])));
    return '';
  }

  if ((count($options) == 1) && drush_get_context('DRUSH_AFFIRMATIVE')) {
    drush_op('variable_del', $args[0]);
    drush_log(dt('!name was deleted.', array('!name' => $args[0])), 'success');
    return '';
  }
  else {
    $choice = drush_choice($options, 'Enter a number to choose which variable to delete.');
    if ($choice !== FALSE) {
      $choice = $options[$choice];
      drush_op('variable_del', $choice);
      drush_log(dt('!choice was deleted.', array('!choice' => $choice)), 'success');
    }
  }
}