protected function attachComposerFactory(BaseCommand $command)
    {
        if (!method_exists($command, 'setComposerFactory')) {
            throw new \InvalidArgumentException('The passed command does not implement method setComposerFactory()');
        }

        /** @var WrappedCommandTrait $command */
        $command->setComposerFactory(
            function () {
                return Factory::create($this->getIO());
            }
        );

        return $command;
    }