laravel / tinker

Powerful REPL for the Laravel framework.
https://laravel.com/docs/artisan#tinker
MIT License
7.34k stars 130 forks source link

Tinker does not fully respect -q and -n flags #67

Closed aksonnic closed 5 years ago

aksonnic commented 5 years ago

Description:

Tinker with either the -q (quiet) or the -n (no interaction) does not fully respect these options. Use case is an include file that echos stuff as part of a build process, but it cannot be run headless.

Steps To Reproduce:

> php artisan tinker -q prints prompt >>> and the Exit: Goodbye. message.

> php artisan tinker -n waits for interaction before exiting.

File hello_world.php:

<?php echo('Hello world!');

> php artisan tinker -qn hello_world.php pauses until exit is typed in shell.

driesvints commented 5 years ago

I've been looking into this but tbh I don't see the point of these options with tinker. -n make no sense as the whole point of tinker is interaction. -q makes a little more sense but then again what's the point of not echo'ing data if you're explicitly asking for it in your tinker commands?

aksonnic commented 5 years ago

Tinker allows running a script on start, so I was using it in a shell script to run a PHP script that could use the app framework/models/etc, and output some data (JSON in this case). Kept having to remove the header output, and it would hang shell script until I typed exit.

It could have been a Command, and I could have written to a file, sure, but it was a one off. And for shell scripting, piping etc it sure is nice to get bare output.

Also, the help for tinker says it accepts these options.

driesvints commented 5 years ago

Yeah but you could technically just run the script with a php execution, right?

php hello_world.php

It's the same thing, not?

Also, the help for tinker says it accepts these options.

I think this is the actual problem and the options shouldn't be here.

aksonnic commented 5 years ago

php hello_world.php wouldn’t boot the app and have all the Laravel goodness.

Noooo, don’t remove the options! :) Will you accept a PR?

driesvints commented 5 years ago

php hello_world.php wouldn’t boot the app and have all the Laravel goodness.

Hmm, excellent point. Hadn't considered that.

Noooo, don’t remove the options! :) Will you accept a PR?

Now that I know the above I think so yeah. Feel free! But definitely make sure you thoroughly explain why in the PR comment.

aksonnic commented 5 years ago

After digging around in the code, it's probably an issue on Psysh as they don't check quiet or interactive flags in their loop. In fact, they purposely reset the verbosity back to normal...

driesvints commented 5 years ago

Hmm well if that's the case then there's nothing we can really do on our end. Atm we aren't planning on differentiating much on how Psysh tackles the basics. Sorry about that.

bobthecow commented 5 years ago

This is fixed and will be available in the next stable PsySH release. Thanks @aksonnic!

driesvints commented 5 years ago

Thanks @bobthecow!