Skip to content

Commit

Permalink
gracefully fail when unable to locate expected binary on the system
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Aug 3, 2022
1 parent abcc6ea commit 039bb31
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Illuminate/Foundation/Console/DocsCommand.php
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Str;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
use Throwable;

Expand Down Expand Up @@ -385,13 +386,22 @@ protected function openViaCustomStrategy($url)
* @param string $url
* @return void
*/

protected function openViaBuiltInStrategy($url)
{
$process = tap(Process::fromShellCommandline(match ($this->systemOsFamily) {
$binary = (new ExecutableFinder())->find(match ($this->systemOsFamily) {
'Darwin' => 'open',
'Windows' => 'start',
'Linux' => 'xdg-open',
}.' '.escapeshellarg($url)))->run();
});

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;
}

$process = tap(Process::fromShellCommandline($binary.' '.escapeshellarg($url)))->run();

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

0 comments on commit 039bb31

Please sign in to comment.