@@ -58,7 +58,8 @@ protected function configure()
58
58
->setDescription (self ::$ defaultDescription )
59
59
->addArgument ('filename ' , InputArgument::IS_ARRAY , 'A file, a directory or "-" for reading from STDIN ' )
60
60
->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 )
62
63
->setHelp (<<<EOF
63
64
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
64
65
the first encountered syntax error.
@@ -76,6 +77,10 @@ protected function configure()
76
77
<info>php %command.full_name% dirname</info>
77
78
<info>php %command.full_name% dirname --format=json</info>
78
79
80
+ You can also exclude one or more specific files:
81
+
82
+ <info>php %command.full_name% dirname --exclude="dirname/foo.yaml" --exclude="dirname/bar.yaml"</info>
83
+
79
84
EOF
80
85
)
81
86
;
@@ -85,7 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
85
90
{
86
91
$ io = new SymfonyStyle ($ input , $ output );
87
92
$ filenames = (array ) $ input ->getArgument ('filename ' );
93
+ $ excludes = $ input ->getOption ('exclude ' );
88
94
$ this ->format = $ input ->getOption ('format ' );
95
+ $ flags = $ input ->getOption ('parse-tags ' );
89
96
90
97
if ('github ' === $ this ->format && !class_exists (GithubActionReporter::class)) {
91
98
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)
96
103
$ this ->format = class_exists (GithubActionReporter::class) && GithubActionReporter::isGithubActionEnvironment () ? 'github ' : 'txt ' ;
97
104
}
98
105
106
+ $ flags = $ flags ? Yaml::PARSE_CUSTOM_TAGS : 0 ;
107
+
99
108
$ this ->displayCorrectFiles = $ output ->isVerbose ();
100
- $ flags = $ input ->getOption ('parse-tags ' ) ? Yaml::PARSE_CUSTOM_TAGS : 0 ;
101
109
102
110
if (['- ' ] === $ filenames ) {
103
111
return $ this ->display ($ io , [$ this ->validate (file_get_contents ('php://stdin ' ), $ flags )]);
@@ -114,7 +122,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
114
122
}
115
123
116
124
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
+ }
118
128
}
119
129
}
120
130
0 commit comments