diff --git a/CHANGELOG.md b/CHANGELOG.md index 56f53413..359a4b93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 2.2.1 under development -- no changes in this release. +- Enh #207: Add `--open` option for `serve` command (@xepozz) +- Enh #207: Print possible options for `serve` command (@xepozz) ## 2.2.0 February 17, 2024 diff --git a/src/Command/Serve.php b/src/Command/Serve.php index 601f9306..ec40ee89 100644 --- a/src/Command/Serve.php +++ b/src/Command/Serve.php @@ -79,6 +79,7 @@ public function configure(): void $this->defaultWorkers ) ->addOption('env', 'e', InputOption::VALUE_OPTIONAL, 'It is only used for testing.') + ->addOption('open', 'o', InputOption::VALUE_OPTIONAL, 'Opens the serving server in the default browser.') ->addOption('xdebug', 'x', InputOption::VALUE_OPTIONAL, 'Enables XDEBUG session.', false); } @@ -149,7 +150,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $xDebugInstalled = extension_loaded('xdebug'); - $xDebugEnabled = $isLinux && $xDebugInstalled && $input->hasOption('xdebug') && $input->getOption('xdebug'); + $xDebugEnabled = $isLinux && $xDebugInstalled && $input->hasOption('xdebug') && $input->getOption('xdebug') === null; if ($xDebugEnabled) { $command[] = 'XDEBUG_MODE=debug XDEBUG_TRIGGER=yes'; @@ -161,15 +162,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $xDebugInstalled ? sprintf( '%s, %s', phpversion('xdebug'), - $xDebugEnabled ? 'enabled' : 'disabled. Add --xdebug 1 to enable', + $xDebugEnabled ? ' Enabled ' : ' Disabled ', ) : 'Not installed', + '--xdebug', ]; - $outputTable[] = ['Workers', $isLinux ? $workers : 'Not supported']; + $outputTable[] = ['Workers', $isLinux ? $workers : 'Not supported', '--workers, -w']; $outputTable[] = ['Address', $address]; - $outputTable[] = ['Document root', $documentRoot]; - $outputTable[] = ($router ? ['Routing file', $router] : []); + $outputTable[] = ['Document root', $documentRoot, '--docroot, -t']; + $outputTable[] = ($router ? ['Routing file', $router, '--router, -r'] : []); - $io->table(['Configuration'], $outputTable); + $io->table(['Configuration', null, 'Options'], $outputTable); $command[] = '"' . PHP_BINARY . '"' . " -S $address -t \"$documentRoot\" $router"; $command = implode(' ', $command); @@ -185,6 +187,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return ExitCode::OK; } + $openInBrowser = $input->hasOption('open') && $input->getOption('open') === null; + + if ($openInBrowser) { + passthru('open http://' . $address); + } passthru($command, $result); return $result;