Fix lint commands frozen on empty stdin
This commit is contained in:
parent
74d5fa62ce
commit
b60e0c1454
@ -57,7 +57,7 @@ the first encountered syntax error.
|
|||||||
|
|
||||||
You can validate the syntax of contents passed from STDIN:
|
You can validate the syntax of contents passed from STDIN:
|
||||||
|
|
||||||
<info>cat filename | php %command.full_name%</info>
|
<info>cat filename | php %command.full_name% -</info>
|
||||||
|
|
||||||
Or the syntax of a file:
|
Or the syntax of a file:
|
||||||
|
|
||||||
@ -77,13 +77,15 @@ EOF
|
|||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$filenames = $input->getArgument('filename');
|
$filenames = $input->getArgument('filename');
|
||||||
$hasStdin = ['-'] === $filenames;
|
|
||||||
|
|
||||||
if ($hasStdin || !$filenames) {
|
if (['-'] === $filenames) {
|
||||||
if ($hasStdin || 0 === ftell(STDIN)) { // remove 0 === ftell(STDIN) check in 5.0
|
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
|
||||||
if (!$hasStdin) {
|
}
|
||||||
@trigger_error('Calling to the "lint:twig" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
|
|
||||||
}
|
if (!$filenames) {
|
||||||
|
// @deprecated to be removed in 5.0
|
||||||
|
if (0 === ftell(STDIN)) {
|
||||||
|
@trigger_error('Piping content from STDIN to the "lint:twig" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
|
||||||
|
|
||||||
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
|
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
|
||||||
}
|
}
|
||||||
@ -97,7 +99,7 @@ EOF
|
|||||||
$filenames = array_merge(...$paths);
|
$filenames = array_merge(...$paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === \count($filenames)) {
|
if (!$filenames) {
|
||||||
throw new RuntimeException('Please provide a filename or pipe template content to STDIN.');
|
throw new RuntimeException('Please provide a filename or pipe template content to STDIN.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,29 +35,12 @@ class XliffLintCommandTest extends TestCase
|
|||||||
{
|
{
|
||||||
$command = new XliffLintCommand();
|
$command = new XliffLintCommand();
|
||||||
$expected = <<<EOF
|
$expected = <<<EOF
|
||||||
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
|
|
||||||
the first encountered syntax error.
|
|
||||||
|
|
||||||
You can validates XLIFF contents passed from STDIN:
|
|
||||||
|
|
||||||
<info>cat filename | php %command.full_name%</info>
|
|
||||||
|
|
||||||
You can also validate the syntax of a file:
|
|
||||||
|
|
||||||
<info>php %command.full_name% filename</info>
|
|
||||||
|
|
||||||
Or of a whole directory:
|
|
||||||
|
|
||||||
<info>php %command.full_name% dirname</info>
|
|
||||||
<info>php %command.full_name% dirname --format=json</info>
|
|
||||||
|
|
||||||
Or find all files in a bundle:
|
Or find all files in a bundle:
|
||||||
|
|
||||||
<info>php %command.full_name% @AcmeDemoBundle</info>
|
<info>php %command.full_name% @AcmeDemoBundle</info>
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
$this->assertEquals($expected, $command->getHelp());
|
$this->assertStringContainsString($expected, $command->getHelp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLintFilesFromBundleDirectory()
|
public function testLintFilesFromBundleDirectory()
|
||||||
|
@ -72,29 +72,12 @@ bar';
|
|||||||
{
|
{
|
||||||
$command = new YamlLintCommand();
|
$command = new YamlLintCommand();
|
||||||
$expected = <<<EOF
|
$expected = <<<EOF
|
||||||
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
|
|
||||||
the first encountered syntax error.
|
|
||||||
|
|
||||||
You can validates YAML contents passed from STDIN:
|
|
||||||
|
|
||||||
<info>cat filename | php %command.full_name%</info>
|
|
||||||
|
|
||||||
You can also validate the syntax of a file:
|
|
||||||
|
|
||||||
<info>php %command.full_name% filename</info>
|
|
||||||
|
|
||||||
Or of a whole directory:
|
|
||||||
|
|
||||||
<info>php %command.full_name% dirname</info>
|
|
||||||
<info>php %command.full_name% dirname --format=json</info>
|
|
||||||
|
|
||||||
Or find all files in a bundle:
|
Or find all files in a bundle:
|
||||||
|
|
||||||
<info>php %command.full_name% @AcmeDemoBundle</info>
|
<info>php %command.full_name% @AcmeDemoBundle</info>
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
$this->assertEquals($expected, $command->getHelp());
|
$this->assertStringContainsString($expected, $command->getHelp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLintFilesFromBundleDirectory()
|
public function testLintFilesFromBundleDirectory()
|
||||||
|
@ -61,7 +61,7 @@ the first encountered syntax error.
|
|||||||
|
|
||||||
You can validates XLIFF contents passed from STDIN:
|
You can validates XLIFF contents passed from STDIN:
|
||||||
|
|
||||||
<info>cat filename | php %command.full_name%</info>
|
<info>cat filename | php %command.full_name% -</info>
|
||||||
|
|
||||||
You can also validate the syntax of a file:
|
You can also validate the syntax of a file:
|
||||||
|
|
||||||
@ -83,16 +83,18 @@ EOF
|
|||||||
$filenames = (array) $input->getArgument('filename');
|
$filenames = (array) $input->getArgument('filename');
|
||||||
$this->format = $input->getOption('format');
|
$this->format = $input->getOption('format');
|
||||||
$this->displayCorrectFiles = $output->isVerbose();
|
$this->displayCorrectFiles = $output->isVerbose();
|
||||||
$hasStdin = ['-'] === $filenames;
|
|
||||||
|
|
||||||
if ($hasStdin || !$filenames) {
|
if (['-'] === $filenames) {
|
||||||
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
|
return $this->display($io, [$this->validate($this->getStdin())]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @deprecated to be removed in 5.0
|
||||||
|
if (!$filenames) {
|
||||||
|
if (0 !== ftell(STDIN)) {
|
||||||
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$hasStdin) {
|
@trigger_error('Piping content from STDIN to the "lint:xliff" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
|
||||||
@trigger_error('Calling to the "lint:xliff" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->display($io, [$this->validate($this->getStdin())]);
|
return $this->display($io, [$this->validate($this->getStdin())]);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ the first encountered syntax error.
|
|||||||
|
|
||||||
You can validates XLIFF contents passed from STDIN:
|
You can validates XLIFF contents passed from STDIN:
|
||||||
|
|
||||||
<info>cat filename | php %command.full_name%</info>
|
<info>cat filename | php %command.full_name% -</info>
|
||||||
|
|
||||||
You can also validate the syntax of a file:
|
You can also validate the syntax of a file:
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ the first encountered syntax error.
|
|||||||
|
|
||||||
You can validates YAML contents passed from STDIN:
|
You can validates YAML contents passed from STDIN:
|
||||||
|
|
||||||
<info>cat filename | php %command.full_name%</info>
|
<info>cat filename | php %command.full_name% -</info>
|
||||||
|
|
||||||
You can also validate the syntax of a file:
|
You can also validate the syntax of a file:
|
||||||
|
|
||||||
@ -86,20 +86,22 @@ EOF
|
|||||||
$this->format = $input->getOption('format');
|
$this->format = $input->getOption('format');
|
||||||
$this->displayCorrectFiles = $output->isVerbose();
|
$this->displayCorrectFiles = $output->isVerbose();
|
||||||
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
|
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
|
||||||
$hasStdin = ['-'] === $filenames;
|
|
||||||
|
|
||||||
if ($hasStdin || !$filenames) {
|
|
||||||
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
|
|
||||||
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$hasStdin) {
|
|
||||||
@trigger_error('Calling to the "lint:yaml" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (['-'] === $filenames) {
|
||||||
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
|
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @deprecated to be removed in 5.0
|
||||||
|
if (!$filenames) {
|
||||||
|
if (0 === ftell(STDIN)) {
|
||||||
|
@trigger_error('Piping content from STDIN to the "lint:yaml" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
||||||
|
}
|
||||||
|
|
||||||
$filesInfo = [];
|
$filesInfo = [];
|
||||||
foreach ($filenames as $filename) {
|
foreach ($filenames as $filename) {
|
||||||
if (!$this->isReadable($filename)) {
|
if (!$this->isReadable($filename)) {
|
||||||
|
Reference in New Issue
Block a user