Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Gracefully fail when unable to locate expected binary on the system for artisan docs command #43521

Merged
merged 1 commit into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 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 @@ -351,7 +352,7 @@ protected function open($url)
} elseif (in_array($this->systemOsFamily, ['Darwin', 'Windows', 'Linux'])) {
$this->openViaBuiltInStrategy($url);
} else {
$this->components->warn('Unable to open the URL on your system. You will need to open it yourself.');
$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.');
}
})($url);
}
Expand Down Expand Up @@ -387,11 +388,19 @@ protected function openViaCustomStrategy($url)
*/
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
2 changes: 1 addition & 1 deletion tests/Foundation/FoundationDocsCommandTest.php
Expand Up @@ -292,7 +292,7 @@ public function testUnknownSystemNotifiedToOpenManualy()
$this->app[Kernel::class]->registerCommand($this->command()->setUrlOpener(null)->setSystemOsFamily('Laravel OS'));

$this->artisan('docs validation')
->expectsOutputToContain('Unable to open the URL on your system. You will need to open it yourself.')
->expectsOutputToContain('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.')
->assertSuccessful();
}

Expand Down