Skip to content

[9.x] Fixes for console input prompts - #45864

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
lukeraymonddowning:console_input_prompt_fix
Jan 30, 2023
Merged

taylorotwell merged 3 commits into
laravel:9.xfrom
lukeraymonddowning:console_input_prompt_fix

Conversation

@lukeraymonddowning

Copy link
Copy Markdown
Contributor

Hey there!

I discovered this bug whilst updating packages ready for Laravel 10.

Replicating

The easiest way to replicate the bug is via a GeneratorCommand, which implements the PromptsForMissingInput contract and trait from #45629. Execute the command and you'll see the question.

The cause

This problem is caused because of the order of execution for Symfony commands and how the PromptsForMissingInput trait works.

Laravel passes command arguments to Symfony as [0 => 'command-name', 'argument' => 'foo', '--option' => 'bar']. This is fine, because vendor/symfony/console/Command/Command.php:303 takes care of this for us by adding a command option based on the Command name.

However, PromptsForMissingInput performs its magic in the initialize method, which is called earlier in command execution (vendor/symfony/console/Command/Command.php:278). As such, the trait infers that the 'command' argument has not been provided and is a required argument, so it will ask the user for all eternity for its value.

The fix

To fix this, I've simply updated the trait to filter out the command argument name when searching for required input. I've added a test for this that uses a fake command to check that no questions are asked when all arguments other than command are provided.

Thanks for all the hard work!

Kind Regards,
Luke

… `command` option, causing console tests to fail and adding an unnecessary question.
… `command` option, causing console tests to fail and adding an unnecessary question.
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 this pull request may close these issues.

2 participants