@@ -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'
@@ -107,11 +108,12 @@ protected function interact(InputInterface $input, OutputInterface $output)
107108 }
108109 }
109110
110-
111111 $ busName = $ input ->getOption ('bus ' );
112-
113- if ($ busName && $ this ->busNames && !$ this ->busLocator ->has ($ busName ) && $ alternatives = $ this ->findAlternatives ($ busName , $ this ->busNames )) {
114- 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 )) {
115117 $ style ->block (sprintf ('Bus "%s" is not defined. ' , $ busName ), null , 'error ' , ' ' , true );
116118
117119 if (1 === \count ($ alternatives )) {
@@ -135,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
135137 }
136138
137139 if (!$ this ->busLocator ->has ($ busName = $ input ->getOption ('bus ' ))) {
138- throw new RuntimeException (sprintf ('Bus "%s" does not exist. ' , $ receiverName ));
140+ throw new RuntimeException (sprintf ('Bus "%s" does not exist. ' , $ busName ));
139141 }
140142
141143 $ receiver = $ this ->receiverLocator ->get ($ receiverName );
0 commit comments