[9.x] Fixes for console input prompts #45864
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thePromptsForMissingInput
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 acommand
option based on the Command name.However,
PromptsForMissingInput
performs its magic in theinitialize
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 thancommand
are provided.Thanks for all the hard work!
Kind Regards,
Luke