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

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

Closed
syntafin opened this issue Sep 18, 2023 · 4 comments
Closed

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

syntafin opened this issue Sep 18, 2023 · 4 comments
Assignees
Labels

Comments

@syntafin
Copy link

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

  • Use Laravel Prompts
  • After 3 Prompts, everything else is skipped
@jessarcher
Copy link
Member

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.

@jessarcher jessarcher changed the title Informational messages not displayed/User input not requested No output after Artisan::call() command Sep 19, 2023
@syntafin
Copy link
Author

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

@jessarcher
Copy link
Member

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
Copy link
Author

Yes I was able to solve it :) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants