* @param string $question
* @param array $choices
* @param mixed $default
- * @param bool $allowEmpty
+ * @param bool $skipValidation
*
* @return string
*/
- public function choiceNoList($question, array $choices, $default = null, $allowEmpty = false)
- {
- if ($allowEmpty) {
- $default = ' ';
- }
-
+ public function choiceNoList(
+ $question,
+ array $choices,
+ $default = null,
+ $skipValidation = false
+ ) {
if (is_null($default)) {
$default = current($choices);
}
$default = $values[$default];
}
- return trim($this->askChoiceQuestion(new ChoiceQuestion($question, $choices, $default)));
+ $choiceQuestion = new ChoiceQuestion($question, $choices, $default);
+ if ($skipValidation) {
+ $choiceQuestion->setValidator(
+ function ($answer) {
+ return $answer;
+ }
+ );
+ }
+
+ return trim($this->askChoiceQuestion($choiceQuestion));
}
/**
{
$questionHelper = new DrupalChoiceQuestionHelper();
$answer = $questionHelper->ask($this->input, $this, $question);
-
return $answer;
}
*/
public function askHiddenEmpty($question)
{
- $question = new Question($question, ' ');
+ $question = new Question($question, '');
$question->setHidden(true);
+ $question->setValidator(
+ function ($answer) {
+ return $answer;
+ }
+ );
return trim($this->askQuestion($question));
}
/**
- * @param string $question
+ * @param string $question
+ * @param string $default
* @param null|callable $validator
*
* @return string
*/
- public function askEmpty($question, $validator = null)
+ public function askEmpty($question, $default = '', $validator = null)
{
- $question = new Question($question, ' ');
+ $question = new Question($question, $default);
+ if (!$validator) {
+ $validator = function ($answer) {
+ return $answer;
+ };
+ }
$question->setValidator($validator);
return trim($this->askQuestion($question));
}
}
+ /**
+ * {@inheritdoc}
+ */
+ public function warning($message)
+ {
+ $this->block($message, 'WARNING', 'fg=white;bg=yellow', ' ', true);
+ }
+
/**
* @param array|string $message
*/
parent::newLine();
}
}
+
+ /**
+ * @return InputInterface
+ */
+ public function getInput()
+ {
+ return $this->input;
+ }
}