@@ -81,7 +81,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181 $ routes = $ this ->router ->getRouteCollection ();
8282
8383 if ($ name ) {
84- if (!($ route = $ routes ->get ($ name )) && $ matchingRoutes = $ this ->findRouteNameContaining ($ name , $ routes )) {
84+ $ route = $ routes ->get ($ name );
85+ $ matchingRoutes = $ this ->findRouteNameContaining ($ name , $ routes );
86+
87+ if (!$ input ->isInteractive () && !$ route && \count ($ matchingRoutes ) > 1 ) {
88+ $ helper ->describe ($ io , $ this ->findRouteContaining ($ name , $ routes ), [
89+ 'format ' => $ input ->getOption ('format ' ),
90+ 'raw_text ' => $ input ->getOption ('raw ' ),
91+ 'show_controllers ' => $ input ->getOption ('show-controllers ' ),
92+ 'output ' => $ io ,
93+ ]);
94+
95+ return 0 ;
96+ }
97+
98+ if (!$ route && $ matchingRoutes ) {
8599 $ default = 1 === \count ($ matchingRoutes ) ? $ matchingRoutes [0 ] : null ;
86100 $ name = $ io ->choice ('Select one of the matching routes ' , $ matchingRoutes , $ default );
87101 $ route = $ routes ->get ($ name );
@@ -120,4 +134,16 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
120134
121135 return $ foundRoutesNames ;
122136 }
137+
138+ private function findRouteContaining (string $ name , RouteCollection $ routes ): RouteCollection
139+ {
140+ $ foundRoutes = new RouteCollection ();
141+ foreach ($ routes as $ routeName => $ route ) {
142+ if (false !== stripos ($ routeName , $ name )) {
143+ $ foundRoutes ->add ($ routeName , $ route );
144+ }
145+ }
146+
147+ return $ foundRoutes ;
148+ }
123149}
0 commit comments