10000 [Console] non interactive confirmation question by antonch1989 · Pull Request #30796 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] non interactive confirmation question #30796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
non interactive confirmation question
  • Loading branch information
antonch1989 committed Mar 31, 2019
commit 943ad8353038f5b0ee0400eb53b25aad21e76153
8 changes: 8 additions & 0 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;

/**
Expand Down Expand Up @@ -63,6 +64,13 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
}
}

if ($question instanceof ConfirmationQuestion) {
$value = trim(fgets(STDIN));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should use $input->getStream() and STDIN as fallback, which implies to move up the intialization of $this->inputStream below

if ($value === 'y') {
Copy link
Member
@chalasr chalasr Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any true-ish value should be considered according to

$this->trueAnswerRegex = $trueAnswerRegex;

I think it should read more bytes from the input stream (as much as in doAsk()) and, if it's not false, return the value after it has been passed to Question::getNormalizer()/getValidator().

Also, couldn't this work for any question instead of only confirmation questions?

return true;
}
}

return $default;
}

Expand Down
0