Closed
Description
When listening to the console.command event and trying to access information there are some problems:
You cannot acess arguments or options in the InputInterface likeSolved by [Console] Bind input before executing the COMMAND event #15938$input->getOption('myoption');
because they are not parsed yet. It's done only later by the application.
A workaround is something like$command->mergeApplicationDefinition(); $input->bind($command->getDefinition());
inside your listener.
IMO the input should already have to params bound before the listener. Otherwise the input is pretty useless in listeners. Since people might want to add arguments/options dynamically in a listener (see 2.), the definition probably also needs to be bound after the listener just as now. So it should be done before and after the listener automatically.- Modifying the inputdefinition in a listener does not really work with the help. One can add options/arguments to some commands dynamically like in http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/. But this will not properly work with the help display because running the help for a command (app/console mycommand --help) will actually run the HelpCommand and an event for this command. Thus the definition is not modifying for the "mycommand" but for the help. So the changed definition is not displayed.