N98\Magento\Command\AbstractMagentoCommand::askForArrayEntry PHP Method

askForArrayEntry() protected method

protected askForArrayEntry ( array $entries, Symfony\Component\Console\Output\OutputInterface $output, string $question ) : mixed
$entries array zero-indexed array of entries (represented by strings) to select from
$output Symfony\Component\Console\Output\OutputInterface
$question string
return mixed
    protected function askForArrayEntry(array $entries, OutputInterface $output, $question)
    {
        $dialog = '';
        foreach ($entries as $key => $entry) {
            $dialog .= '<comment>[' . ($key + 1) . ']</comment> ' . $entry . "\n";
        }
        $dialog .= "<question>{$question}</question> ";
        $selected = $this->getHelper('dialog')->askAndValidate($output, $dialog, function ($typeInput) use($entries) {
            if (!in_array($typeInput, range(1, count($entries)))) {
                throw new InvalidArgumentException('Invalid type');
            }
            return $typeInput;
        });
        return $entries[$selected - 1];
    }