StackFormation\Command\AbstractCommand::interactAskForBlueprint PHP Method

interactAskForBlueprint() protected method

protected interactAskForBlueprint ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    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;
    }