[5.5] Check for --no-interaction flag on command calls #22515
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.
Currently, calling an artisan command from another artisan command as described in the docs (
$this->call(...)
) does not allow the--no-interaction
flag to be set on the command (or rather, you can set it, but it won't have any effect unless the called command specifically checks for it).The current workaround is to use the
Artisan
facade.This was raised in the Adldap2-Laravel repo:
Adldap2/Adldap2-Laravel#441 (comment)
This PR solves the issue by explicitly checking for the
--no-interaction
flag (but not the shorthand-n
flag) to set the interactive mode of the new input in the same manner symfony/application sets it inApplication::configureIO
:https://github.com/symfony/symfony/blob/07766b39052b6ba294dc6ddf85e38ee61a8e0bcb/src/Symfony/Component/Console/Application.php#L791-L792
An alternative would be to check if the current command is being run in non-interactive mode, but I think that would have a higher chance of breaking existing code. This way, the only way to break existing code is if someone is using the
--no-interaction
argument in a command call and somehow still expecting interaction.Avoiding BC breaks is also the reason I've omitted the
-n
short syntax, as it is plausible that people may have developed commands that are being called exclusively by other commands and have their own meaning for-n
without knowing it's intended purpose.