Asks user for confirmation and returns value corresponding to the chosen value.

@param  string     $question Question to ask
@param  string     $default  Default answer
@param  array|null $options  Answer options
@return bool
353539
public function ask(string $question, $default = 'n', ?array $options = null)
	{
		$options = $options === null ? ['y' => true, 'n' => false] : $this->normalizeKeys($options);

		$input = parent::ask(trim($question) . ' [' . $this->getOptions($options, $default) . '] ');

		$input = mb_strtolower(empty($input) ? $default : $input);

		if(!isset($options[$input]))
		{
			return $this->ask($question, $default, $options);
		}

		return $options[$input];
	}
844483
public function askChoice($question, array $options, $allowEmptyChoice = true, $default = null)
    {
        $this->write($this->encloseAsQuestion($question, $default));

        $optionValues = array_values($options);

        foreach ($optionValues as $key => $optionQuestion) {
            $this->write('[' . ($key+1) . ']' . $optionQuestion);               //+1 because normal people prefers 1 over 0 as first option
        }

        $validator = function ($choosenValue) use ($optionValues, $allowEmptyChoice, $default) {
            $isValidValue = isset($optionValues[$choosenValue-1]);
            $isAllowedEmpty = is_null($choosenValue) && $allowEmptyChoice;

            if ($isValidValue) {
                return $choosenValue;
            } elseif ($isAllowedEmpty) {
                return $default;
            }

            throw new InputException('Invalid value (' . $choosenValue . ') provided.');
        };

        $message = 'Choose' . ($allowEmptyChoice ? ' (Hit enter for no choice)' : '');

        $answer = $this->askAndValidate($message, $validator, false, $default);

        if (!is_null($answer)) {
            $optionRealValues = array_keys($options);
            $answer = $optionRealValues[$answer-1];
        }

        return $answer;
    }
1303389
protected function askNumeric( $question, $default = null ) {
		$ask = 'Your answer needs to be a numeric value';

		if ( ! is_null( $default ) ) {
			$question .= ' [Default: '. $default .'] ';
			$ask .= ' or blank for default';
		}

		$answer = $this->ask( $question );

		while ( ! is_numeric( $answer ) and ! ( $answer == '' and ! is_null( $default ) ) ) {
			$answer = $this->ask( $ask .'. ');
		}
		if ( $answer == '' ) {
			$answer = $default;
		}
		return $answer;
	}
1010709
protected function getConfirmationQuestion(string $questionName, bool $defaultValue = false): ConfirmationQuestion
    {
        return new ConfirmationQuestion(
            sprintf(
                '<info>%s</info> [<comment>%s</comment>]? ',
                $questionName,
                $defaultValue ? 'yes' : 'no'
            ),
            $defaultValue
        );
    }
571053
public function ask($string, $default = null) {
        if ($default === true) {
            $suffix = 'Y/n';
        } else if ($default === false) {
            $suffix = 'y/N';
        } else {
            $suffix = 'y/n';
        }

        $this->output->write(
            "<question>$string</question> [<yellow>$suffix</yellow>]: "
        );
        $input = $this->input->readLine();

        if (array_contains(['yes', 'y'], $input)) {
            return true;
        }

        if (array_contains(['no', 'n'], $input)) {
            return false;
        }

        if (empty($input)) {
            if ($default === true) {
                return true;
            }

            if ($default === false) {
                return false;
            }
        }

        return $this->ask($string, $default);
    }
610
private function choice($question, array $choices, $default, InputInterface $input, OutputInterface $output)
    {
        $helper = new QuestionHelper();

        $result = $helper->ask($input, $output, new ChoiceQuestion(
            $question,
            $choices,
            $choices[$default]
        ));

        $output->writeln('');

        return $result;
    }
1324821
def confirm(question: str, default: bool = True) -> bool:
    

    result = input('{question} [{yes}/{no}]:'.format(
        question=question,
        yes='(Y)' if default else 'Y',
        no='N' if default else '(N)'
    ))

    if not result:
        return default

    if result[0].lower() in ['y', 't', '1']:
        return True
    return False
136107
public function optionOrAsk($option, $question, $default = null)
    {
        $value = $this->input->getOption($option);
        if ($value === null || Str::likeEmpty($value)) {
            $value = $this->ask($question, $default);
        }

        return $value;
    }
674989
def yes?(message, *args, &block)
      defaults = { default: true }
      options  = Utils.extract_options!(args)
      options.merge!(defaults.reject { |k, _| options.key?(k) })

      question = ConfirmQuestion.new(self, options)
      question.call(message, &block)
    end
463268
public function askWithCompletion($question, array $choices, $default = null)
    {
        $question = new Question($question, $default);

        $question->setAutocompleterValues($choices);

        return $this->output->askQuestion($question);
    }
728582
protected function confirm($sQuestion, $bDefault)
    {
        $sQuestion = is_array($sQuestion) ? implode("\n", $sQuestion) : $sQuestion;
        $oHelper   = $this->getHelper('question');
        $sDefault  = (bool) $bDefault ? 'Y' : 'N';
        $oQuestion = new ConfirmationQuestion($sQuestion . ' [' . $sDefault . ']: ', $bDefault);

        return $oHelper->ask($this->oInput, $this->oOutput, $oQuestion);
    }
160528
protected function confirm($message, $default = null)
    {
        /** @var QuestionHelper $q */
        $q = $this->getHelperSet()->get('question');

        $question = new ConfirmationQuestion(
            $message . ($default ? (sprintf(' [%s]', $default ? 'yes' : 'no')) : '') . ' : ', true === $default
        );

        $question->setMaxAttempts(3);

        $response = $q->ask($this->getInput(), $this->getOutput(), $question);

        return $response;
    }
511682
public static function ask(string $question, string $default = '', \Closure $validator = null): ?string
    {
        return self::question($question, $default, $validator);
    }
44132
def ask(self, question, default=False):
        
        choices = '[%s/%s]' % ('Y' if default else 'y', 'n' if default else 'N')
        while True:
            response = raw_input('%s %s' % (question, choices)).strip()
            if not response:
                return default
            elif response in 'yYoO':
                return True
            elif response in 'nN':
                return False
1186211
public function choose($question, $choice = 'yn', $default = 'n')
    {
        if (!is_string($choice)) {
            $choice = implode('', $choice);
        }

        $lowercase = str_ireplace($default, strtoupper($default), strtolower($choice));
        $choices = trim(implode('/', preg_split('//', $lowercase)), '/');
        $line = $this->prompt(sprintf('%s [%s]', $question, $choices), $default, '');

        if (stripos($choice, $line) !== false) {
            return strtolower($line);
        }

        return strtolower($default);
    }
890116
private function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = true)
    {
        if ($this->getHelperSet()->has('question')) {
            $question = new ConfirmationQuestion($question, $default);

            return $this->getHelper('question')->ask($input, $output, $question);
        }

        return $this->getHelper('dialog')->askConfirmation($output, $question, $default);
    }
64469
protected function ask($question, $default = null)
    {
        $defaultComment = '';
        
        if ($default !== null) {
            $defaultComment = ' [<comment>' . $default . '</comment>]';
        }
        
        $question = preg_replace('/(?:(\?)\s*$|(\?)?\s+$)|(?<!\s|\?)$/', $defaultComment . '$1 ', $question);
        
        return $this->io->ask($question, $default);
    }