Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $bot = new Bot($output, self::$config->get('service.name'));
     if (!$output->isDecorated()) {
         $bot->render();
         return;
     }
     // Stay positive: return code 0 when the user quits.
     if (function_exists('pcntl_signal')) {
         declare (ticks=1);
         pcntl_signal(SIGINT, function () {
             echo "\n";
             exit;
         });
     }
     while (true) {
         $bot->render();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Platformsh\Cli\Helper\QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $options = $this->form->resolveOptions($input, $output, $questionHelper);
     $estimate = $this->getEstimate($options['plan'], $options['storage'], $options['environments']);
     if (!$estimate) {
         $costConfirm = "Failed to estimate project cost";
     } else {
         $costConfirm = "The estimated monthly cost of this project is: <comment>{$estimate['total']}</comment>";
     }
     $costConfirm .= "\n\nAre you sure you want to continue?";
     if (!$questionHelper->confirm($costConfirm)) {
         return 1;
     }
     $subscription = $this->api()->getClient()->createSubscription($options['region'], $options['plan'], $options['title'], $options['storage'] * 1024, $options['environments']);
     $this->api()->clearProjectsCache();
     $this->stdErr->writeln(sprintf('Your %s project has been requested (subscription ID: <comment>%s</comment>)', self::$config->get('service.name'), $subscription->id));
     $this->stdErr->writeln(sprintf("\nThe %s Bot is activating your project\n", self::$config->get('service.name')));
     $bot = new Bot($this->stdErr);
     $start = time();
     while ($subscription->isPending() && time() - $start < 300) {
         $bot->render();
         if (!isset($lastCheck) || time() - $lastCheck >= 2) {
             try {
                 $subscription->refresh(['timeout' => 5, 'exceptions' => false]);
                 $lastCheck = time();
             } catch (ConnectException $e) {
                 if (strpos($e->getMessage(), 'timed out') !== false) {
                     $this->stdErr->writeln('<warning>' . $e->getMessage() . '</warning>');
                 } else {
                     throw $e;
                 }
             }
         }
     }
     $this->stdErr->writeln("");
     if (!$subscription->isActive()) {
         $this->stdErr->writeln("<error>The project failed to activate</error>");
         return 1;
     }
     $this->stdErr->writeln("The project is now ready!");
     $this->stdErr->writeln("  Region: <info>{$subscription->project_region}</info>");
     $this->stdErr->writeln("  Project ID: <info>{$subscription->project_id}</info>");
     $this->stdErr->writeln("  Project title: <info>{$subscription->project_title}</info>");
     $this->stdErr->writeln("  URL: <info>{$subscription->project_ui}</info>");
     return 0;
 }