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

[6.x] Check no-interaction flag exists and is true for Artisan commands #33950

Merged
merged 2 commits into from
Aug 20, 2020
Merged

[6.x] Check no-interaction flag exists and is true for Artisan commands #33950

merged 2 commits into from
Aug 20, 2020

Conversation

liamjcooper
Copy link
Contributor

Go easy on me, this is my first contribution to open source.

This PR was made because I noticed a bug with the way that the CallsCommand concern handles how it checks if the command should be run with no-interaction i.e. does not prompt for user input.

It currently only checks if the option is present, rather than checks if it is true or false in the input array. So, rather than hasParameterOption in createInputFromArguments, I changed it to getParameterOption which still returns false if the option is not present. If not present === false; present in terminal === true; present but value is false === false.

I reproduced this bug when calling a deprecated Artisan command in a Laravel package which passed all of the arguments and options to the new Artisan command via $this->call(...), PSB an example.

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $options = collect($this->options())->mapWithKeys(function($value, $key) {
            return ["--{$key}" => $value];
        })->toArray();

        $this->call('prompt:real', $options);

        return 0;
    }

With this array of options, it passes a default value for no-interaction which is false. In its current state, the framework will take that option as: you want no prompt to appear as it runs through the command.

Here is an example of the real command that should prompt for input, but would not:

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $this->ask('What is your name?');

        return 0;
    }

Thank you for taking the time to review this. I hope I have explained this clearly enough.

@taylorotwell taylorotwell merged commit c8d453c into laravel:6.x Aug 20, 2020
@liamjcooper liamjcooper deleted the fix/no-interaction-flag branch September 8, 2020 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants