protected function execute(InputInterface $input, OutputInterface $output) { $vagrant = new Vagrant(); $hostList = $this->getHostList($input, $output); if ($hostList === null) { if ($input->getOption("start")) { $output->writeln(sprintf("<bg=red>Note:</> <fg=yellow>You supplied the --start option, that only works when you supply an identifier as well</>")); } $vagrant->commandSsh(); } else { $count = count($hostList); # handle all boxes that match the inputStr foreach ($hostList as $host) { /** @var \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")); } } }
/** * Should return (one of) * array of \App\Service\Vagrant\Host * null, if no input is given (empty identifier) * * @param InputInterface $input * @param OutputInterface $output * @return null|array(\App\Service\Vagrant\Host) */ 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 \App\Service\Vagrant\Host $host */ $host = $vagrant->lookupBox($id); $hosts[] = $host; unset($host); } return $hosts; } }
protected function execute(InputInterface $input, OutputInterface $output) { $vagrant = new Vagrant(); $hostList = $this->getHostList($input, $output); if ($hostList === null) { $vagrant->commandSuspend(); } else { $count = count($hostList); # handle all boxes that match the inputStr foreach ($hostList as $host) { /** @var \App\Service\Vagrant\Host $host */ $output->writeln(sprintf("<fg=yellow>Suspending:</> %s <fg=blue>%s</>", $host->getData("name"), $host->getData("dir"))); $vagrant->commandSuspend($host->getData("id")); } # print success-message if ($count) { $output->writeln(sprintf("<fg=green>Done:</> Suspended <fg=blue>%s</> %s", $count, $count > 1 ? 'boxes' : "box")); } } }