]> BookStack Code Mirror - system-cli/blob - src/Services/InteractiveConsole.php
Bumped version
[system-cli] / src / Services / InteractiveConsole.php
1 <?php declare(strict_types=1);
2
3 namespace Cli\Services;
4
5 use Symfony\Component\Console\Question\ChoiceQuestion;
6 use Symfony\Component\Console\Helper\QuestionHelper;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Output\OutputInterface;
9 use Symfony\Component\Console\Question\ConfirmationQuestion;
10
11 class InteractiveConsole
12 {
13     public function __construct(
14         protected QuestionHelper $helper,
15         protected InputInterface $input,
16         protected OutputInterface $output,
17     ) {
18     }
19
20     public function confirm(string $text): bool
21     {
22         $question = new ConfirmationQuestion($text . " (y/n)\n", false);
23         return $this->helper->ask($this->input, $this->output, $question);
24     }
25
26     public function choice(string $question, array $answers)
27     {
28         $question = new ChoiceQuestion($question, $answers, $answers[0]);
29         return $this->helper->ask($this->input, $this->output, $question);
30     }
31 }