You are here

function drush_acsf_variables_acsf_vget in Acquia Cloud Site Factory Connector 8

Command callback. Retrieves a named ACSF variable.

File

acsf_variables/acsf_variables.drush.inc, line 63
Provides drush commands for the acsf_variables module.

Code

function drush_acsf_variables_acsf_vget($name) {
  if (!\Drupal::moduleHandler()
    ->moduleExists('acsf_variables')) {
    return drush_set_error(dt('The acsf_variables module must be enabled.'));
  }
  if (empty($name)) {
    return drush_set_error(dt('You must provide the name of the variable to retrieve as the first argument.'));
  }
  $format = drush_get_option('format', 'var_export');
  $exact = drush_get_option('exact');
  if ($exact) {
    if (($value = \Drupal::service('acsf.variable_storage')
      ->get($name)) && !is_null($value)) {
      $variables[$name] = $value;
    }
  }
  else {
    $variables = \Drupal::service('acsf.variable_storage')
      ->getMatch($name);
  }
  if (!empty($variables)) {
    foreach ($variables as $variable_name => $variable) {
      if ($format == 'json') {
        $value = drush_format($variable, NULL, $format);
      }
      else {
        $value = dt('@name: !value', [
          '@name' => $variable_name,
          '!value' => drush_format($variable, NULL, $format),
        ]);
      }
      drush_print($value);
    }
  }
  else {
    return drush_set_error(dt('@name not found.', [
      '@name' => $name,
    ]));
  }
}