From c8a621d7b69ab2e568d97a20f837ca733a224006 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Mon, 28 Aug 2023 00:26:11 +1000 Subject: [PATCH] [1.x] Use Laravel Prompts when available (#612) * Use Laravel Prompts when available * Formatting --- src/Console/AddCommand.php | 2 +- .../Concerns/InteractsWithDockerComposeServices.php | 12 ++++++++++-- src/Console/InstallCommand.php | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Console/AddCommand.php b/src/Console/AddCommand.php index 36c2cc92..ac88c598 100644 --- a/src/Console/AddCommand.php +++ b/src/Console/AddCommand.php @@ -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)) { diff --git a/src/Console/Concerns/InteractsWithDockerComposeServices.php b/src/Console/Concerns/InteractsWithDockerComposeServices.php index b93e4918..10974980 100644 --- a/src/Console/Concerns/InteractsWithDockerComposeServices.php +++ b/src/Console/Concerns/InteractsWithDockerComposeServices.php @@ -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); } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 5bc286e5..87ca9847 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -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)) {