diff --git a/composer.json b/composer.json index 1dec2fd..7a36fbe 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "symfony/yaml": "^4 | ^5", "symfony/console": "^4 | ^5", "symfony/filesystem": "^4 | ^5", + "symfony/finder": "^4 | ^5", "dflydev/dot-access-data": "^1.1.0" }, "license": "MIT", diff --git a/composer.lock b/composer.lock index 9a4e676..969c56c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1f123a5a1e0ac60f3ff0af3e3bea94d7", + "content-hash": "a95010d0c1a48b4cc020b7c672912a74", "packages": [ { "name": "dflydev/dot-access-data", @@ -240,6 +240,55 @@ "homepage": "https://symfony.com", "time": "2020-01-21T08:40:24+00:00" }, + { + "name": "symfony/finder", + "version": "v5.0.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "600a52c29afc0d1caa74acbec8d3095ca7e9910d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/600a52c29afc0d1caa74acbec8d3095ca7e9910d", + "reference": "600a52c29afc0d1caa74acbec8d3095ca7e9910d", + "shasum": "" + }, + "require": { + "php": "^7.2.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2020-03-27T16:56:45+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.14.0", diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php index a77136c..4e1ff4c 100644 --- a/src/Command/LintCommand.php +++ b/src/Command/LintCommand.php @@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Finder\Finder; use Symfony\Component\Yaml\Yaml; /** @@ -23,11 +24,11 @@ protected function configure() $this ->setName('lint') ->setDescription('Validates that a given YAML file has valid syntax.') - ->addUsage("path/to/file.yml") + ->addUsage('path/to/file.yml') ->addArgument( - 'filename', + 'path', InputArgument::REQUIRED, - "The filename of the YAML file" + 'The path or directory of the YAML file' ); } @@ -39,15 +40,37 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $filename = $input->getArgument('filename'); - $yaml_parsed = $this->loadYamlFile($filename); + $path = $input->getArgument('path'); + $yaml_parsed = $this->loadYamlFile($path); if (!$yaml_parsed) { // Exit with a status of 1. return 1; } + if (is_dir($path)) { + $finder = new Finder(); + $finder->files()->in($path); + foreach ($finder as $file) { + $yaml_parsed = $this->loadYamlFile($file->getRealPath()); + if (!$yaml_parsed) { + // Exit with a status of 1. + return 1; + } + } + } else { + $yaml_parsed = $this->loadYamlFile($path); + if (!$yaml_parsed) { + // Exit with a status of 1. + return 1; + } + } + if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { - $output->writeln("The file $filename contains valid YAML."); + if (is_dir($path)) { + $output->writeln("The directory $path contains valid YAML."); + } else { + $output->writeln("The file $path contains valid YAML."); + } } return 0; diff --git a/tests/phpunit/LintCommandTest.php b/tests/phpunit/LintCommandTest.php index 79e7556..057d904 100644 --- a/tests/phpunit/LintCommandTest.php +++ b/tests/phpunit/LintCommandTest.php @@ -24,7 +24,7 @@ public function testLint($file, $expected_output, $expected_exit_code) $commandTester = new CommandTester($command); $commandTester->execute(array( 'command' => $command->getName(), - 'filename' => $file + 'path' => $file ), ['verbosity' => Output::VERBOSITY_VERBOSE]); $output = $commandTester->getDisplay();