Skip to content

Commit

Permalink
Improve windows support and WSL support (#43585)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Aug 8, 2022
1 parent 7e77f4e commit 50f5a91
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Illuminate/Foundation/Console/DocsCommand.php
Expand Up @@ -388,25 +388,28 @@ protected function openViaCustomStrategy($url)
*/
protected function openViaBuiltInStrategy($url)
{
$binary = (new ExecutableFinder())->find(match ($this->systemOsFamily) {
'Darwin' => 'open',
'Windows' => 'start',
'Linux' => 'xdg-open',
});
if ($this->systemOsFamily === 'Windows') {
$process = tap(Process::fromShellCommandline(escapeshellcmd("start {$url}")))->run();

if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}

return;
}

$binary = Collection::make(match ($this->systemOsFamily) {
'Darwin' => ['open'],
'Linux' => ['xdg-open', 'wslview'],
})->first(fn ($binary) => (new ExecutableFinder)->find($binary) !== null);

if ($binary === null) {
$this->components->warn('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.');

return;
}

$binaryExecutable = [
'Darwin' => 'open',
'Windows' => 'start',
'Linux' => 'xdg-open',
][$this->systemOsFamily];

$process = tap(Process::fromShellCommandline($binaryExecutable.' '.escapeshellcmd($url)))->run();
$process = tap(Process::fromShellCommandline(escapeshellcmd("{$binary} {$url}")))->run();

if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
Expand Down

0 comments on commit 50f5a91

Please sign in to comment.