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:
using getNativeDefinition instead of getDefinition to get command input definition
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 isapp --generate-hook
, but the command we're getting completion for isapp _completion
and due_completion
command input definition was merged with application definition all the arguments are shifted right becausecommand
argument (from application input definition) is added in front.This can be solved by:
getNativeDefinition
instead ofgetDefinition
to get command input definitionCompletionCommand::getNativeDefinition
method to always return command-only (not merged) input definition$this->setDefinition($this->getNativeDefinition())
from theCommandCompletion::configure
method.Same approach is used with
ListCommand
: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Command/ListCommand.php#L35