Skip to content

Commit 5c98802

Browse files
94nonifabpot
authored andcommitted
[TwigBridge] Allow twig:lint to excludes dirs
1 parent a1bf369 commit 5c98802

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Command/LintCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected function configure()
5757
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
5858
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
5959
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
60+
->addOption('excludes', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Excluded directory', [])
6061
->setHelp(<<<'EOF'
6162
The <info>%command.name%</info> command lints a template and outputs to STDOUT
6263
the first encountered syntax error.
@@ -84,6 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8485
$io = new SymfonyStyle($input, $output);
8586
$filenames = $input->getArgument('filename');
8687
$showDeprecations = $input->getOption('show-deprecations');
88+
$excludes = $input->getOption('excludes');
8789
$this->format = $input->getOption('format') ?? (GithubActionReporter::isGithubActionEnvironment() ? 'github' : 'txt');
8890

8991
if (['-'] === $filenames) {
@@ -121,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
121123
}
122124

123125
try {
124-
$filesInfo = $this->getFilesInfo($filenames);
126+
$filesInfo = $this->getFilesInfo($filenames, $excludes);
125127
} finally {
126128
if ($showDeprecations) {
127129
restore_error_handler();
@@ -131,24 +133,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131133
return $this->display($input, $output, $io, $filesInfo);
132134
}
133135

134-
private function getFilesInfo(array $filenames): array
136+
private function getFilesInfo(array $filenames, array $excludes): array
135137
{
136138
$filesInfo = [];
137139
foreach ($filenames as $filename) {
138-
foreach ($this->findFiles($filename) as $file) {
140+
foreach ($this->findFiles($filename, $excludes) as $file) {
139141
$filesInfo[] = $this->validate(file_get_contents($file), $file);
140142
}
141143
}
142144

143145
return $filesInfo;
144146
}
145147

146-
protected function findFiles(string $filename): iterable
148+
protected function findFiles(string $filename, array $excludes): iterable
147149
{
148150
if (is_file($filename)) {
149151
return [$filename];
150152
} elseif (is_dir($filename)) {
151-
return Finder::create()->files()->in($filename)->name($this->namePatterns);
153+
return Finder::create()->files()->in($filename)->name($this->namePatterns)->exclude($excludes);
152154
}
153155

154156
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));

0 commit comments

Comments
 (0)