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
[Console] Add ability to select values interactively #6343
Conversation
* @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite) | ||
* @param string $errorMessage Message which will be shown if invalid value from choice list would be picked | ||
* | ||
* @return mixed The selected value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should make it more clear that the selected value is a a key of the $choices
array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its the array key that is returned, the return type can only be string|integer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Maybe the default value should be shown somehow? |
@Seldaek: It's up to you to display it (probably in the question). That's how the other |
* | ||
* @return integer|string The selected value (the key of the choices array) | ||
*/ | ||
public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should typehint the choices as array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
Would be nice to also add the ability to select multiple values (probably other PR). |
… consistent with other method in the same class
@Tobion That's indeed something that should be done in another PR. |
This PR was merged into the master branch. Commits ------- 008dc8f [Console] tweaked the select() method in the dialog helper to be more consistent with other method in the same class 692b0f4 [Console] added select() method for DialogHelper Discussion ---------- [Console] Add ability to select values interactively This is a slightly modified version of #5417 Adds ability to select from value list: $values = array('One', 'Two', 'Three'); $pick = $this->getHelper('dialog')->select($output, 'Pick a bundle:', $values, 2); var_dump($pick); ... would give the following CLI output: Pick a bundle: 0 One 1 Two 2 Three > 1 1 --------------------------------------------------------------------------- by Seldaek at 2012-12-14T09:07:40Z Maybe the default value should be shown somehow? --------------------------------------------------------------------------- by fabpot at 2012-12-14T09:28:42Z @Seldaek: It's up to you to display it (probably in the question). That's how the other `ask*` methods work. --------------------------------------------------------------------------- by Tobion at 2012-12-14T09:38:40Z Would be nice to also add the ability to select multiple values (probably other PR). So one can select each option individually to toggle it's selection. And one can select multiple with a range like `2-7` (as in the git console with `git add -i`). --------------------------------------------------------------------------- by fabpot at 2012-12-14T09:45:10Z @Tobion That's indeed something that should be done in another PR.
@fabpot i think you've missed "return => key" handling while tweaking the code. |
I removed this on purpose.The list of options is already quite long, and getting the value from the original array is simple enough to not add more options. |
one way to go could be introducing some kind of DialogSelectPromptBuilder, but not sure |
This is a slightly modified version of #5417
Adds ability to select from value list:
... would give the following CLI output: