-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[10.x] Prompts #46772
Merged
Merged
[10.x] Prompts #46772
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
03a9d5f
Configure prompt fallbacks
jessarcher adcbe06
Update built-in prompts
jessarcher 3a2e7d1
Add placeholder values to make commands
jessarcher e7991d8
Improve docs command when page not found
jessarcher d3255e4
Formatting
jessarcher 166f24b
Show all docs matches when nothing entered
jessarcher 4868139
Update option labels
jessarcher 9a2a972
Tweak vendor:publish compatibility with both prompts
jessarcher 928a89d
Fallback to Symfony when running tests
jessarcher 2bdc345
formatting and fixes
taylorotwell 1110a57
print newline if using prompts on confirmable trait
taylorotwell 4f3bed5
Apply fixes from StyleCI
StyleCIBot 3b039da
Improving spacing between components
jessarcher 4a1c3bc
Update OutputStyle.php
taylorotwell 04a0943
Adds missing dependency
nunomaduro a997347
Adjusts visibitily
nunomaduro 8bb43e8
Fixes return type
nunomaduro 44803ad
Add missing deprecation tag
jessarcher c194be3
Ensure newline state is preserved correctly
jessarcher 93d4431
Formatting
jessarcher 434c1ea
Fix example for `make:command`
jessarcher bb6387e
Prompt for missing args with the arg name when no description provided
jessarcher e5a9d62
Allow passing a closure when customizing missing argument prompts
jessarcher 486dd71
Add missing secret component
jessarcher b5f7561
Add `required` support to prompt fallbacks
jessarcher 1e2f8d3
Simply `select` fallback
jessarcher f2674c7
Add fallback for search prompt
jessarcher 4b8fd9f
Update prompts dependency
jessarcher 6799a1b
Update prompts version
jessarcher f97a714
Fix installation of prompts in CI
jessarcher 436a825
Fix tests
jessarcher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console\Concerns; | ||
|
||
use Laravel\Prompts\ConfirmPrompt; | ||
use Laravel\Prompts\MultiSelectPrompt; | ||
use Laravel\Prompts\PasswordPrompt; | ||
use Laravel\Prompts\Prompt; | ||
use Laravel\Prompts\SearchPrompt; | ||
use Laravel\Prompts\SelectPrompt; | ||
use Laravel\Prompts\SuggestPrompt; | ||
use Laravel\Prompts\TextPrompt; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
trait ConfiguresPrompts | ||
{ | ||
/** | ||
* Configure the prompt fallbacks. | ||
* | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @return void | ||
*/ | ||
protected function configurePrompts(InputInterface $input) | ||
{ | ||
Prompt::setOutput($this->output); | ||
|
||
Prompt::fallbackWhen(! $input->isInteractive() || windows_os() || $this->laravel->runningUnitTests()); | ||
|
||
TextPrompt::fallbackUsing(fn (TextPrompt $prompt) => $this->promptUntilValid( | ||
fn () => $this->components->ask($prompt->label, $prompt->default ?: null) ?? '', | ||
$prompt->required, | ||
$prompt->validate | ||
)); | ||
|
||
PasswordPrompt::fallbackUsing(fn (PasswordPrompt $prompt) => $this->promptUntilValid( | ||
fn () => $this->components->secret($prompt->label) ?? '', | ||
$prompt->required, | ||
$prompt->validate | ||
)); | ||
|
||
ConfirmPrompt::fallbackUsing(fn (ConfirmPrompt $prompt) => $this->promptUntilValid( | ||
fn () => $this->components->confirm($prompt->label, $prompt->default), | ||
$prompt->required, | ||
$prompt->validate | ||
)); | ||
|
||
SelectPrompt::fallbackUsing(fn (SelectPrompt $prompt) => $this->promptUntilValid( | ||
fn () => $this->components->choice($prompt->label, $prompt->options, $prompt->default), | ||
false, | ||
$prompt->validate | ||
)); | ||
|
||
MultiSelectPrompt::fallbackUsing(function (MultiSelectPrompt $prompt) { | ||
if ($prompt->default !== []) { | ||
return $this->promptUntilValid( | ||
fn () => $this->components->choice($prompt->label, $prompt->options, implode(',', $prompt->default), multiple: true), | ||
$prompt->required, | ||
$prompt->validate | ||
); | ||
} | ||
|
||
return $this->promptUntilValid( | ||
fn () => collect($this->components->choice($prompt->label, ['' => 'None', ...$prompt->options], 'None', multiple: true)) | ||
->reject('') | ||
->all(), | ||
$prompt->required, | ||
$prompt->validate | ||
); | ||
}); | ||
|
||
SuggestPrompt::fallbackUsing(fn (SuggestPrompt $prompt) => $this->promptUntilValid( | ||
fn () => $this->components->askWithCompletion($prompt->label, $prompt->options, $prompt->default ?: null) ?? '', | ||
$prompt->required, | ||
$prompt->validate | ||
)); | ||
|
||
SearchPrompt::fallbackUsing(fn (SearchPrompt $prompt) => $this->promptUntilValid( | ||
function () use ($prompt) { | ||
$query = $this->components->ask($prompt->label); | ||
|
||
$options = ($prompt->options)($query); | ||
|
||
return $this->components->choice($prompt->label, $options); | ||
}, | ||
false, | ||
$prompt->validate | ||
)); | ||
} | ||
|
||
/** | ||
* Prompt the user until the given validation callback passes. | ||
* | ||
* @param \Closure $prompt | ||
* @param bool|string $required | ||
* @param \Closure|null $validate | ||
* @return mixed | ||
*/ | ||
protected function promptUntilValid($prompt, $required, $validate) | ||
{ | ||
while (true) { | ||
$result = $prompt(); | ||
|
||
if ($required && ($result === '' || $result === [] || $result === false)) { | ||
$this->components->error(is_string($required) ? $required : 'Required.'); | ||
|
||
continue; | ||
} | ||
|
||
if ($validate) { | ||
$error = $validate($result); | ||
|
||
if (is_string($error) && strlen($error) > 0) { | ||
$this->components->error($error); | ||
|
||
continue; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate having to do this.
The issue is that
laravel/prompts
depends onilluminate/collections ^10.0
, which creates a circular dependency. This would ordinarily be fine because thecomposer.json
in this project specifies that it providesilluminate/collections
atself.version
. However, when doing a shallow clone in CI, none of the tags exist, soself.version
resolves to the hash of the commit, which doesn't satisfy the dependency.Alternatives are:
laravel/prompts
depend on*
instead of^10.0
but remove the ability for composer to force a known compatible version.laravel/prompts
and rely on built-in PHP methods.version
key to thecomposer.json
on this repo and maintain it going forward.version
key tocomposer.json
just for the duration of the build, scraping it fromApplication.php
. We'd need to be careful with any actions that make commits (e.g. update changelog) to make sure they don't include the change.I went with this option as it felt the least hacky and problematic. The downside is that the clone is slower and bigger (an additional ~20MB of git history). If this isn't acceptable, I think I'd opt for removing collections from
laravel/prompts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
Illuminate\Support\Collection
is only used for type-hint and$collect instanceof Collection
I believe we can skip it fromlaravel/prompts
as it shouldn't cause any issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prompts is using collections functionality in a few places, not just the types :(