Skip to content

Commit

Permalink
[Console] Consider STDIN interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky authored and nicolas-grekas committed Feb 7, 2020
1 parent 54e1cf9 commit 55b6ebf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
11 changes: 0 additions & 11 deletions Application.php
Expand Up @@ -36,7 +36,6 @@
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\StreamableInputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -947,16 +946,6 @@ protected function configureIO(InputInterface $input, OutputInterface $output)

if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) {
$input->setInteractive(false);
} elseif (\function_exists('posix_isatty')) {

This comment has been minimized.

Copy link
@JoydS

JoydS Mar 5, 2020

That is a really hard BC... You can't do that on a minor with nothing in the changelog !

This comment has been minimized.

Copy link
@danepowell

danepowell Mar 19, 2020

Contributor

No kidding, this bit us hard and we spent a lot time just tracing it back to Symfony. Seems to be follow-up discussion here: symfony/symfony#36027

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Mar 19, 2020

Member

Please confirm symfony/symfony#36031 fixes the issue for you.

This comment has been minimized.

Copy link
@JoydS

JoydS Mar 19, 2020

I fixed the code long time ago adding --no-interaction, but thanks

$inputStream = null;

if ($input instanceof StreamableInputInterface) {
$inputStream = $input->getStream();
}

if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) {
$input->setInteractive(false);
}
}

switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
Expand Down
9 changes: 1 addition & 8 deletions Tester/ApplicationTester.php
Expand Up @@ -59,19 +59,12 @@ public function run(array $input, $options = [])
$this->input->setInteractive($options['interactive']);
}

$shellInteractive = getenv('SHELL_INTERACTIVE');

if ($this->inputs) {
$this->input->setStream(self::createStream($this->inputs));
putenv('SHELL_INTERACTIVE=1');
}

$this->initOutput($options);

$this->statusCode = $this->application->run($this->input, $this->output);

putenv($shellInteractive ? "SHELL_INTERACTIVE=$shellInteractive" : 'SHELL_INTERACTIVE');

return $this->statusCode;
return $this->statusCode = $this->application->run($this->input, $this->output);
}
}
28 changes: 28 additions & 0 deletions Tests/phpt/uses_stdin_as_interactive_input.phpt
@@ -0,0 +1,28 @@
--STDIN--
Hello World
--FILE--
<?php

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

(new Application())
->register('app')
->setCode(function(InputInterface $input, OutputInterface $output) {
$output->writeln((new QuestionHelper())->ask($input, $output, new Question('Foo?')));
})
->getApplication()
->setDefaultCommand('app', true)
->run()
;
--EXPECT--
Foo?Hello World

0 comments on commit 55b6ebf

Please sign in to comment.