@@ -58,7 +58,8 @@ protected function configure()
5858 ->setDescription (self ::$ defaultDescription )
5959 ->addArgument ('filename ' , InputArgument::IS_ARRAY , 'A file, a directory or "-" for reading from STDIN ' )
6060 ->addOption ('format ' , null , InputOption::VALUE_REQUIRED , 'The output format ' )
61- ->addOption ('parse-tags ' , null , InputOption::VALUE_NONE , 'Parse custom tags ' )
61+ ->addOption ('exclude ' , 'e ' , InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY , 'Path(s) to exclude ' )
62+ ->addOption ('parse-tags ' , null , InputOption::VALUE_NEGATABLE , 'Parse custom tags ' , null )
6263 ->setHelp (<<<EOF
6364The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
6465the first encountered syntax error.
@@ -76,6 +77,10 @@ protected function configure()
7677 <info>php %command.full_name% dirname</info>
7778 <info>php %command.full_name% dirname --format=json</info>
7879
80+ You can also exclude one or more specific files:
81+
82+ <info>php %command.full_name% dirname --exclude="dirname/foo.yml" --exclude="dirname/bar.yml"</info>
83+
7984EOF
8085 )
8186 ;
@@ -85,7 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8590 {
8691 $ io = new SymfonyStyle ($ input , $ output );
8792 $ filenames = (array ) $ input ->getArgument ('filename ' );
93+ $ excludes = $ input ->getOption ('exclude ' );
8894 $ this ->format = $ input ->getOption ('format ' );
95+ $ flags = $ input ->getOption ('parse-tags ' );
8996
9097 if ('github ' === $ this ->format && !class_exists (GithubActionReporter::class)) {
9198 throw new \InvalidArgumentException ('The "github" format is only available since "symfony/console" >= 5.3. ' );
@@ -96,8 +103,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
96103 $ this ->format = class_exists (GithubActionReporter::class) && GithubActionReporter::isGithubActionEnvironment () ? 'github ' : 'txt ' ;
97104 }
98105
106+ $ flags = $ flags ? Yaml::PARSE_CUSTOM_TAGS : 0 ;
107+
99108 $ this ->displayCorrectFiles = $ output ->isVerbose ();
100- $ flags = $ input ->getOption ('parse-tags ' ) ? Yaml::PARSE_CUSTOM_TAGS : 0 ;
101109
102110 if (['- ' ] === $ filenames ) {
103111 return $ this ->display ($ io , [$ this ->validate (file_get_contents ('php://stdin ' ), $ flags )]);
@@ -114,7 +122,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
114122 }
115123
116124 foreach ($ this ->getFiles ($ filename ) as $ file ) {
117- $ filesInfo [] = $ this ->validate (file_get_contents ($ file ), $ flags , $ file );
125+ if (!\in_array ($ file ->getPathname (), $ excludes , true )) {
126+ $ filesInfo [] = $ this ->validate (file_get_contents ($ file ), $ flags , $ file );
127+ }
118128 }
119129 }
120130
0 commit comments