Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Prompts #1337

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}