/**
  * Adds a virtual host name to the hosts file of the host system.
  *
  * @param VirtualHost[] $vhosts
  */
 public function addServerToHostsFile(array $vhosts)
 {
     // Get the docker-machine VM ip address.
     $dockerMachineIpAddress = Application::getDocker()->getDockerMachineIpAddress('default');
     $vhostServerNames = [];
     foreach ($vhosts as $vhost) {
         $vhostServerNames[] = $vhost->getServerName();
     }
     $vhostServerNames = join(' ', $vhostServerNames);
     $found = false;
     $hosts = file('/etc/hosts');
     if ($hosts) {
         foreach ($hosts as $line) {
             $line = str_replace(array("\t", '#'), ' ', $line);
             preg_match_all('#^(.*?) (.*)$#', $line, $matches);
             if (!empty($matches[1][0]) && !empty($matches[2][0])) {
                 $ip = trim($matches[1][0]);
                 $host = trim($matches[2][0]);
                 if ($ip == $dockerMachineIpAddress && $host == $vhostServerNames) {
                     $found = true;
                     break;
                 }
             }
         }
         if (!$found) {
             $process = new Process(sprintf('sudo sh -c "echo \'%s %s\' >> /etc/hosts"', $dockerMachineIpAddress, $vhostServerNames . ' '));
             $process->setTty(true);
             $process->run();
             print $process->getOutput();
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get the project.
     $database = new ProjectDatabase(Application::getDatabase());
     $acronym = $input->getArgument('project_acronym');
     $project = null;
     try {
         $project = $database->getProjectByAcronym($input->getArgument('project_acronym'));
         Application::getDocker()->removeEnvironment($project, $input->getArgument('feature_branch'));
     } catch (DatabaseQueryException $e) {
         $output->writeln(sprintf('Unable to find <error>project</error> by acronym <error>%s</error>.', $acronym));
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Read in the arguments.
     $acronym = $input->getArgument('project_acronym');
     $branch = $input->getArgument('feature_branch');
     $installProfile = $input->getArgument('drupal_install_profile');
     $project = null;
     try {
         // Get the project.
         $projectDatabase = new ProjectDatabase(Application::getDatabase());
         $project = $projectDatabase->getProjectByAcronym($input->getArgument('project_acronym'));
         // Create the docker environment.
         Application::getDocker()->createEnvironment($project, $branch, $installProfile);
     } catch (DockerManagerCreateEnvironmentException $e) {
         $output->writeln(sprintf('<error>Failed</error> to create <error>environment</error> [project: %s, branch: %s]', $acronym, $branch));
     } catch (DatabaseQueryException $e) {
         $output->writeln(sprintf('Unable to find <error>project</error> by acronym <error>%s</error>.', $acronym));
     }
 }