Skip to content

Commit 5ed8e82

Browse files
[3.x] Prompts (#1337)
* Prompt when required installer argument is missing * Improve testing framework selection * Bump minimum Laravel requirement * Update InstallCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent bb5edaf commit 5ed8e82

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"require": {
1717
"php": "^8.1.0",
1818
"ext-json": "*",
19-
"illuminate/console": "^10.0",
20-
"illuminate/support": "^10.0",
19+
"illuminate/console": "^10.17",
20+
"illuminate/support": "^10.17",
2121
"jenssegers/agent": "^2.6",
2222
"laravel/fortify": "^1.15"
2323
},

src/Console/InstallCommand.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44

55
use Exception;
66
use Illuminate\Console\Command;
7+
use Illuminate\Contracts\Console\PromptsForMissingInput;
78
use Illuminate\Filesystem\Filesystem;
89
use Illuminate\Support\Str;
910
use RuntimeException;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
1013
use Symfony\Component\Finder\Finder;
1114
use Symfony\Component\Process\PhpExecutableFinder;
1215
use Symfony\Component\Process\Process;
1316

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
1521
{
1622
/**
1723
* The name and signature of the console command.
@@ -830,4 +836,50 @@ protected function runCommands($commands)
830836
$this->output->write(' '.$line);
831837
});
832838
}
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+
}
833885
}

0 commit comments

Comments
 (0)