Skip to content

Commit

Permalink
Fixes issue if there is no herd or valet installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiCO2k committed May 31, 2024
1 parent 0094be6 commit ec30856
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\multiselect;
use function Laravel\Prompts\select;
Expand Down Expand Up @@ -760,17 +760,7 @@ protected function generateAppUrl($name)
*/
protected function getTld()
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, 'tld', '-v']);

$process->run();

if ($process->isSuccessful()) {
return trim($process->getOutput());
}
}

return 'test';
return $this->runOnValetOrHerd('tld') ?? 'test';
}

/**
Expand All @@ -792,16 +782,30 @@ protected function canResolveHostname($hostname)
*/
protected function isParked(string $directory)
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, 'paths', '-v']);
$output = $this->runOnValetOrHerd('paths');

$process->run();
return $output !== false ? in_array(dirname($directory), json_decode($output)) : false;
}

if ($process->isSuccessful()) {
$output = json_decode(trim($process->getOutput()));

return in_array(dirname($directory), $output);
}
/**
* Runs the given command on "herd" or "valet" cli.
*
* @param string $command
* @return string|bool
*/
protected function runOnValetOrHerd(string $command)
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, $command, '-v']);

try {
$process->run();

if ($process->isSuccessful()) {
return trim($process->getOutput());
}
} catch (ProcessStartFailedException) {}
}

return false;
Expand Down

0 comments on commit ec30856

Please sign in to comment.