/** * Check command * * @return $this * @throws CommandExecutionException */ protected function checkCommand() { if ($this->command === null) { throw $this->generateException('Commmand is not set'); } if (!$this->command->isExecuteable()) { throw $this->generateException('Commmand "' . $this->command->getCommand() . '" is not executable or available'); } return $this; }
/** * Execute docker compose run * * @param string $containerName Container name * @param CommandBuilderInterface $command Command * * @return int|null|void */ protected function executeDockerComposeRun($containerName, CommandBuilderInterface $command) { // Search updir for docker-compose.yml $path = $this->getDockerPath(); if (!empty($path)) { // Switch to directory of docker-compose.yml PhpUtility::chdir($path); $this->output->writeln('<info>Executing "' . $command->getCommand() . '" in docker container "' . $containerName . '" ...</info>'); $dockerCommand = new CommandBuilder('docker-compose', 'run --rm %s', array($containerName)); $dockerCommand->append($command, false); $dockerCommand->executeInteractive(); } else { $this->output->writeln('<p-error>No docker-compose.yml found in tree</p-error>'); return 1; } return 0; }
/** * Append another command builder * * @param CommandBuilderInterface $command Command builder * @param boolean $inline Add command as inline string (one big parameter) * * @return $this */ public function append(CommandBuilderInterface $command, $inline = true) { // Check if sub command is executeable if (!$command->isExecuteable()) { throw new \RuntimeException('Sub command "' . $command->getCommand() . '" is not executable or available'); } if ($inline) { // Inline, one big parameter $this->addArgument($command->build()); } else { // Append each as own argument $this->addArgument($command->command); $this->argumentList = array_merge($this->argumentList, $command->argumentList); } return $this; }