From ec308561338dbf9589a1d17570b0a63db9e1f50a Mon Sep 17 00:00:00 2001 From: Francisco Madeira Date: Fri, 31 May 2024 10:58:25 +0100 Subject: [PATCH 1/3] Fixes issue if there is no `herd` or `valet` installed. --- src/NewCommand.php | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/NewCommand.php b/src/NewCommand.php index 9b37c1c..8f82105 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -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; @@ -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'; } /** @@ -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; From 466a710b1993777ff5e3c00a14be21e0d1b8d827 Mon Sep 17 00:00:00 2001 From: Francisco Madeira Date: Fri, 31 May 2024 11:01:36 +0100 Subject: [PATCH 2/3] style: fixes --- src/NewCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NewCommand.php b/src/NewCommand.php index 8f82105..d1b5cec 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -14,6 +14,7 @@ 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; @@ -787,7 +788,6 @@ protected function isParked(string $directory) return $output !== false ? in_array(dirname($directory), json_decode($output)) : false; } - /** * Runs the given command on "herd" or "valet" cli. * @@ -805,7 +805,8 @@ protected function runOnValetOrHerd(string $command) if ($process->isSuccessful()) { return trim($process->getOutput()); } - } catch (ProcessStartFailedException) {} + } catch (ProcessStartFailedException) { + } } return false; From 66de8fbb4ff883d019c68819686f9ca933dedfad Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 31 May 2024 11:23:30 -0500 Subject: [PATCH 3/3] Update NewCommand.php --- src/NewCommand.php | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/NewCommand.php b/src/NewCommand.php index d1b5cec..34e3ae2 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -788,30 +788,6 @@ protected function isParked(string $directory) return $output !== false ? in_array(dirname($directory), json_decode($output)) : false; } - /** - * 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; - } - /** * Get the version that should be downloaded. * @@ -851,6 +827,30 @@ protected function phpBinary() : 'php'; } + /** + * Runs the given command on the "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; + } + /** * Run the given commands. *