|
4 | 4 |
|
5 | 5 | use Exception; |
6 | 6 | use Illuminate\Console\Command; |
| 7 | +use Illuminate\Contracts\Console\PromptsForMissingInput; |
7 | 8 | use Illuminate\Filesystem\Filesystem; |
8 | 9 | use Illuminate\Support\Str; |
9 | 10 | use RuntimeException; |
| 11 | +use Symfony\Component\Console\Input\InputInterface; |
| 12 | +use Symfony\Component\Console\Output\OutputInterface; |
10 | 13 | use Symfony\Component\Finder\Finder; |
11 | 14 | use Symfony\Component\Process\PhpExecutableFinder; |
12 | 15 | use Symfony\Component\Process\Process; |
13 | 16 |
|
14 | | -class InstallCommand extends Command |
| 17 | +use function Laravel\Prompts\multiselect; |
| 18 | +use function Laravel\Prompts\select; |
| 19 | + |
| 20 | +class InstallCommand extends Command implements PromptsForMissingInput |
15 | 21 | { |
16 | 22 | /** |
17 | 23 | * The name and signature of the console command. |
@@ -830,4 +836,50 @@ protected function runCommands($commands) |
830 | 836 | $this->output->write(' '.$line); |
831 | 837 | }); |
832 | 838 | } |
| 839 | + |
| 840 | + /** |
| 841 | + * Prompt for missing input arguments using the returned questions. |
| 842 | + * |
| 843 | + * @return array |
| 844 | + */ |
| 845 | + protected function promptForMissingArgumentsUsing() |
| 846 | + { |
| 847 | + return [ |
| 848 | + 'stack' => fn () => select( |
| 849 | + label: 'Which Jetstream stack would you like to install?', |
| 850 | + options: [ |
| 851 | + 'inertia' => 'Vue with Inertia', |
| 852 | + 'livewire' => 'Livewire', |
| 853 | + ] |
| 854 | + ), |
| 855 | + ]; |
| 856 | + } |
| 857 | + |
| 858 | + /** |
| 859 | + * Interact further with the user if they were prompted for missing arguments. |
| 860 | + * |
| 861 | + * @param \Symfony\Component\Console\Input\InputInterface $input |
| 862 | + * @param \Symfony\Component\Console\Output\OutputInterface $output |
| 863 | + * @return void |
| 864 | + */ |
| 865 | + protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) |
| 866 | + { |
| 867 | + collect(multiselect( |
| 868 | + label: 'Would you like any optional features?', |
| 869 | + options: collect([ |
| 870 | + 'teams' => 'Team support', |
| 871 | + 'api' => 'API support', |
| 872 | + 'verification' => 'Email verification', |
| 873 | + 'dark' => 'Dark mode', |
| 874 | + ])->when( |
| 875 | + $input->getArgument('stack') === 'inertia', |
| 876 | + fn ($options) => $options->put('ssr', 'Inertia SSR') |
| 877 | + )->sort()->all(), |
| 878 | + ))->each(fn ($option) => $input->setOption($option, true)); |
| 879 | + |
| 880 | + $input->setOption('pest', select( |
| 881 | + label: 'Which testing framework do you prefer?', |
| 882 | + options: ['PHPUnit', 'Pest'], |
| 883 | + ) === 'Pest'); |
| 884 | + } |
833 | 885 | } |
0 commit comments