laravel / prompts

Beautiful and user-friendly forms for your command-line PHP applications.
https://laravel.com/docs/prompts
MIT License
529 stars 94 forks source link

Select Validation does not handle argument supplied via CLI #145

Closed JonathanAspeling closed 6 months ago

JonathanAspeling commented 6 months ago

Laravel Prompts Version

v0.1.15

Laravel Version

v10.44.0 ./de

PHP Version

8.2.15

Operating System & Version

Linux Container

Terminal Application

n/a

Description

Good day,

I trust you are doing well!

In short:

I have an artisan command that accepts arguments for when it needs to be called programmatically.

One of the arguments/inputs is of type text. I noted when I supplied the text argument programmatically that prompts validated it and blocked the artisan command from running which is great! It used my custom call back.

I thought this was default behaviour - so later when I added a select prompt I expected it do do the same but noted that it does not and think this might be a bug?

I checked the docs and you can add validation to the select method.

Hoping I spotted something!

Steps To Reproduce

  1. In a Laravel project with the prompts package included
  2. Set up an artisan command
  3. Include these files
    
    use Illuminate\Contracts\Console\PromptsForMissingInput;

use function Laravel\Prompts\text; use function Laravel\Prompts\select;


4. implement PromptsForMissingInput in the artisan command class
5. Ensure that your command can take an arguement for the text property
6. Add text property
7. Add validation that would block an invalid text value
8. Pass invalid text value via CLI argument and watch it get blocked
9. Repeat above steps but with select prompt
10. Notice that it does not get blocked when submitting as a CLI argument and that the artisan command continues to run
JonathanAspeling commented 6 months ago

Howdy apologies!

I made a reasoning error. Thought it was a cool feature that the validation of the promptForMissingArgumentsUsing bits also got applied/exercised if you pass in arguments programmatically when actually I had a check function in the artisan handle method that was catching the issues when called programmatically!

Really great package - enjoying getting into it! <3