Search code examples
symfonysymfony-console

Symfony Console Questionn Helper - How to prompt the default value


In the Symfony Console component, using the Question Helper, is it possible to automatically print the default value of a question?

For example, for this question:

$question = new Question( 'What is your response? ', 'Default response' );

I'd like something like this to be printed:

What is your response? [Default response]


Solution

  • This isn't possible in Symfony 2.5. The only methods supported are explained here.

    The only thing I could suggest would be to have a variable for the default response. E.g:

    $default = 'Default response';
    $questionString = sprintf('What is your response? [%s]', $default);
    $question = new Question($questionString, $default);