Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $inputOptions = $input->getOptions();
     $optionCollection = $this->configModel->getAvailableOptions();
     $commandOptions = [];
     $optionsWithDefaultValues = [];
     foreach ($optionCollection as $option) {
         $commandOptions[$option->getName()] = false;
         $currentValue = $this->deploymentConfig->get($option->getConfigPath());
         if ($currentValue !== null && $inputOptions[$option->getName()] !== null) {
             $dialog = $this->getHelperSet()->get('dialog');
             if (!$dialog->askConfirmation($output, '<question>Overwrite the existing configuration for ' . $option->getName() . '?[Y/n]</question>')) {
                 $inputOptions[$option->getName()] = null;
             }
         }
         if ($option->getDefault() === $inputOptions[$option->getName()] && $inputOptions[$option->getName()] !== null) {
             $optionsWithDefaultValues[] = $option->getName();
         }
     }
     $inputOptions = array_filter($inputOptions, function ($value) {
         return $value !== null;
     });
     $optionsToChange = array_intersect(array_keys($inputOptions), array_keys($commandOptions));
     $this->configModel->process($inputOptions);
     if (count($optionsWithDefaultValues) > 0) {
         $defaultValuesMessage = implode(', ', $optionsWithDefaultValues);
         $output->writeln('<info>We saved default values for these options: ' . $defaultValuesMessage . '.</info>');
     } else {
         if (count($optionsToChange) > 0) {
             $output->writeln('<info>You saved the new configuration.</info>');
         } else {
             $output->writeln('<info>You made no changes to the configuration.</info>');
         }
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $inputOptions = $input->getOptions();
     $configOptionsToValidate = [];
     foreach ($this->configModel->getAvailableOptions() as $option) {
         if (array_key_exists($option->getName(), $inputOptions)) {
             $configOptionsToValidate[$option->getName()] = $inputOptions[$option->getName()];
         }
     }
     $errors = $this->configModel->validate($configOptionsToValidate);
     $errors = array_merge($errors, $this->adminUser->validate($input));
     if (!empty($errors)) {
         foreach ($errors as $error) {
             $output->writeln("<error>{$error}</error>");
         }
         throw new \InvalidArgumentException('Parameters validation is failed');
     }
 }