Skip to content

Commit

Permalink
[1.x] Use Laravel Prompts when available (#612)
Browse files Browse the repository at this point in the history
* Use Laravel Prompts when available

* Formatting
  • Loading branch information
jessarcher committed Aug 27, 2023
1 parent fc45bdd commit c8a621d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Console/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle()
} elseif ($this->option('no-interaction')) {
$services = $this->defaultServices;
} else {
$services = $this->gatherServicesWithSymfonyMenu();
$services = $this->gatherServicesInteractively();
}

if ($invalidServices = array_diff($services, $this->services)) {
Expand Down
12 changes: 10 additions & 2 deletions src/Console/Concerns/InteractsWithDockerComposeServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ trait InteractsWithDockerComposeServices
protected $defaultServices = ['mysql', 'redis', 'selenium', 'mailpit'];

/**
* Gather the desired Sail services using a Symfony menu.
* Gather the desired Sail services using an interactive prompt.
*
* @return array
*/
protected function gatherServicesWithSymfonyMenu()
protected function gatherServicesInteractively()
{
if (function_exists('\Laravel\Prompts\multiselect')) {
return \Laravel\Prompts\multiselect(
label: 'Which services would you like to install?',
options: $this->services,
default: ['mysql'],
);
}

return $this->choice('Which services would you like to install?', $this->services, 0, null, true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle()
} elseif ($this->option('no-interaction')) {
$services = $this->defaultServices;
} else {
$services = $this->gatherServicesWithSymfonyMenu();
$services = $this->gatherServicesInteractively();
}

if ($invalidServices = array_diff($services, $this->services)) {
Expand Down

0 comments on commit c8a621d

Please sign in to comment.