Skip to content

[Enhancement] netbeans - force interactive shell when limited detection #14102

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

Closed
wants to merge 3 commits into from

Conversation

cordoval
Copy link
Contributor

Q A
Bug Fix? y
New Feature? n
BC Breaks? n
Deprecations? n
Tests Pass? y
Fixed Tickets #9946
License MIT
Doc PR

@@ -855,7 +855,7 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
$input->setInteractive(false);
} elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) {
$inputStream = $this->getHelperSet()->get('dialog')->getInputStream();
if (!@posix_isatty($inputStream)) {
if (!@posix_isatty($inputStream) && !(true === getenv('SHELL_INTERACTIVE'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be true !== getenv('SHELL_INTERACTIVE')

@cordoval
Copy link
Contributor Author

fabbot.io is now queued? how to reset that one?

@@ -855,7 +855,7 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
$input->setInteractive(false);
} elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) {
$inputStream = $this->getHelperSet()->get('dialog')->getInputStream();
if (!@posix_isatty($inputStream)) {
if (!@posix_isatty($inputStream) && true !== getenv('SHELL_INTERACTIVE')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getenv can return a string or false when the env var is not set. But it cannot be true

@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

done @stof

@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

@tmysik can you please help me verify with this that the terminal now remains interactive? thanks

@cordoval cordoval force-pushed the fix-netbeans-interactive-shell branch from 50c3fa2 to 4b8448e Compare April 3, 2015 03:36
@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

I think the failure in tests is unrelated to this PR.

@tmysik
Copy link

tmysik commented Apr 3, 2015

@cordoval Will be glad to do that! However, could you please provide steps how can I get Symfony with the fix/change? Thanks.

@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

It should be simple, you need to add my fork git remote add cordoval git@github.com:cordoval/symfony.git
then checkout fix-netbeans-interactive-shell branch and you should be in there to test.

@tmysik
Copy link

tmysik commented Apr 3, 2015

@cordoval I must be doing something wrong but not sure what :/ I get:

Fatal error: Call to undefined method Symfony\Component\ClassLoader\DebugUniversalClassLoader::useIncludePath() in /home/gapon/NetBeansProjects/symfony2nb/vendor/symfony/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php on line 41

The command NetBeans runs is:

"/usr/bin/php" "/home/gapon/NetBeansProjects/symfony2nb/app/console" "--ansi" "list" "--xml"

Thanks.

@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

beforehand you have to run composer and all

@tmysik
Copy link

tmysik commented Apr 3, 2015

@cordoval Sorry, no idea what you mean exactly. What I did:

  • created new Symfony project as stated on the download page (using symfony installer)
  • replaced the Symfony sources by your checkout (in vendor directory)
  • run Symfony command to list commands

The result is:

Fatal error: Class 'Symfony\Bundle\DebugBundle\DebugBundle' not found in /home/gapon/NetBeansProjects/s2nb/app/AppKernel.php on line 23
Done.

Thanks.

@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

no, don't use the installer. Development wise i always prefer to clone a symfony-standard edition and checkout branch 2.7, and then run composer install --prefer-source, then go under vendor and cd symfony/symfony then add remotes and git remote update and then checkout my branch after adding the remote. Tedious work but it is what is contributing to any package so far.

@tmysik
Copy link

tmysik commented Apr 3, 2015

@cordoval I followed your steps but still got:

Fatal error: Class 'Symfony\Bundle\DebugBundle\DebugBundle' not found in /home/gapon/NetBeansProjects/symfony-standard/app/AppKernel.php on line 23

Just for verification:

gapon@cattie ~/NetBeansProjects/symfony-standard/vendor/symfony/symfony $ git checkout fix-netbeans-interactive-shell 
Branch fix-netbeans-interactive-shell set up to track remote branch fix-netbeans-interactive-shell from cordoval.
Switched to a new branch 'fix-netbeans-interactive-shell'
gapon@cattie ~/NetBeansProjects/symfony-standard/vendor/symfony/symfony $ git branch 
  2.7
* fix-netbeans-interactive-shell

Thanks.

@stof
Copy link
Member

stof commented Apr 3, 2015

@tmysik the branch with the bugfix is based on symfony 2.3, not on 2.7. So use the 2.4 branch of symfony-standard too to test it

@tmysik
Copy link

tmysik commented Apr 3, 2015

@stof So, I switched symfony-standard to 2.4 branch. Went to vendor/symfony/symfony and switched again to fix-netbeans-interactive-shell branch. However, listing Symfony commands ends with this error:

[RuntimeException]
The console handler requires symfony/monolog-bridge 2.4+

Perhaps it would be great if someone could create a ZIP with properly configured symfony-standard project and proper Symfony version for NetBeans problem - I could it then just easily verify in NetBeans :)

Thanks.

@stof
Copy link
Member

stof commented Apr 3, 2015

I said 2.3, not 2.4

@stof
Copy link
Member

stof commented Apr 3, 2015

ah actually, I mixed the version in my previous comment, sorry

@tmysik
Copy link

tmysik commented Apr 3, 2015

@stof Perfect, thanks for the steps, it works now! And I can confirm that the Symfony commands are interactive again in NetBeans so everything works for us now. Thanks a lot, guys!

@cordoval
Copy link
Contributor Author

cordoval commented Apr 3, 2015

yeah sorry to have said 2.7, i really meant 2.3. Thanks @stof. @tmysik nice! great job!

This should be LGTM then 👍

@tmysik
Copy link

tmysik commented Apr 3, 2015

Thanks a lot for solving this problem!

@fabpot
Copy link
Member

fabpot commented Apr 3, 2015

Thank you @cordoval.

fabpot added a commit that referenced this pull request Apr 3, 2015
…ted detection (cordoval)

This PR was squashed before being merged into the 2.3 branch (closes #14102).

Discussion
----------

[Enhancement] netbeans - force interactive shell when limited detection

|Q            |A  |
|---          |---|
|Bug Fix?     |y  |
|New Feature? |n  |
|BC Breaks?   |n  |
|Deprecations?|n  |
|Tests Pass?  |y  |
|Fixed Tickets|  #9946 |
|License      |MIT|
|Doc PR       |   |

Commits
-------

02cda05 [Enhancement] netbeans - force interactive shell when limited detection
@fabpot fabpot closed this Apr 3, 2015
@cordoval cordoval deleted the fix-netbeans-interactive-shell branch April 3, 2015 13:07
nicolas-grekas added a commit that referenced this pull request Feb 7, 2020
This PR was submitted for the master branch but it was merged into the 4.4 branch instead.

Discussion
----------

[Console] Consider STDIN interactive

| Q             | A
| ------------- | ---
| Branch?       |4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #30726, supersedes #30796
| License       | MIT
| Doc PR        | -

As demonstrated with `yes | bin/console foo` in #30726, original assumption made in #1699 was wrong. Then, #8452 was merged which solved bug #8079 -> this was a use case when application hangs with `--no-interaction` flag - nobody probably realized that application can be in "non-interactive" mode, without using this flag and not hang. Then, there was #14102 which was poor man's fix for problem caused by this. So already plenty issues this behaviour causes. Looks like a mess to me. Application should be considered non-interactive only when explicitly specified so (--no-interactive flag), otherwise it doesn't hang.

### What this change means?
It only changes one case: When doing `echo foo | bin/console bar`, `yes | bin/console bar`, `bin/console bar < foo`, etc. Redirecting stdout is not affected, as application in that case was considered interactive before too. With stdin, this opens possibility to control symfony/console based application by default via stdin, including via `proc_open`.

Additionally, not only it allows to control the input for questions, it also makes the question and answers to display on screen. So before, user had no idea what questions are happening and what answers (defaults) are being used.

### About a BC break
I'm not really aware of a valid use case this can break. Can you help find any?

1. Since symfony/console components were NOT interactive with stdin before, stdin couldn't be used to control them - so there this change breaks nothing, because it didn't make sense to pass stdin there instead of specifying -n flag.
1. If application uses internal logic where it relies on STDIN disregarding `Output::isInteractive` flag, this doesn't change anything for these either - they will keep using STDIN disregarding result of this flag.
1. What if application uses internal logic for stdin AND console components like QuestionHelper? To me, that doesn't make much sense, because with previous behaviour, such questions would result always into defaults. It might make sense in case application supports both modes - either stdin, or user supplied input and just use default answers with stdin. But I cannot figure out example of such use - what would be the case where application allows user to control something via stdin, but at the same time forbids them to set certain aspects (answers to questions given)?
1. What about `SHELL_INTERACTIVE` env variable? Only way to utilize it was to force enable interactive mode, but since it will be interactive now by default, it will do nothing and no behaviour changes.
1. Preventing stdin control was much bigger potential BC break. Despite that, it was disallowed in minor Symfony version. And as far as I can see, I saw no backlash.

Finally, this targets Symfony 5.0 to be extra sure anyways, so I think it's ok, but feel free to suggest documenting this in upgrade guide or changelog. I would even target 4.4, but chose 5.0 as it's easier to push through there.

Commits
-------

ef157d5 [Console] Consider STDIN interactive
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.

5 participants