Permalink
Browse files

Updated the stlyes of the YAML commands

  • Loading branch information...
javiereguiluz authored and fabpot committed Sep 29, 2015
1 parent b630972 commit c3ce7ca14121168865588f4879c44a2e939feb26
@@ -15,6 +15,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
@@ -62,8 +63,10 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$stdout = $output;
$output = new SymfonyStyle($input, $output);
if (false !== strpos($input->getFirstArgument(), ':l')) {
$output->writeln('<comment>The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.</comment>');
$output->caution('The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.');
}
$filename = $input->getArgument('filename');
@@ -78,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$content .= fread(STDIN, 1024);
}
return $this->display($input, $output, array($this->validate($content)));
return $this->display($input, $stdout, $output, array($this->validate($content)));
}
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
@@ -100,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filesInfo[] = $this->validate(file_get_contents($file), $file);
}
return $this->display($input, $output, $filesInfo);
return $this->display($input, $stdout, $output, $filesInfo);
}
private function validate($content, $file = null)
@@ -115,33 +118,37 @@ private function validate($content, $file = null)
return array('file' => $file, 'valid' => true);
}
private function display(InputInterface $input, OutputInterface $output, $files)
private function display(InputInterface $input, OutputInterface $stdout, $output, $files)
{
switch ($input->getOption('format')) {
case 'txt':
return $this->displayTxt($output, $files);
return $this->displayTxt($stdout, $output, $files);
case 'json':
return $this->displayJson($output, $files);
default:
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
}
}
private function displayTxt(OutputInterface $output, $filesInfo)
private function displayTxt(OutputInterface $stdout, $output, $filesInfo)
{
$errors = 0;
foreach ($filesInfo as $info) {
if ($info['valid'] && $output->isVerbose()) {
$output->writeln('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
if ($info['valid'] && $stdout->isVerbose()) {
$output->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
} elseif (!$info['valid']) {
++$errors;
$output->writeln(sprintf('<error>KO</error> in %s', $info['file']));
$output->writeln(sprintf('<error>>> %s</error>', $info['message']));
$output->text(sprintf('<error> ERROR </error> in %s', $info['file']));
$output->text(sprintf('<error> >> %s</error>', $info['message']));
}
}
$output->writeln(sprintf('<comment>%d/%d valid files</comment>', count($filesInfo) - $errors, count($filesInfo)));
if ($errors === 0) {
$output->success(sprintf('All %d YAML files contain valid syntax.', count($filesInfo)));
} else {
$output->warning(sprintf('%d YAML files have valid syntax and %d contain errors.', count($filesInfo) - $errors, $errors));
}
return min($errors, 1);
}
@@ -25,8 +25,7 @@ public function testDebugAllRoutes()
$ret = $tester->execute(array('name' => null), array('decorated' => false));
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains('Path', $tester->getDisplay());
$this->assertContains('/foo', $tester->getDisplay());
$this->assertContains('Name Method Scheme Host Path', $tester->getDisplay());
}
public function testDebugSingleRoute()

0 comments on commit c3ce7ca

Please sign in to comment.