@@ -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