protected function execute(InputInterface $input, OutputInterface $output)
{
$this->validateInput($input);
$variableName = $input->getArgument('name');
$variableValue = $input->getArgument('value');
$json = $input->getOption('json');
if ($json && !$this->validateJson($variableValue)) {
throw new \Exception("Invalid JSON: <error>{$variableValue}</error>");
}
// Check whether the variable already exists. If there is no change,
// quit early.
$existing = $this->getSelectedEnvironment()->getVariable($variableName);
if ($existing && $existing->getProperty('value') === $variableValue && $existing->getProperty('is_json') == $json) {
$this->stdErr->writeln("Variable <info>{$variableName}</info> already set as: {$variableValue}");
return 0;
}
// Set the variable to a new value.
$result = $this->getSelectedEnvironment()->setVariable($variableName, $variableValue, $json);
$this->stdErr->writeln("Variable <info>{$variableName}</info> set to: {$variableValue}");
$success = true;
if (!$result->countActivities()) {
$this->rebuildWarning();
} elseif (!$input->getOption('no-wait')) {
$success = ActivityUtil::waitMultiple($result->getActivities(), $this->stdErr, $this->getSelectedProject());
}
return $success ? 0 : 1;
}