1515use RectorPrefix202603 \Symfony \Component \Console \Input \InputInterface ;
1616use RectorPrefix202603 \Symfony \Component \Console \Input \InputOption ;
1717use RectorPrefix202603 \Symfony \Component \Console \Output \OutputInterface ;
18+ use RectorPrefix202603 \Symfony \Component \Console \Style \SymfonyStyle ;
1819use RectorPrefix202603 \Webmozart \Assert \Assert ;
1920final class ConsoleApplication extends Application
2021{
22+ /**
23+ * @readonly
24+ */
25+ private SymfonyStyle $ symfonyStyle ;
2126 /**
2227 * @var string
2328 */
2429 private const NAME = 'Rector ' ;
2530 /**
2631 * @param Command[] $commands
2732 */
28- public function __construct (array $ commands )
33+ public function __construct (array $ commands, SymfonyStyle $ symfonyStyle )
2934 {
35+ $ this ->symfonyStyle = $ symfonyStyle ;
3036 parent ::__construct (self ::NAME , VersionResolver::PACKAGE_VERSION );
3137 Assert::notEmpty ($ commands );
3238 Assert::allIsInstanceOf ($ commands , Command::class);
@@ -48,16 +54,22 @@ public function doRun(InputInterface $input, OutputInterface $output): int
4854 $ output ->write (\PHP_EOL );
4955 }
5056 $ commandName = $ input ->getFirstArgument ();
57+ if ($ commandName === null ) {
58+ return parent ::doRun ($ input , $ output );
59+ }
5160 // if paths exist or if the command name is not the first argument but with --option, eg:
5261 // bin/rector src
5362 // bin/rector --only "RemovePhpVersionIdCheckRector"
5463 // file_exists() can check directory and file
55- if (is_string ( $ commandName ) && ( file_exists ($ commandName ) || isset ($ _SERVER ['argv ' ][1 ]) && $ commandName !== $ _SERVER ['argv ' ][1 ] && $ input ->hasParameterOption ($ _SERVER ['argv ' ][1 ]) )) {
64+ if (file_exists ($ commandName ) || isset ($ _SERVER ['argv ' ][1 ]) && $ commandName !== $ _SERVER ['argv ' ][1 ] && $ input ->hasParameterOption ($ _SERVER ['argv ' ][1 ])) {
5665 // prepend command name if implicit
5766 $ privatesAccessor = new PrivatesAccessor ();
5867 $ tokens = $ privatesAccessor ->getPrivateProperty ($ input , 'tokens ' );
5968 $ tokens = array_merge (['process ' ], $ tokens );
6069 $ privatesAccessor ->setPrivateProperty ($ input , 'tokens ' , $ tokens );
70+ } elseif (!$ this ->has ($ commandName )) {
71+ $ this ->symfonyStyle ->error (sprintf ('The following given path does not match any files or directories: %s%s ' , "\n\n - " , $ commandName ));
72+ return \Rector \Console \ExitCode::FAILURE ;
6173 }
6274 return parent ::doRun ($ input , $ output );
6375 }
0 commit comments