Skip to content

[Console] invalid default returned from ChoiceQuestion on non interactive mode when using SymfonyStyle #25470

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
mathroc opened this issue Dec 12, 2017 · 4 comments

Comments

@mathroc
Copy link
Contributor

mathroc commented Dec 12, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3.x

the choice index is returned instead of the choice value when a default choice is specified and the command is executed with -n

the default value is set to the choice index here : https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Style/SymfonyStyle.php#L230

so I’ve tried to run $io->askQuestion(new ChoiceQuestion($question, $choices, $default)); directly. it works on non interactive mode but fails on interactive mode

I think ChoiceQuestion should override getDefault() to solve this. I can make a PR for this but will this considered a BC break ? or does it falls in the bug fix category ?

@Simperfit
Copy link
Contributor

@mathroc Could you make a PR for this ? I think this should be a bugfix since the behaviour is wrong right now.

@chalasr
Copy link
Member

chalasr commented Dec 14, 2017

Can you give a simple reproducer so that we can confirm it's a bug?

@Simperfit
Copy link
Contributor

@chalasr Reproducer and bugfix added.

@Simperfit
Copy link
Contributor

Status: Reviewed

nicolas-grekas added a commit that referenced this issue Dec 18, 2017
…nd passing -n would output the index (Simperfit)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] fix a bug when you are passing a default value and passing -n would output the index

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #25470
| License       | MIT
| Doc PR        |

We are fixing a bug when you are using a default value with -n, it would output the index instead of the value.

Simple reproducer Simperfit/symfony-reproducer@5079dd1?diff=split#diff-77efcc28bc5309e1af9ac07a1e073009R40

Commits
-------

41ffc69 [Console] fix a bug when you are passing a default value and passing -n would ouput the index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants