Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
51 changes: 50 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions src/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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'
);
}

Expand All @@ -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("<info>The file $filename contains valid YAML.</info>");
if (is_dir($path)) {
$output->writeln("<info>The directory $path contains valid YAML.</info>");
} else {
$output->writeln("<info>The file $path contains valid YAML.</info>");
}
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down