diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index e059740a1375d..d58cf38d87bc6 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -57,6 +57,7 @@ protected function configure() ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions()))) ->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors') ->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN') + ->addOption('excludes', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Excluded directory', []) ->setHelp(<<<'EOF' The %command.name% command lints a template and outputs to STDOUT the first encountered syntax error. @@ -84,6 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io = new SymfonyStyle($input, $output); $filenames = $input->getArgument('filename'); $showDeprecations = $input->getOption('show-deprecations'); + $excludes = $input->getOption('excludes'); $this->format = $input->getOption('format') ?? (GithubActionReporter::isGithubActionEnvironment() ? 'github' : 'txt'); if (['-'] === $filenames) { @@ -121,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } try { - $filesInfo = $this->getFilesInfo($filenames); + $filesInfo = $this->getFilesInfo($filenames, $excludes); } finally { if ($showDeprecations) { restore_error_handler(); @@ -131,11 +133,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return $this->display($input, $output, $io, $filesInfo); } - private function getFilesInfo(array $filenames): array + private function getFilesInfo(array $filenames, array $excludes): array { $filesInfo = []; foreach ($filenames as $filename) { - foreach ($this->findFiles($filename) as $file) { + foreach ($this->findFiles($filename, $excludes) as $file) { $filesInfo[] = $this->validate(file_get_contents($file), $file); } } @@ -143,12 +145,12 @@ private function getFilesInfo(array $filenames): array return $filesInfo; } - protected function findFiles(string $filename): iterable + protected function findFiles(string $filename, array $excludes): iterable { if (is_file($filename)) { return [$filename]; } elseif (is_dir($filename)) { - return Finder::create()->files()->in($filename)->name($this->namePatterns); + return Finder::create()->files()->in($filename)->name($this->namePatterns)->exclude($excludes); } throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));