Skip to content
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

Stop prepending the Cancel option to choice lists #4907

Closed
DieterHolvoet opened this issue Nov 25, 2021 · 0 comments · Fixed by #4908
Closed

Stop prepending the Cancel option to choice lists #4907

DieterHolvoet opened this issue Nov 25, 2021 · 0 comments · Fixed by #4908

Comments

@DieterHolvoet
Copy link
Contributor

DieterHolvoet commented Nov 25, 2021

Problem

A Cancel option is prepended to every choice list, why is this necessary if you can just Ctrl+C to exit like with every other command?

CleanShot 2021-11-25 at 12 44 58@2x

@weitzman had this to say in #4853 (comment):

That cancel choice has been there so long I don't recall its justification. I think you are the first person to actually call it out. I bet others have silently grumbled. Lets discuss in a different PR.

Solution

Stop adding the extra option in DrushStyle::choice.

public function choice($question, array $choices, $default = null)
{
$choices = array_merge(['cancel' => 'Cancel'], $choices) ;
$choices_values = array_values($choices);
$return = parent::choice($question, $choices_values, $default);
if ($return == 'Cancel') {
throw new UserAbortException();
} else {
return array_search($return, $choices);
}
}

We cannot completely remove the method since the Cancel option isn't the only change that override does: it also displays the choices as an indexed list instead of a keyed list:

CleanShot 2021-11-25 at 13 03 51@2x

CleanShot 2021-11-25 at 13 04 14@2x

This might be a BC break: if you pass an indexed array as options and you hardcoded the default value to a certain index, you will now have to subtract 1 from that index.

DieterHolvoet added a commit to DieterHolvoet/drush that referenced this issue Dec 27, 2021
Since the Cancel option is removed from choice lists (drush-ops#4907), the numerical indexes changed. Commands that use an indexed array for options and that have a default value will have to update that default value. I haven't found another occurrence of this issue in Drush core.
DieterHolvoet added a commit that referenced this issue Dec 27, 2021
Since the Cancel option is removed from choice lists (#4907), the numerical indexes changed. Commands that use an indexed array for options and that have a default value will have to update that default value. I haven't found another occurrence of this issue in Drush core.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant