Skip to content

Commit

Permalink
[3.x] Prompts (#1337)
Browse files Browse the repository at this point in the history
* Prompt when required installer argument is missing

* Improve testing framework selection

* Bump minimum Laravel requirement

* Update InstallCommand.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
jessarcher and taylorotwell committed Aug 2, 2023
1 parent bb5edaf commit 5ed8e82
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"require": {
"php": "^8.1.0",
"ext-json": "*",
"illuminate/console": "^10.0",
"illuminate/support": "^10.0",
"illuminate/console": "^10.17",
"illuminate/support": "^10.17",
"jenssegers/agent": "^2.6",
"laravel/fortify": "^1.15"
},
Expand Down
54 changes: 53 additions & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

use Exception;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

class InstallCommand extends Command
use function Laravel\Prompts\multiselect;
use function Laravel\Prompts\select;

class InstallCommand extends Command implements PromptsForMissingInput
{
/**
* The name and signature of the console command.
Expand Down Expand Up @@ -830,4 +836,50 @@ protected function runCommands($commands)
$this->output->write(' '.$line);
});
}

/**
* Prompt for missing input arguments using the returned questions.
*
* @return array
*/
protected function promptForMissingArgumentsUsing()
{
return [
'stack' => fn () => select(
label: 'Which Jetstream stack would you like to install?',
options: [
'inertia' => 'Vue with Inertia',
'livewire' => 'Livewire',
]
),
];
}

/**
* Interact further with the user if they were prompted for missing arguments.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)
{
collect(multiselect(
label: 'Would you like any optional features?',
options: collect([
'teams' => 'Team support',
'api' => 'API support',
'verification' => 'Email verification',
'dark' => 'Dark mode',
])->when(
$input->getArgument('stack') === 'inertia',
fn ($options) => $options->put('ssr', 'Inertia SSR')
)->sort()->all(),
))->each(fn ($option) => $input->setOption($option, true));

$input->setOption('pest', select(
label: 'Which testing framework do you prefer?',
options: ['PHPUnit', 'Pest'],
) === 'Pest');
}
}

0 comments on commit 5ed8e82

Please sign in to comment.