Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ca0dbd

Browse files
committed
Bus argument is a required option when multiple buses are defined
1 parent aeb528f commit 3ca0dbd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public function __construct(ContainerInterface $busLocator, ContainerInterface $
5757
protected function configure(): void
5858
{
5959
$defaultReceiverName = 1 === \count($this->receiverNames) ? current($this->receiverNames) : null;
60+
$defaultBusName = 1 === \count($this->busNames) ? current($this->busNames) : null;
6061

6162
$this
6263
->setDefinition(array(
6364
new InputArgument('receiver', $defaultReceiverName ? InputArgument::OPTIONAL : InputArgument::REQUIRED, 'Name of the receiver', $defaultReceiverName),
6465
new InputOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit the number of received messages'),
6566
new InputOption('memory-limit', 'm', InputOption::VALUE_REQUIRED, 'The memory limit the worker can consume'),
6667
new InputOption('time-limit', 't', InputOption::VALUE_REQUIRED, 'The time limit in seconds the worker can run'),
67-
new InputOption('bus', 'b', InputOption::VALUE_REQUIRED, 'Name of the bus to which received messages should be dispatched', 'message_bus'),
68+
new InputOption('bus', 'b', InputOption::VALUE_REQUIRED, 'Name of the bus to which received messages should be dispatched', $defaultBusName),
6869
))
6970
->setDescription('Consumes messages')
7071
->setHelp(<<<'EOF'
@@ -108,9 +109,11 @@ protected function interact(InputInterface $input, OutputInterface $output)
108109
}
109110

110111
$busName = $input->getOption('bus');
111-
112-
if ($busName && $this->busNames && !$this->busLocator->has($busName) && $alternatives = $this->findAlternatives($busName, $this->busNames)) {
113-
if ($alternatives = $this->findAlternatives($busName, $this->busNames)) {
112+
if ($this->busNames && !$this->busLocator->has($busName)) {
113+
if (null === $busName) {
114+
$style->block('Missing bus argument.', null, 'error', ' ', true);
115+
$input->setOption('bus', $style->choice('Select one of the available buses', $this->busNames));
116+
} elseif ($alternatives = $this->findAlternatives($busName, $this->busNames)) {
114117
$style->block(sprintf('Bus "%s" is not defined.', $busName), null, 'error', ' ', true);
115118

116119
if (1 === \count($alternatives)) {
@@ -134,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
134137
}
135138

136139
if (!$this->busLocator->has($busName = $input->getOption('bus'))) {
137-
throw new RuntimeException(sprintf('Bus "%s" does not exist.', $receiverName));
140+
throw new RuntimeException(sprintf('Bus "%s" does not exist.', $busName));
138141
}
139142

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

0 commit comments

Comments
 (0)