8000 [Yaml] Added support for multiple files or directories in LintCommand · symfony/symfony@d0f7950 · GitHub
[go: up one dir, main page]

Skip to content

Commit d0f7950

Browse files
ycerutonicolas-grekas
authored andcommitted
[Yaml] Added support for multiple files or directories in LintCommand
1 parent 00e5cd9 commit d0f7950

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* added support for multiple files or directories in `LintCommand`
8+
49
4.0.0
510
-----
611

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Command\Command;
1515
use Symfony\Component\Console\Exception\InvalidArgumentException;
1616
use Symfony\Component\Console\Exception\RuntimeException;
17+
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Input\InputOption;
1920
use Symfony\Component\Console\Output\OutputInterface;
@@ -53,7 +54,7 @@ protected function configure()
5354
{
5455
$this
5556
->setDescription('Lints a file and outputs encountered errors')
56-
->addArgument('filename', null, 'A file or a directory or STDIN')
57+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
5758
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5859
->addOption('parse-tags', null, InputOption::VALUE_NONE, 'Parse custom tags')
5960
->setHelp(<<<EOF
@@ -81,26 +82,28 @@ protected function configure()
8182
protected function execute(InputInterface $input, OutputInterface $output)
8283
{
8384
$io = new SymfonyStyle($input, $output);
84-
$filename = $input->getArgument('filename');
85+
$filenames = (array) $input->getArgument('filename');
8586
$this->format = $input->getOption('format');
8687
$this->displayCorrectFiles = $output->isVerbose();
8788
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
8889

89-
if (!$filename) {
90+
if (0 === \count($filenames)) {
9091
if (!$stdin = $this->getStdin()) {
9192
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9293
}
9394

9495
return $this->display($io, array($this->validate($stdin, $flags)));
9596
}
9697

97-
if (!$this->isReadable($filename)) {
98-
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
99-
}
100-
10198
$filesInfo = array();
102-
foreach ($this->getFiles($filename) as $file) {
103-
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
99+
foreach ($filenames as $filename) {
100+
if (!$this->isReadable($filename)) {
101+
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
102+
}
103+
104+
foreach ($this->getFiles($filename) as $file) {
105+
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
106+
}
104107
}
105108

106109
return $this->display($io, $filesInfo);

src/Symfony/Component/Yaml/Tests/Command/LintCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public function testLintCorrectFile()
3737
$this->assertRegExp('/^\/\/ OK in /', trim($tester->getDisplay()));
3838
}
3939

40+
public function testLintCorrectFiles()
41+
{
42+
$tester = $this->createCommandTester();
43+
$filename1 = $this->createFile('foo: bar');
44+
$filename2 = $this->createFile('bar: baz');
45+
46+
$ret = $tester->execute(array('filename' => array($filename1, $filename2)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
47+
48+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
49+
$this->assertRegExp('/^\/\/ OK in /', trim($tester->getDisplay()));
50+
}
51+
4052
public function testLintIncorrectFile()
4153
{
4254
$incorrectContent = '

0 commit comments

Comments
 (0)
0