10000 [Console] Added a note about the behavior of the command question helper by astepin · Pull Request #16978 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Console] Added a note about the behavior of the command question helper #16978

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
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
28 changes: 28 additions & 0 deletions components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ the second argument is not provided, ``true`` is assumed.

The regex defaults to ``/^y/i``.

.. note::

When your output implements ``ConsoleOutputInterface`` the ``stderr`` output is used using :method:`ConsoleOutputInterf 7F3C ace::getErrorOutput`.
This output might have a different formatter than the default one. This might lead to unexpected results.
If this is the case, you can apply custom styles directly on to the error output::

use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Question\Question;

// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');

if($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}

$outputStyle = new OutputFormatterStyle('red', 'yellow', ['bold', 'blink']);
$output->getFormatter()->setStyle('fire', $outputStyle);

$bundleName = $helper->ask($input, $output, $question);
}

More information on formatting can be found on the :doc:`/components/console/helpers/formatterhelper` page.

Asking the User for Information
-------------------------------

Expand Down
0