-
Notifications
You must be signed in to change notification settings - Fork 11.3k
[9.x] CLI Prompts #45629
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
Merged
Merged
[9.x] CLI Prompts #45629
Conversation
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 allows more flexibility as commands can implement the contract _and_ define their own `interact` method.
0b23d39
to
a9a3e5c
Compare
You're insane, @jessarcher . Thanks for all your effort on Laravel. 🚀 |
Thanks |
LukeTowers
added a commit
to wintercms/storm
that referenced
this pull request
Mar 31, 2025
Adds the PromptsForMissingInput functionality added to Laravel in v9.49.0 (laravel/framework#45629) to the base Command class
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces the ability to automatically prompt the user for missing command arguments instead of returning an error.
This functionality has been added to all
make:*
commands.Before
After
This functionality can be added to any command by implementing the new
Illuminate\Contracts\Console\PromptsForMissingInput
interface:Commands that implement
PromptsForMissingInput
will be checked for any required arguments that were not provided, and then use the argument description to prompt for the value.It also exposes a hook that is called only after the user is prompted for missing arguments, allowing additional actions to be performed. I've used this to add additional prompts on a few of the
make:*
commands that have commonly needed options:Additional prompt for
make:model
The
make:model
command can prompt for additional classes:It will only prompt for options when the required argument is not provided. In other words, it won't prompt for options when calling
make:model Post
.The following illustrates the different scenarios where prompts will and won't show:
make:model
Prompts for model name and additional classes.make:model --migration
Prompts only for the model name.make:model Post
Does not prompt for anything.make:model --no-interaction
Does not prompt for anything.Additional prompt for
make:listener
The
make:listener
command can prompt for the event class being listened for, with tab completion for events in theapp/Events
directory:Additional prompt for
make:observer
andmake:policy
The
make:observer
andmake:policy
commands will prompt for the model, also with tab completion of models in the standard locations:Additional prompt for
make:test
The
make:test
command will prompt for the type of test you would like:Additional prompts for
make:controller
The
make:controller
command will prompt for the type of controller you would like. Ifapi
,resource
, orsingleton
is selected, it will also prompt for the model:I went with the name
PromptsForMissingInput
rather thanPromptsForMissingArguments
to leave the door open for prompting when an option that requires a value is passed without the value.I realise this is a pretty big DX change, so I would appreciate feedback. I'd like to stress that these prompts will only show when an error would otherwise be displayed and only in interactive terminal sessions. If you always pass the required arguments, then nothing will change for you. But if you're like me and can never remember which
make:model
options you want, then you would now be able to run the command without arguments and be prompted for the common options instead of needing to run it with--help
first.