/** * @param InputInterface $input * @param OutputInterface $output * * @throws \InvalidArgumentException * @return Docker */ protected function getDocker(InputInterface $input, OutputInterface $output) { if ($this->getDefinition()->hasArgument(self::ARGUMENT_TARGET)) { $target = $input->getArgument(self::ARGUMENT_TARGET) ?: $this->project->getCurrentTarget(); } else { $target = $this->project->getCurrentTarget(); } $targets = $this->project->getTargets(); if (false === $targets->offsetExists($target)) { throw new \InvalidArgumentException('You must choose a valid target to start the containers. Valid options are:' . "\n - " . implode("\n - ", array_keys($targets->getArrayCopy()))); } $ssh = $targets->offsetGet($target); /** @var ExecutorFactory $factory */ $factory = $this->getApplication()->getService('executor.factory'); $executor = $factory->createExecutor($output, true, $ssh); /** @var Docker $docker */ $docker = $this->getApplication()->getService('docker'); $docker->setExecutor($executor); return $docker; }
private function chooseTarget(Project $project, OutputInterface $output) { $output->writeln('Project has multiple target definitions. Do you want to choose one?'); $targets = ["" => "Skip this for now, decide later"] + array_map(function ($value) { if (null === $value) { return 'run from <comment>localhost</comment>'; } return sprintf('run via ssh from <comment>%s</comment>', $value); }, $project->getTargets()->getArrayCopy()); $value = $this->getDialogHelper()->select($output, "Available options: ", $targets, ""); if ($value) { $project->setCurrentTarget($value); } }