Skip to content

Commit

Permalink
[spiral/console] Added method to easily ask multiple choice questions (
Browse files Browse the repository at this point in the history
  • Loading branch information
simioluwatomi authored and butschster committed Apr 27, 2023
1 parent ae80144 commit 6674409
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Console/src/Traits/HelpersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;

Expand Down Expand Up @@ -85,6 +86,23 @@ protected function ask(string $question, string $default = null): mixed
return $this->output->ask($question, $default);
}

/**
* Asks a multiple choice question.
*/
protected function choiceQuestion(
string $question,
array $choices,
mixed $default = null,
int $attempts = null,
bool $multiselect = false
): mixed {
$question = new ChoiceQuestion($question, $choices, $default);

$question->setMaxAttempts($attempts)->setMultiselect($multiselect);

return $this->output->askQuestion($question);
}

/**
* Prompt the user for input but hide the answer from the console.
*/
Expand Down

0 comments on commit 6674409

Please sign in to comment.