laravel / prompts

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

No output after `Artisan::call()` command #74

Closed syntafin closed 1 year ago

syntafin commented 1 year ago

Laravel Prompts Version

0.1.7

Laravel Version

10.23.1

PHP Version

8,2.10

Operating System & Version

Arch Linux (Stable Kernel)/Ubuntu 22.04

Terminal Application

ZSH

Description

Good day, asked on Discord yesterday and got said to open an issue.

I migrated the Migration Console Command in my application to Prompts, the informational message intro is shown, and the confirm question too, but after this nothing else, until the command is done, for local environment this does work, but on staging/production it doesnt, as some parts need manual input there.

Maybe this video shows what I mean: https://github.com/laravel/prompts/assets/695535/0fb409e9-4b61-4f7a-bb65-eeae6728c929

Even if I remove the spin (I just tested something with it, as it is not documented), nothing else is shown, the full code of my migration can be found in this Gist: https://gist.github.com/syntafin/dc028e3d9a6863dcef5d26a0bbc9ea96

Last shown prompt is in Line 50-56, everything else doesnt appear (migration still completes on local).

Steps To Reproduce

jessarcher commented 1 year ago

Hi @syntafin,

I've replicated this and found that it's the Artisan::call() commands that are causing it.

If you change them to $this->call() then it works fine.

This is how it's documented to call commands from other commands: https://laravel.com/docs/10.x/artisan#calling-commands-from-other-commands

The Artisan::call() method is only documented for calling Artisan commands outside of the CLI: https://laravel.com/docs/10.x/artisan#programmatically-executing-commands

Still, I don't see any reason why Artisan::call() shouldn't work. I haven't had a chance to dig it fully, but it seems that Artisan::call() doesn't output anything to the CLI, so it's probably changing the OutputBuffer on Prompts and then not restoring it afterwards.

I'll leave this open to investigate properly when I get a chance.

syntafin commented 1 year ago

Thanks for the info! I will change it and try it again.

jessarcher commented 1 year ago

Hey @syntafin, did this solve it for you?

I have some ideas on how to make Artisan::call() handle this scenario, but I'm not sure whether I can justify spending time on it.

Just to document what I'm thinking (mostly for my own benefit):

  1. Publicly expose the output method on Prompts
  2. In both of Laravel's call methods, cache the current output buffer and then restore it afterwards, rather than relying on the $this->output property being correctly set in the command.

This should make things a bit more resilient, but it would need to be staged with a major version bump so that Laravel can safely depend on the new functionality being available.

syntafin commented 1 year ago

Yes I was able to solve it :) .