stecman / symfony-console-completion

Automatic tab-key completion for Symfony console application options, arguments and parameters
MIT License
421 stars 26 forks source link

Unable to auto-complete for `_completion` command #46

Closed aik099 closed 9 years ago

aik099 commented 9 years ago

As part of console command execution (in pure Symfony Console component) the application input definition is merged with command own input definition. This results in application arguments and options being added to each executed command.

When getting completion for arguments and options we're using command input definition, but since the executed command is app _completion the input definition doesn't contain application input definitions and it's wonderful.

But when we extend CompletionCommand and attempt for it's arguments options we're getting into trouble because the completion command executed from hook is app --generate-hook, but the command we're getting completion for is app _completion and due _completion command input definition was merged with application definition all the arguments are shifted right because command argument (from application input definition) is added in front.

This can be solved by:

  1. using getNativeDefinition instead of getDefinition to get command input definition
  2. override CompletionCommand::getNativeDefinition method to always return command-only (not merged) input definition
  3. call the $this->setDefinition($this->getNativeDefinition()) from the CommandCompletion::configure method.

Same approach is used with ListCommand: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Command/ListCommand.php#L35