/**
  * Ask the user to select one of the given plugins or enter one of $allowedAnswers
  * Will loop until a valid choice was made
  *
  * @param  Plugin[] $plugins
  * @param  string[] $allowedAnswers
  * @return string
  */
 public function selectPlugin($plugins, $allowedAnswers = array('all'))
 {
     while (true) {
         system('clear');
         $this->outputRenderer->show($plugins);
         $question = new Question($this->formatQuestion(count($plugins), $allowedAnswers));
         $response = $this->ioService->ask($question);
         if ($range = $this->getPluginRange($response)) {
             return array_filter(array_map(function ($number) use($plugins) {
                 return isset($plugins[$number - 1]) ? $plugins[$number - 1] : null;
             }, $range), function ($plugin) {
                 return $plugin;
             });
         } elseif (isset($plugins[$response - 1])) {
             return $plugins[$response - 1];
         } elseif (in_array($response, $allowedAnswers)) {
             return $response;
         } else {
             $question = new Question('<error>Invalid answer, hit enter to continue</error>');
             $this->ioService->ask($question);
         }
     }
 }
 /**
  * Show the plugin list to the user, until "all" or "exit" was entered
  *
  * @param callable $callback
  * @param array    $params
  */
 public function operationLoop($callback, $params)
 {
     $plugins = $this->pluginProvider->getPlugins();
     while (true) {
         $response = $this->pluginSelector->selectPlugin($plugins, array('all', 'exit'));
         if ($response == 'exit') {
             return;
         }
         $this->ioService->cls();
         $responsePlugins = $this->getPluginsFromResponse($response, $plugins);
         foreach ($responsePlugins as $plugin) {
             $this->executeMethodCallback($plugin, $callback, $params);
         }
         $this->ioService->ask("\n<error>Done, hit enter to continue.</error>");
         $this->ioService->cls();
     }
 }
 /**
  * @param InputInterface $input
  * @param IoService $ioService
  */
 private function askDatabasePassword(InputInterface $input, IoService $ioService)
 {
     $databasePassword = $input->getOption('db-password');
     if (!$databasePassword) {
         $databasePassword = $ioService->ask("Please provide the database password: ");
         $input->setOption('db-password', trim($databasePassword));
     }
 }
 /**
  * @param InputInterface $input
  * @param IoService      $ioService
  * @param string         $suggestion
  */
 protected function askBasePath(InputInterface $input, IoService $ioService, $suggestion)
 {
     $basePath = $input->getOption('basePath');
     if (!$basePath) {
         $basePath = $ioService->ask("Please provide the basepath you want to use <{$suggestion}>: ");
         $input->setOption('basePath', trim($basePath) ? $basePath : $suggestion);
     }
 }
 /**
  * @param InputInterface $input
  * @param IoService      $ioService
  *
  * @return string
  */
 private function askBranch(InputInterface $input, IoService $ioService)
 {
     $branch = $input->getOption('branch');
     if (!$branch) {
         $branchSuggestion = self::MAIN_BRANCH;
         $branch = $ioService->ask("Please provide the branch you want to install <{$branchSuggestion}>: ");
         $branch = trim($branch) ? $branch : self::MAIN_BRANCH;
         $input->setOption('branch', $branch);
         return $branch;
     }
     return $branch;
 }
 /**
  * @param InputInterface $input
  * @param IoService      $ioService
  *
  * @return string
  */
 private function askBranch(InputInterface $input, IoService $ioService)
 {
     $branch = $input->getOption('branch');
     if (!$branch) {
         $branch = $ioService->ask('Please provide the branch you want to install <master>: ');
         $branch = trim($branch) ? $branch : 'master';
         $input->setOption('branch', $branch);
         return $branch;
     }
     return $branch;
 }