Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $vagrant = new Vagrant();
     $hostList = $this->getHostList($input, $output);
     if ($hostList === null) {
         if ($input->getOption("start")) {
             $vagrant->commandUp();
         }
         $vagrant->commandSsh();
     } else {
         $count = count($hostList);
         # handle all boxes that match the inputStr
         foreach ($hostList as $host) {
             /** @var \Klang\App\Service\Vagrant\Host $host */
             if ($host->getData("state") != 'running') {
                 if ($input->getOption("start")) {
                     $output->writeln(sprintf("<fg=yellow>Starting:</> %s <fg=blue>%s</>", $host->getData("name"), $host->getData("dir")));
                     $vagrant->commandUp($host->getData("id"));
                 } else {
                     $count--;
                     $output->writeln(sprintf("<bg=red>Box %s (%s) is not running!</>", $host->getData("name"), $host->getData("dir")));
                     $output->writeln(sprintf("<fg=yellow>Use option --start to start it for you</>"));
                     continue;
                 }
             }
             $output->writeln(sprintf("<fg=yellow>Starting ssh-session to:</> %s <fg=blue>%s</>", $host->getData("name"), $host->getData("dir")));
             $vagrant->commandSsh($host->getData("id"));
         }
         # print success-message
         if ($count) {
             $output->writeln(sprintf("<fg=green>Done:</> ssh-session ended for <fg=blue>%s</> %s", $count, $count > 1 ? 'boxes' : "box"));
         }
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Exception
  * @throws \Symfony\Component\Console\Exception\ExceptionInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $vagrant = new Vagrant();
     foreach ($this->actions as $action) {
         if (!isset($action["boxes"])) {
             continue;
         }
         /** @var VagrantCommand $command */
         $command = $this->getApplication()->find($action["action"]);
         $statusInput = new ArrayInput(array("identifier" => $action["boxes"]), $command->getDefinition());
         $command->run($statusInput, $output);
         $vagrant->flushCache();
     }
 }
 /**
  * Should return (one of)
  *      array of \Klang\App\Service\Vagrant\Host
  *      null, if no input is given (empty identifier)
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return null|array(\Klang\App\Service\Vagrant\Host)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getHostList(InputInterface $input, OutputInterface $output)
 {
     $vagrant = new Vagrant();
     $inputStr = $input->getArgument("identifier");
     if ($inputStr === null) {
         return null;
     } else {
         $hosts = [];
         # handle all boxes that match the inputStr
         foreach ($vagrant->resolveStr($inputStr) as $id) {
             /** @var \Klang\App\Service\Vagrant\Host $host */
             $host = $vagrant->lookupBox($id);
             $hosts[] = $host;
             unset($host);
         }
         return $hosts;
     }
 }
Esempio n. 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $vagrant = new Vagrant();
     $hostList = $this->getHostList($input, $output);
     if ($hostList === null) {
         $vagrant->commandHalt();
     } else {
         $count = count($hostList);
         # handle all boxes that match the inputStr
         foreach ($hostList as $host) {
             /** @var \Klang\App\Service\Vagrant\Host $host */
             $output->writeln(sprintf("<fg=yellow>Halting:</> %s <fg=blue>%s</>", $host->getData("name"), $host->getData("dir")));
             $vagrant->commandHalt($host->getData("id"));
         }
         # print success-message
         if ($count) {
             $output->writeln(sprintf("<fg=green>Done:</> Halted <fg=blue>%s</> %s", $count, $count > 1 ? 'boxes' : "box"));
         }
     }
 }