public static assocArrayToString ( array $array, $itemSeparator = '; ', $keyValueSeparator = '=' ) | ||
$array | array |
protected function interactAskForBlueprint(InputInterface $input, OutputInterface $output) { $blueprint = $input->getArgument('blueprint'); if (empty($blueprint) || strpos($blueprint, '*') !== false || strpos($blueprint, '?') !== false) { $choices = $this->blueprintFactory->getBlueprintLabels($blueprint ? $blueprint : null); if (count($choices) == 0) { throw new \Exception('No matching blueprints found'); } elseif (count($choices) == 1) { $blueprint = end($choices); } else { $helper = $this->getHelper('question'); $question = new ChoiceQuestion('Please select a blueprint', $choices); $question->setErrorMessage('Blueprint %s is invalid.'); $blueprint = $helper->ask($input, $output, $question); } $output->writeln('Selected blueprint: ' . $blueprint); list($blueprint) = explode(' ', $blueprint); } elseif (!empty($blueprint) && !$this->blueprintFactory->blueprintExists($blueprint)) { if ($result = $this->blueprintFactory->findByStackname($blueprint)) { $output->writeln('Blueprint reverse match found: <fg=green>' . $result['blueprint'] . '</>'); $output->writeln('With ENV vars: <fg=green>' . Helper\Div::assocArrayToString($result['envvars']) . '</>'); $helper = $this->getHelper('question'); $question = new ConfirmationQuestion("Use this blueprint and set env vars? [y/N] ", false); if (!$helper->ask($input, $output, $question)) { throw new \Exception('Operation aborted'); } $blueprint = $result['blueprint']; foreach ($result['envvars'] as $var => $value) { $output->writeln("Setting env var: {$var}={$value}"); putenv("{$var}={$value}"); } } } $input->setArgument('blueprint', $blueprint); return $blueprint; }
protected function execute(InputInterface $input, OutputInterface $output) { $nameFilter = $input->getOption('nameFilter'); $stacks = $this->getStackFactory()->getStacksFromApi(false, $nameFilter); $error = false; $data = []; foreach ($stacks as $stackName => $stack) { /* @var $stack Stack */ $this->dependencyTracker->reset(); $tmp = []; $tmp['stackName'] = $stackName; $tmp['status'] = Helper\Decorator::decorateStatus($stack->getStatus()); $tmp['blueprintName'] = ''; $tmp['parameters'] = ''; $tmp['template'] = ''; $diff = new Diff($output); try { $blueprint = $this->blueprintFactory->getBlueprintByStack($stack); $env = $stack->getUsedEnvVars(); $diff->setStack($stack); $diff->setBlueprint($blueprint); $tmp['blueprintName'] = '<fg=green>' . $blueprint->getName() . '</>'; if (count($env)) { $tmp['blueprintName'] .= "\n" . wordwrap(Div::assocArrayToString($stack->getUsedEnvVars()), 80, "\n"); } $tmp = array_merge($tmp, $diff->compare()); if (isset($tmp['error']) && $tmp['error'] === true) { $error = true; } } catch (BlueprintReferenceNotFoundException $e) { $tmp['blueprintName'] = '-'; $tmp['parameters'] = '<fg=red>not found</>'; $tmp['template'] = '<fg=red>not found</>'; $error = true; } catch (BlueprintNotFoundException $e) { $tmp['blueprintName'] = '<fg=red>Not found: ' . $e->getBlueprintName() . '</>'; $tmp['parameters'] = '<fg=red>not found</>'; $tmp['template'] = '<fg=red>not found</>'; $error = true; } catch (\Exception $e) { $tmp['blueprintName'] = '<fg=red>Exception: ' . $e->getMessage() . '</>'; $tmp['parameters'] = '<fg=red>exception</>'; $tmp['template'] = '<fg=red>exception</>'; $error = true; } if (isset($tmp['error'])) { // so the column doesn't show on in the output table unset($tmp['error']); } $data[] = $tmp; } $output->writeln(''); $table = new Table($output); $table->setHeaders(['Stack', 'Status', 'Blueprint', 'Parameters', 'Template']); $table->setRows($data); $table->render(); $output->writeln(''); $output->writeln("-> Run this to show a diff for a specific stack:"); $output->writeln("{$GLOBALS['argv'][0]} stack:diff <stackName>"); $output->writeln(''); $output->writeln("-> Run this to update a live stack:"); $output->writeln("{$GLOBALS['argv'][0]} blueprint:deploy -o <blueprintName>"); $output->writeln(''); return $error === true ? 1 : 0; }