application = $application; } /** * @param ConsoleCommandEvent $event */ public function alterCommandOptions(ConsoleCommandEvent $event) { /* @var Command $command */ $command = $event->getCommand(); $input = $event->getInput(); if ($command->getName() == 'help') { // Symfony 3.x prepares $input for us; Symfony 2.x, on the other // hand, passes it in prior to binding with the command definition, // so we have to go to a little extra work. It may be inadvisable // to do these steps for commands other than 'help'. if (!$input->hasArgument('command_name')) { $command->ignoreValidationErrors(); $command->mergeApplicationDefinition(); $input->bind($command->getDefinition()); } // Symfony Console helpfully swaps 'command_name' and 'command' // depending on whether the user entered `help foo` or `--help foo`. // One of these is always `help`, and the other is the command we // are actually interested in. $nameOfCommandToDescribe = $event->getInput()->getArgument('command_name'); if ($nameOfCommandToDescribe == 'help') { $nameOfCommandToDescribe = $event->getInput()->getArgument('command'); } $commandToDescribe = $this->application->find($nameOfCommandToDescribe); $this->findAndAddHookOptions($commandToDescribe); } else { $this->findAndAddHookOptions($command); } } public function findAndAddHookOptions($command) { if (!$command instanceof AnnotatedCommand) { return; } $command->optionsHook(); } /** * @{@inheritdoc} */ public static function getSubscribedEvents() { return [ConsoleEvents::COMMAND => 'alterCommandOptions']; } }