function drush_state_set

8.0.x drush_state_set($key = NULL, $value = NULL)
7.x drush_state_set($key = NULL, $data = NULL)

State set command callback.


$key: The config key.

$value: The data to save to state.


commands/core/, line 102
Provides State commands.


function drush_state_set($key = NULL, $value = NULL) {
  // This hidden option is a convenient way to pass a value without passing a key.
  $value = drush_get_option('value', $value);

  if (!isset($value)) {
    return drush_set_error('DRUSH_STATE_ERROR', dt('No state value specified.'));

  // Special flag indicating that the value has been passed via STDIN.
  if ($value === '-') {
    $value = stream_get_contents(STDIN);

  // If the value is a string (usual case, unless we are called from code),
  // then format the input.
  if (is_string($value)) {
    $value = drush_value_format($value, drush_get_option('format', 'auto'));

  \Drupal::state()->set($key, $value);