/**
  * {@inheritdoc}
  */
 protected function writePrompt(OutputInterface $output, Question $question)
 {
     $text = $question->getQuestion();
     $default = $question->getDefault();
     switch (true) {
         case null === $default:
             $text = sprintf(' <info>%s</info>:', $text);
             break;
         case $question instanceof ConfirmationQuestion:
             $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
             break;
         case $question instanceof ChoiceQuestion && $question->isMultiSelect():
             $choices = $question->getChoices();
             $default = explode(',', $default);
             foreach ($default as $key => $value) {
                 $default[$key] = $choices[trim($value)];
             }
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, implode(', ', $default));
             break;
         case $question instanceof ChoiceQuestion:
             $choices = $question->getChoices();
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
             break;
         default:
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $default);
     }
     $output->writeln($text);
     if ($question instanceof ChoiceQuestion) {
         $width = max(array_map('strlen', array_keys($question->getChoices())));
         foreach ($question->getChoices() as $key => $value) {
             $output->writeln(sprintf("  [<comment>%-{$width}s</comment>] %s", $key, $value));
         }
     }
     $output->write(' > ');
 }
 /**
  * {@inheritdoc}
  */
 protected function writePrompt(OutputInterface $output, Question $question)
 {
     $text = $question->getQuestion();
     $default = $question->getDefault();
     $choices = $question->getChoices();
     $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
     $output->writeln($text);
     $output->write(' > ');
 }
Ejemplo n.º 3
0
 /**
  * Asks a question to the user.
  *
  * @param InputInterface  $input    An InputInterface instance
  * @param OutputInterface $output   An OutputInterface instance
  * @param Question        $question The question to ask
  *
  * @return string The user answer
  *
  * @throws \RuntimeException If there is no data to read in the input stream
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if (!$input->isInteractive()) {
         return $question->getDefault();
     }
     if (!$question->getValidator()) {
         return $this->doAsk($output, $question);
     }
     $interviewer = function () use($output, $question) {
         return $this->doAsk($output, $question);
     };
     return $this->validateAttempts($interviewer, $output, $question);
 }
Ejemplo n.º 4
0
 /**
  * Asks a question to the user.
  *
  * @param InputInterface  $input    An InputInterface instance
  * @param OutputInterface $output   An OutputInterface instance
  * @param Question        $question The question to ask
  *
  * @return string The user answer
  *
  * @throws RuntimeException If there is no data to read in the input stream
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if ($output instanceof ConsoleOutputInterface) {
         $output = $output->getErrorOutput();
     }
     if (!$input->isInteractive()) {
         return $question->getDefault();
     }
     if (!$question->getValidator()) {
         return $this->doAsk($output, $question);
     }
     $that = $this;
     $interviewer = function () use($output, $question, $that) {
         return $that->doAsk($output, $question);
     };
     return $this->validateAttempts($interviewer, $output, $question);
 }