@@ -57,14 +57,15 @@ public function __construct(ContainerInterface $busLocator, ContainerInterface $
57
57
protected function configure (): void
58
58
{
59
59
$ defaultReceiverName = 1 === \count ($ this ->receiverNames ) ? current ($ this ->receiverNames ) : null ;
60
+ $ defaultBusName = 1 === \count ($ this ->busNames ) ? current ($ this ->busNames ) : null ;
60
61
61
62
$ this
62
63
->setDefinition (array (
63
64
new InputArgument ('receiver ' , $ defaultReceiverName ? InputArgument::OPTIONAL : InputArgument::REQUIRED , 'Name of the receiver ' , $ defaultReceiverName ),
64
65
new InputOption ('limit ' , 'l ' , InputOption::VALUE_REQUIRED , 'Limit the number of received messages ' ),
65
66
new InputOption ('memory-limit ' , 'm ' , InputOption::VALUE_REQUIRED , 'The memory limit the worker can consume ' ),
66
67
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 ),
68
69
))
69
70
->setDescription ('Consumes messages ' )
70
71
->setHelp (<<<'EOF'
@@ -108,9 +109,11 @@ protected function interact(InputInterface $input, OutputInterface $output)
108
109
}
109
110
110
111
$ 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 )) {
114
117
$ style ->block (sprintf ('Bus "%s" is not defined. ' , $ busName ), null , 'error ' , ' ' , true );
115
118
116
119
if (1 === \count ($ alternatives )) {
@@ -134,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
134
137
}
135
138
136
139
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 ));
138
141
}
139
142
140
143
$ receiver = $ this ->receiverLocator ->get ($ receiverName );
0 commit comments