1616use Symfony \Component \Console \Input \InputInterface ;
1717use Symfony \Component \Console \Input \InputOption ;
1818use Symfony \Component \Console \Output \OutputInterface ;
19+ use Symfony \Component \Console \Style \SymfonyStyle ;
1920use Webmozart \Assert \Assert ;
2021
2122final class ConsoleApplication extends Application
@@ -25,7 +26,7 @@ final class ConsoleApplication extends Application
2526 /**
2627 * @param Command[] $commands
2728 */
28- public function __construct (array $ commands )
29+ public function __construct (array $ commands, private readonly SymfonyStyle $ symfonyStyle )
2930 {
3031 parent ::__construct (self ::NAME , VersionResolver::PACKAGE_VERSION );
3132
@@ -57,12 +58,15 @@ public function doRun(InputInterface $input, OutputInterface $output): int
5758
5859 $ commandName = $ input ->getFirstArgument ();
5960
61+ if ($ commandName === null ) {
62+ return parent ::doRun ($ input , $ output );
63+ }
64+
6065 // if paths exist or if the command name is not the first argument but with --option, eg:
6166 // bin/rector src
6267 // bin/rector --only "RemovePhpVersionIdCheckRector"
6368 // file_exists() can check directory and file
64- if (is_string ($ commandName ) && (
65- file_exists ($ commandName ) || isset ($ _SERVER ['argv ' ][1 ])
69+ if ((file_exists ($ commandName ) || isset ($ _SERVER ['argv ' ][1 ])
6670 && $ commandName !== $ _SERVER ['argv ' ][1 ]
6771 // ensure verify has parameter option, eg: --only
6872 && $ input ->hasParameterOption ($ _SERVER ['argv ' ][1 ])
@@ -73,6 +77,16 @@ public function doRun(InputInterface $input, OutputInterface $output): int
7377 $ tokens = $ privatesAccessor ->getPrivateProperty ($ input , 'tokens ' );
7478 $ tokens = array_merge (['process ' ], $ tokens );
7579 $ privatesAccessor ->setPrivateProperty ($ input , 'tokens ' , $ tokens );
80+ } elseif (! $ this ->has ($ commandName )) {
81+ $ this ->symfonyStyle ->error (
82+ sprintf (
83+ 'The following given path does not match any files or directories: %s%s ' ,
84+ "\n\n - " ,
85+ $ commandName
86+ )
87+ );
88+
89+ return ExitCode::FAILURE ;
7690 }
7791
7892 return parent ::doRun ($ input , $ output );
0 commit comments