Skip to content

Commit a6d3c60

Browse files
authored
Merge pull request #207 from yiisoft/serve
Show options + add open flag for Serve command
2 parents a7d8e33 + 4f6cc5b commit a6d3c60

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## 2.2.1 under development
44

5-
- no changes in this release.
5+
- Enh #207: Add `--open` option for `serve` command (@xepozz)
6+
- Enh #207: Print possible options for `serve` command (@xepozz)
67

78
## 2.2.0 February 17, 2024
89

src/Command/Serve.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function configure(): void
7979
$this->defaultWorkers
8080
)
8181
->addOption('env', 'e', InputOption::VALUE_OPTIONAL, 'It is only used for testing.')
82+
->addOption('open', 'o', InputOption::VALUE_OPTIONAL, 'Opens the serving server in the default browser.')
8283
->addOption('xdebug', 'x', InputOption::VALUE_OPTIONAL, 'Enables XDEBUG session.', false);
8384
}
8485

@@ -149,7 +150,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
149150
}
150151

151152
$xDebugInstalled = extension_loaded('xdebug');
152-
$xDebugEnabled = $isLinux && $xDebugInstalled && $input->hasOption('xdebug') && $input->getOption('xdebug');
153+
$xDebugEnabled = $isLinux && $xDebugInstalled && $input->hasOption('xdebug') && $input->getOption('xdebug') === null;
153154

154155
if ($xDebugEnabled) {
155156
$command[] = 'XDEBUG_MODE=debug XDEBUG_TRIGGER=yes';
@@ -161,15 +162,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
161162
$xDebugInstalled ? sprintf(
162163
'%s, %s',
163164
phpversion('xdebug'),
164-
$xDebugEnabled ? '<info>enabled</>' : '<error>disabled. Add --xdebug 1 to enable</>',
165+
$xDebugEnabled ? '<info> Enabled </>' : '<error> Disabled </>',
165166
) : '<error>Not installed</>',
167+
'--xdebug',
166168
];
167-
$outputTable[] = ['Workers', $isLinux ? $workers : 'Not supported'];
169+
$outputTable[] = ['Workers', $isLinux ? $workers : 'Not supported', '--workers, -w'];
168170
$outputTable[] = ['Address', $address];
169-
$outputTable[] = ['Document root', $documentRoot];
170-
$outputTable[] = ($router ? ['Routing file', $router] : []);
171+
$outputTable[] = ['Document root', $documentRoot, '--docroot, -t'];
172+
$outputTable[] = ($router ? ['Routing file', $router, '--router, -r'] : []);
171173

172-
$io->table(['Configuration'], $outputTable);
174+
$io->table(['Configuration', null, 'Options'], $outputTable);
173175

174176
$command[] = '"' . PHP_BINARY . '"' . " -S $address -t \"$documentRoot\" $router";
175177
$command = implode(' ', $command);
@@ -185,6 +187,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
185187
return ExitCode::OK;
186188
}
187189

190+
$openInBrowser = $input->hasOption('open') && $input->getOption('open') === null;
191+
192+
if ($openInBrowser) {
193+
passthru('open http://' . $address);
194+
}
188195
passthru($command, $result);
189196

190197
return $result;

0 commit comments

Comments
 (0)