@@ -52,6 +52,7 @@ protected function configure()
52
52
->setDescription ('Lints a file and outputs encountered errors ' )
53
53
->addArgument ('filename ' , null , 'A file or a directory or STDIN ' )
54
54
->addOption ('format ' , null , InputOption::VALUE_REQUIRED , 'The output format ' , 'txt ' )
55
+ ->addOption ('parse-tags ' , null , InputOption::VALUE_NONE , 'Parse custom tags ' )
55
56
->setHelp (<<<EOF
56
57
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
57
58
the first encountered syntax error.
@@ -80,13 +81,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
80
81
$ filename = $ input ->getArgument ('filename ' );
81
82
$ this ->format = $ input ->getOption ('format ' );
82
83
$ this ->displayCorrectFiles = $ output ->isVerbose ();
84
+ $ flags = $ input ->getOption ('parse-tags ' ) ? Yaml::PARSE_CUSTOM_TAGS : 0 ;
83
85
84
86
if (!$ filename ) {
85
87
if (!$ stdin = $ this ->getStdin ()) {
86
88
throw new \RuntimeException ('Please provide a filename or pipe file content to STDIN. ' );
87
89
}
88
90
89
- return $ this ->display ($ io , array ($ this ->validate ($ stdin )));
91
+ return $ this ->display ($ io , array ($ this ->validate ($ stdin, $ flags )));
90
92
}
91
93
92
94
if (!$ this ->isReadable ($ filename )) {
@@ -95,13 +97,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
95
97
96
98
$ filesInfo = array ();
97
99
foreach ($ this ->getFiles ($ filename ) as $ file ) {
98
- $ filesInfo [] = $ this ->validate (file_get_contents ($ file ), $ file );
100
+ $ filesInfo [] = $ this ->validate (file_get_contents ($ file ), $ flags , $ file );
99
101
}
100
102
101
103
return $ this ->display ($ io , $ filesInfo );
102
104
}
103
105
104
- private function validate ($ content , $ file = null )
106
+ private function validate ($ content , $ flags , $ file = null )
105
107
{
106
108
$ prevErrorHandler = set_error_handler (function ($ level , $ message , $ file , $ line ) use (&$ prevErrorHandler ) {
107
109
if (E_USER_DEPRECATED === $ level ) {
@@ -112,7 +114,7 @@ private function validate($content, $file = null)
112
114
});
113
115
114
116
try {
115
- $ this ->getParser ()->parse ($ content , Yaml::PARSE_CONSTANT );
117
+ $ this ->getParser ()->parse ($ content , Yaml::PARSE_CONSTANT | $ flags );
116
118
} catch (ParseException $ e ) {
117
119
return array ('file ' => $ file , 'valid ' => false , 'message ' => $ e ->getMessage ());
118
120
} finally {
0 commit comments