Skip to content

Commit 6b1d00b

Browse files
committed
deprecated not passing dash symbol (-) to STDIN commands
1 parent 3ef0425 commit 6b1d00b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* Added support to dump `null` as `~` by using the `Yaml::DUMP_NULL_AS_TILDE` flag.
8+
* deprecated accepting STDIN implicitly when using the `lint:yaml` command, use `lint:yaml -` (append a dash) instead to make it explicit.
89

910
4.3.0
1011
-----

Command/LintCommand.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function configure()
5454
{
5555
$this
5656
->setDescription('Lints a file and outputs encountered errors')
57-
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
57+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
5858
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5959
->addOption('parse-tags', null, InputOption::VALUE_NONE, 'Parse custom tags')
6060
->setHelp(<<<EOF
@@ -86,13 +86,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686
$this->format = $input->getOption('format');
8787
$this->displayCorrectFiles = $output->isVerbose();
8888
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
89+
$hasStdin = '-' === ($filenames[0] ?? '');
8990

90-
if (0 === \count($filenames)) {
91-
if (!$stdin = $this->getStdin()) {
91+
if ($hasStdin || 0 === \count($filenames)) {
92+
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
9293
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9394
}
9495

95-
return $this->display($io, [$this->validate($stdin, $flags)]);
96+
if (!$hasStdin) {
97+
@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);
98+
}
99+
100+
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
96101
}
97102

98103
$filesInfo = [];
@@ -199,18 +204,14 @@ private function getFiles(string $fileOrDirectory)
199204
}
200205
}
201206

202-
private function getStdin(): ?string
207+
private function getStdin(): string
203208
{
204-
if (0 !== ftell(STDIN)) {
205-
return null;
206-
}
207-
208-
$inputs = '';
209+
$yaml = '';
209210
while (!feof(STDIN)) {
210-
$inputs .= fread(STDIN, 1024);
211+
$yaml .= fread(STDIN, 1024);
211212
}
212213

213-
return $inputs;
214+
return $yaml;
214215
}
215216

216217
private function getParser()

0 commit comments

Comments
 (0)