|
17 | 17 | use Symfony\Component\Console\Question\ConfirmationQuestion;
|
18 | 18 | use Symfony\Component\Console\Question\Question;
|
19 | 19 | use Symfony\Component\Console\Style\SymfonyStyle;
|
| 20 | +use Symfony\Component\Console\Formatter\OutputFormatter; |
20 | 21 |
|
21 | 22 | /**
|
22 | 23 | * Symfony Style Guide compliant question helper.
|
@@ -52,42 +53,35 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
|
52 | 53 | */
|
53 | 54 | protected function writePrompt(OutputInterface $output, Question $question)
|
54 | 55 | {
|
55 |
| - $text = $question->getQuestion(); |
| 56 | + $text = OutputFormatter::escape($question->getQuestion()); |
56 | 57 | $default = $question->getDefault();
|
57 | 58 |
|
58 |
| - switch (true) { |
59 |
| - case null === $default: |
60 |
| - $text = sprintf(' <info>%s</info>:', $text); |
61 |
| - |
62 |
| - break; |
63 |
| - |
64 |
| - case $question instanceof ConfirmationQuestion: |
65 |
| - $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); |
66 |
| - |
67 |
| - break; |
| 59 | + if ($question instanceof ConfirmationQuestion) { |
| 60 | + $text = sprintf(' <info>%s (yes/no)</info>', $text); |
| 61 | + } else { |
| 62 | + $text = sprintf(' <info>%s</info>', $text); |
| 63 | + } |
68 | 64 |
|
69 |
| - case $question instanceof ChoiceQuestion && $question->isMultiselect(): |
| 65 | + if ($question instanceof ConfirmationQuestion) { |
| 66 | + $default = $default ? 'yes' : 'no'; |
| 67 | + } elseif (null !== $default) { |
| 68 | + if ($question instanceof ChoiceQuestion && $question->isMultiselect()) { |
70 | 69 | $choices = $question->getChoices();
|
71 | 70 | $default = explode(',', $default);
|
72 | 71 |
|
73 | 72 | foreach ($default as $key => $value) {
|
74 | 73 | $default[$key] = $choices[trim($value)];
|
75 | 74 | }
|
76 | 75 |
|
77 |
| - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, implode(', ', $default)); |
78 |
| - |
79 |
| - break; |
80 |
| - |
81 |
| - case $question instanceof ChoiceQuestion: |
| 76 | + $default = implode(', ', $default); |
| 77 | + } elseif ($question instanceof ChoiceQuestion && null !== $default) { |
82 | 78 | $choices = $question->getChoices();
|
83 |
| - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]); |
84 |
| - |
85 |
| - break; |
86 |
| - |
87 |
| - default: |
88 |
| - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $default); |
| 79 | + $default = $choices[$default]; |
| 80 | + } |
89 | 81 | }
|
90 | 82 |
|
| 83 | + $text .= ; |
| 84 | + |
91 | 85 | $output->writeln($text);
|
92 | 86 |
|
93 | 87 | if ($question instanceof ChoiceQuestion) {
|
|
0 commit comments