-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Bind input before executing the COMMAND event #15938
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
Conversation
wouldn't this break cases where the command is allowing to get arguments interactively in |
@stof afaics, this only binds, the validation is still done after interact. So I don't think it should cause trouble. It also means listeners can add options/arguments without getting validation errors. |
Failures related to #15940 and not this PR |
Please also add a test where the listener adds an option. And check if it can be used. |
I was looking when validation actually happens as I saw symfony/console#15.
|
So this case from @stof doesn't break because
|
I think exactly that is still no possible with this solution. If you call a command with an option/argument that is only about to be added by a listener, it will throw an exception already when trying to parse the input via |
I think to solve the problem, we really need to refactor the validation. |
@Tobion yeah, or wrap things inside a try..catch loop as is done in other bind cases. (not doing validation in |
So |
8bd327f
to
c41899f
Compare
try { | ||
$command->mergeApplicationDefinition(); | ||
$input->bind($command->getDefinition()); | ||
} catch (InvalidArgumentException $e) { |
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 it would be easiest to just catch all Symfony\Component\Console\Exception\ExceptionInterface
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.
similarly https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Console/Command/Command.php#L234 should be updated
c41899f
to
0af1676
Compare
ping @symfony/deciders PR is now updated and ready to be merged imo |
👍 Status: Reviewed |
👍 Should we add a changelog entry so that people interested in changing the definition notice this is possible now? |
Thank you @wouterj. |
…t (WouterJ) This PR was merged into the 2.8 branch. Discussion ---------- [Console] Bind input before executing the COMMAND event | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10695 (problem 1) | License | MIT | Doc PR | - Previously, `$input` wasn't very usefull in the `console.command` event, as the input was not yet bound to the command definition. With this PR, the input is now bound twice: Once before the event is dispatched (to make it usefull in the listeners) and once at the original location in `Command#run()` (to allow changing the input definition in an event listener). Commits ------- 0af1676 Bind input before executing the COMMAND event
…mmand event (chalasr) This PR was merged into the 2.8 branch. Discussion ---------- [Console] Do not squash input changes made from console.command event | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19441 | License | MIT | Doc PR | n/a Setting arguments/options from the `console.command` event is expected to work since #15938 Commits ------- c8d364b [Console] Do not squash input changes made from console.command event
Previously,
$input
wasn't very usefull in theconsole.command
event, as the input was not yet bound to the command definition.With this PR, the input is now bound twice: Once before the event is dispatched (to make it usefull in the listeners) and once at the original location in
Command#run()
(to allow changing the input definition in an event listener).