Skip to content

Commit ad66a9a

Browse files
xiCO2ktaylorotwell
andauthored
Improves output if Herd or Valet are installed. (#335)
* Check if the Herd or Valet are available. * typo * style: fixes * style: fixes * style: fixes * Update NewCommand.php * Update NewCommand.php * Update NewCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 59ea47d commit ad66a9a

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/NewCommand.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
212212
}
213213

214214
$output->writeln(" <bg=blue;fg=white> INFO </> Application ready in <options=bold>[{$name}]</>. You can start your local development using:".PHP_EOL);
215-
216215
$output->writeln('<fg=gray>➜</> <options=bold>cd '.$name.'</>');
217-
$output->writeln('<fg=gray>➜</> <options=bold>php artisan serve</>');
218-
$output->writeln('');
219216

217+
if ($this->isParked($directory)) {
218+
$url = $this->generateAppUrl($name);
219+
$output->writeln('<fg=gray>➜</> Open: <options=bold;href='.$url.'>'.$url.'</>');
220+
} else {
221+
$output->writeln('<fg=gray>➜</> <options=bold>php artisan serve</>');
222+
}
223+
224+
$output->writeln('');
220225
$output->writeln(' New to Laravel? Check out our <href=https://bootcamp.laravel.com>bootcamp</> and <href=https://laravel.com/docs/installation#next-steps>documentation</>. <options=bold>Build something amazing!</>');
221226
$output->writeln('');
222227
}
@@ -756,6 +761,29 @@ protected function canResolveHostname($hostname)
756761
return gethostbyname($hostname.'.') !== $hostname.'.';
757762
}
758763

764+
/**
765+
* Determine if the given directory is parked using Herd or Valet.
766+
*
767+
* @param string $directory
768+
* @return bool
769+
*/
770+
protected function isParked(string $directory)
771+
{
772+
foreach (['herd', 'valet'] as $tool) {
773+
$process = new Process([$tool, 'paths']);
774+
775+
$process->run();
776+
777+
if ($process->isSuccessful()) {
778+
$output = json_decode(trim($process->getOutput()));
779+
780+
return in_array(dirname($directory), $output);
781+
}
782+
}
783+
784+
return false;
785+
}
786+
759787
/**
760788
* Get the version that should be downloaded.
761789
*

0 commit comments

Comments
 (0)