Repository: symfony/symfony
File: src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php (PHP)

Code before:

                return;
            }

            $io->block('Which transports/receivers do you want to consume?', null, 'fg=white;bg=blue', ' ', true);

            $io->writeln('Choose which receivers you want to consume messages from in order of priority.');
            if (\count($this->receiverNames) > 1) {
                $io->writeln(\sprintf('Hint: to consume from multiple, use a list of their names, e.g. <comment>%s</comment>', implode(', ', $this->receiverNames)));
            }

            $question = new ChoiceQuestion('Select receivers to consume:', $this->receiverNames, 0);
            $question->setMultiselect(true);

            $input->setArgument('receivers', $io->askQuestion($question));
        }

        if (!$input->getArgument('receivers')) {
            throw new RuntimeException('Please pass at least one receiver.');
        }
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        if ($input->getOption('exclude-receivers') && !$input->getOption('all')) {
            throw new InvalidOptionException('The --exclude-receivers option can only be used with the --all option.');
        }

        $receivers = [];
        $rateLimiters = [];
        $receiverNames = $input->getOption('all') ? $this->receiverNames : $input->getArgument('receivers');

        if ($input->getOption('all') && $excludedTransports = $input->getOption('exclude-receivers')) {
            $receiverNames = array_diff($receiverNames, $excludedTransports);

            if (!$receiverNames) {
                throw new RuntimeException('All transports/receivers have been excluded. Please specify at least one to consume from.');
            }
        }

        foreach ($receiverNames as $receiverName) {
            if (!$this->receiverLocator->has($receiverName)) {
                $message = \sprintf('The receiver "%s" does not exist.', $receiverName);
                if ($this->receiverNames) {
                    $message .= \sprintf(' Valid receivers are: %s.', implode(', ', $this->receiverNames));
                }

                throw new RuntimeException($message);
            }

            $receiver = $this->receiverLocator->get($receiverName);

Review comment (suggestion):
```suggestion
            throw new InvalidOptionException('The "--exclude-receivers" option can only be used with the "--all" option.');
```

Code after:

                return;
            }

            $io->block('Which transports/receivers do you want to consume?', null, 'fg=white;bg=blue', ' ', true);

            $io->writeln('Choose which receivers you want to consume messages from in order of priority.');
            if (\count($this->receiverNames) > 1) {
                $io->writeln(\sprintf('Hint: to consume from multiple, use a list of their names, e.g. <comment>%s</comment>', implode(', ', $this->receiverNames)));
            }

            $question = new ChoiceQuestion('Select receivers to consume:', $this->receiverNames, 0);
            $question->setMultiselect(true);

            $input->setArgument('receivers', $io->askQuestion($question));
        }

        if (!$input->getArgument('receivers')) {
            throw new RuntimeException('Please pass at least one receiver.');
        }
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        if ($input->getOption('exclude-receivers') && !$input->getOption('all')) {
            throw new InvalidOptionException('The "--exclude-receivers" option can only be used with the "--all" option.');
        }

        $receivers = [];
        $rateLimiters = [];
        $receiverNames = $input->getOption('all') ? $this->receiverNames : $input->getArgument('receivers');

        if ($input->getOption('all') && $excludedTransports = $input->getOption('exclude-receivers')) {
            $receiverNames = array_diff($receiverNames, $excludedTransports);

            if (!$receiverNames) {
                throw new RuntimeException('All transports/receivers have been excluded, please specify at least one to consume from.');
            }
        }

        foreach ($receiverNames as $receiverName) {
            if (!$this->receiverLocator->has($receiverName)) {
                $message = \sprintf('The receiver "%s" does not exist.', $receiverName);
                if ($this->receiverNames) {
                    $message .= \sprintf(' Valid receivers are: %s.', implode(', ', $this->receiverNames));
                }

                throw new RuntimeException($message);
            }

            $receiver = $this->receiverLocator->get($receiverName);