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