[Console] Consider STDIN interactive
This commit is contained in:
parent
cd2dec3a7f
commit
ef157d5b3f
@ -36,7 +36,6 @@ use Symfony\Component\Console\Input\InputAwareInterface;
|
|||||||
use Symfony\Component\Console\Input\InputDefinition;
|
use Symfony\Component\Console\Input\InputDefinition;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\StreamableInputInterface;
|
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@ -947,16 +946,6 @@ class Application implements ResetInterface
|
|||||||
|
|
||||||
if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) {
|
if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) {
|
||||||
$input->setInteractive(false);
|
$input->setInteractive(false);
|
||||||
} elseif (\function_exists('posix_isatty')) {
|
|
||||||
$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')) {
|
switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
|
||||||
|
@ -59,19 +59,12 @@ class ApplicationTester
|
|||||||
$this->input->setInteractive($options['interactive']);
|
$this->input->setInteractive($options['interactive']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$shellInteractive = getenv('SHELL_INTERACTIVE');
|
|
||||||
|
|
||||||
if ($this->inputs) {
|
if ($this->inputs) {
|
||||||
$this->input->setStream(self::createStream($this->inputs));
|
$this->input->setStream(self::createStream($this->inputs));
|
||||||
putenv('SHELL_INTERACTIVE=1');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->initOutput($options);
|
$this->initOutput($options);
|
||||||
|
|
||||||
$this->statusCode = $this->application->run($this->input, $this->output);
|
return $this->statusCode = $this->application->run($this->input, $this->output);
|
||||||
|
|
||||||
putenv($shellInteractive ? "SHELL_INTERACTIVE=$shellInteractive" : 'SHELL_INTERACTIVE');
|
|
||||||
|
|
||||||
return $this->statusCode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
Reference in New Issue
Block a user