55namespace Leaf \Console ;
66
77use Symfony \Component \Console \Command \Command ;
8+ use Symfony \Component \Console \Input \InputArgument ;
89use Symfony \Component \Console \Input \InputOption ;
910use Symfony \Component \Console \Input \InputInterface ;
1011use Symfony \Component \Console \Output \OutputInterface ;
@@ -20,6 +21,7 @@ protected function configure()
2021 $ this
2122 ->setHelp ('Start the leaf app server ' )
2223 ->setDescription ('Run your Leaf app ' )
24+ ->addArgument ('filename ' , InputArgument::OPTIONAL , 'The PHP script to run ' )
2325 ->addOption ('port ' , 'p ' , InputOption::VALUE_OPTIONAL , 'Port to run app on ' )
2426 ->addOption ('watch ' , 'w ' , InputOption::VALUE_NONE , 'Run your leaf app with hot reloading [experimental] ' );
2527 }
@@ -43,6 +45,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4345 }
4446 }
4547
48+ if ($ input ->getArgument ('filename ' )) {
49+ $ input ->setOption ('watch ' , true );
50+ }
51+
4652 if ($ input ->getOption ('watch ' )) {
4753 $ leafWatcherInstalled = Utils \Core::commandExists ('leaf-watcher ' );
4854 $ node = Utils \Core::findNodeJS ();
@@ -79,6 +85,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7985 $ port = $ input ->getOption ('port ' ) ? (int ) $ input ->getOption ('port ' ) : 5500 ;
8086 $ process = Process::fromShellCommandline ("$ watcher --exec $ leaf serve --port $ port " , null , null , null , null );
8187
88+ if ($ input ->getArgument ('filename ' )) {
89+ $ filename = $ input ->getArgument ('filename ' );
90+ $ process = Process::fromShellCommandline ("$ watcher --exec " . PHP_BINARY . " $ filename " , null , null , null , null );
91+ }
92+
8293 return $ process ->run (function ($ type , $ line ) use ($ output ) {
8394 $ output ->write ($ line );
8495 });
0 commit comments