diff --git a/src/ServeCommand.php b/src/ServeCommand.php index a846a69..bb45069 100644 --- a/src/ServeCommand.php +++ b/src/ServeCommand.php @@ -5,6 +5,7 @@ namespace Leaf\Console; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,6 +21,7 @@ protected function configure() $this ->setHelp('Start the leaf app server') ->setDescription('Run your Leaf app') + ->addArgument('filename', InputArgument::OPTIONAL, 'The PHP script to run') ->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'Port to run app on') ->addOption('watch', 'w', InputOption::VALUE_NONE, 'Run your leaf app with hot reloading [experimental]'); } @@ -43,6 +45,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } + if ($input->getArgument('filename')) { + $input->setOption('watch', true); + } + if ($input->getOption('watch')) { $leafWatcherInstalled = Utils\Core::commandExists('leaf-watcher'); $node = Utils\Core::findNodeJS(); @@ -79,6 +85,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $port = $input->getOption('port') ? (int) $input->getOption('port') : 5500; $process = Process::fromShellCommandline("$watcher --exec $leaf serve --port $port", null, null, null, null); + if ($input->getArgument('filename')) { + $filename = $input->getArgument('filename'); + $process = Process::fromShellCommandline("$watcher --exec " . PHP_BINARY . " $filename", null, null, null, null); + } + return $process->run(function ($type, $line) use ($output) { $output->write($line); });