3333use Symfony \Component \Console \Exception \RuntimeException ;
3434use Symfony \Component \Console \Formatter \OutputFormatter ;
3535use Symfony \Component \Console \Helper \DebugFormatterHelper ;
36+ use Symfony \Component \Console \Helper \DescriptorHelper ;
3637use Symfony \Component \Console \Helper \FormatterHelper ;
3738use Symfony \Component \Console \Helper \Helper ;
3839use Symfony \Component \Console \Helper \HelperSet ;
@@ -259,7 +260,24 @@ public function doRun(InputInterface $input, OutputInterface $output)
259260 // the command name MUST be the first element of the input
260261 $ command = $ this ->find ($ name );
261262 } catch (\Throwable $ e ) {
262- if (!($ e instanceof CommandNotFoundException && !$ e instanceof NamespaceNotFoundException) || 1 !== \count ($ alternatives = $ e ->getAlternatives ()) || !$ input ->isInteractive ()) {
263+ if (($ e instanceof CommandNotFoundException && !$ e instanceof NamespaceNotFoundException) && 1 === \count ($ alternatives = $ e ->getAlternatives ()) && $ input ->isInteractive ()) {
264+ $ alternative = $ alternatives [0 ];
265+
266+ $ style = new SymfonyStyle ($ input , $ output );
267+ $ style ->block (sprintf ("\nCommand \"%s \" is not defined. \n" , $ name ), null , 'error ' );
268+ if (!$ style ->confirm (sprintf ('Do you want to run "%s" instead? ' , $ alternative ), false )) {
269+ if (null !== $ this ->dispatcher ) {
270+ $ event = new ConsoleErrorEvent ($ input , $ output , $ e );
271+ $ this ->dispatcher ->dispatch ($ event , ConsoleEvents::ERROR );
272+
273+ return $ event ->getExitCode ();
274+ }
275+
276+ return 1 ;
277+ }
278+
279+ $ command = $ this ->find ($ alternative );
280+ } else {
263281 if (null !== $ this ->dispatcher ) {
264282 $ event = new ConsoleErrorEvent ($ input , $ output , $ e );
265283 $ this ->dispatcher ->dispatch ($ event , ConsoleEvents::ERROR );
@@ -271,25 +289,22 @@ public function doRun(InputInterface $input, OutputInterface $output)
271289 $ e = $ event ->getError ();
272290 }
273291
274- throw $ e ;
275- }
276-
277- $ alternative = $ alternatives [0 ];
278-
279- $ style = new SymfonyStyle ($ input , $ output );
280- $ style ->block (sprintf ("\nCommand \"%s \" is not defined. \n" , $ name ), null , 'error ' );
281- if (!$ style ->confirm (sprintf ('Do you want to run "%s" instead? ' , $ alternative ), false )) {
282- if (null !== $ this ->dispatcher ) {
283- $ event = new ConsoleErrorEvent ($ input , $ output , $ e );
284- $ this ->dispatcher ->dispatch ($ event , ConsoleEvents::ERROR );
285-
286- return $ event ->getExitCode ();
292+ try {
293+ if ($ e instanceof CommandNotFoundException && $ namespace = $ this ->findNamespace ($ name )) {
294+ $ helper = new DescriptorHelper ();
295+ $ helper ->describe ($ output instanceof ConsoleOutputInterface ? $ output ->getErrorOutput () : $ output , $ this , [
296+ 'format ' => 'txt ' ,
297+ 'raw_text ' => false ,
298+ 'namespace ' => $ namespace ,
299+ 'short ' => false ,
300+ ]);
301+
302+ return isset ($ event ) ? $ event ->getExitCode () : 1 ;
303+ }
304+ } catch (NamespaceNotFoundException ) {
305+ throw $ e ;
287306 }
288-
289- return 1 ;
290307 }
291-
292- $ command = $ this ->find ($ alternative );
293308 }
294309
295310 if ($ command instanceof LazyCommand) {
0 commit comments