[FrameworkBundle] Move lint commands to lint namespace.

This commit is contained in:
Abdellatif Ait boudad 2015-03-30 20:06:15 +01:00
parent 4b19daf1b0
commit 8f72338513
5 changed files with 20 additions and 10 deletions

View File

@ -35,13 +35,13 @@ class LintCommand extends Command
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct($name = 'twig:lint') public function __construct($name = 'lint:twig')
{ {
parent::__construct($name); parent::__construct($name);
} }
/** /**
* Sets the twig environment * Sets the twig environment.
* *
* @param \Twig_Environment $twig * @param \Twig_Environment $twig
*/ */
@ -61,6 +61,7 @@ class LintCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setAliases(array('twig:lint'))
->setDescription('Lints a template and outputs encountered errors') ->setDescription('Lints a template and outputs encountered errors')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt') ->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
->addArgument('filename', InputArgument::IS_ARRAY) ->addArgument('filename', InputArgument::IS_ARRAY)
@ -87,6 +88,10 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
if (false !== strpos($input->getFirstArgument(), ':l')) {
$output->writeln('<comment>The use of "twig:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:twig" instead.</comment>');
}
$twig = $this->getTwigEnvironment(); $twig = $this->getTwigEnvironment();
if (null === $twig) { if (null === $twig) {
@ -99,7 +104,7 @@ EOF
if (0 === count($filenames)) { if (0 === count($filenames)) {
if (0 !== ftell(STDIN)) { if (0 !== ftell(STDIN)) {
throw new \RuntimeException("Please provide a filename or pipe template content to STDIN."); throw new \RuntimeException('Please provide a filename or pipe template content to STDIN.');
} }
$template = ''; $template = '';
@ -210,14 +215,14 @@ EOF
$line = $exception->getTemplateLine(); $line = $exception->getTemplateLine();
if ($file) { if ($file) {
$output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line)); $output->writeln(sprintf('<error>KO</error> in %s (line %s)', $file, $line));
} else { } else {
$output->writeln(sprintf("<error>KO</error> (line %s)", $line)); $output->writeln(sprintf('<error>KO</error> (line %s)', $line));
} }
foreach ($this->getContext($template, $line) as $no => $code) { foreach ($this->getContext($template, $line) as $no => $code) {
$output->writeln(sprintf( $output->writeln(sprintf(
"%s %-6s %s", '%s %-6s %s',
$no == $line ? '<error>>></error>' : ' ', $no == $line ? '<error>>></error>' : ' ',
$no, $no,
$code $code

View File

@ -80,7 +80,7 @@ class LintCommandTest extends \PHPUnit_Framework_TestCase
$application = new Application(); $application = new Application();
$application->add($command); $application->add($command);
$command = $application->find('twig:lint'); $command = $application->find('lint:twig');
return new CommandTester($command); return new CommandTester($command);
} }

View File

@ -33,7 +33,8 @@ class YamlLintCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('yaml:lint') ->setName('lint:yaml')
->setAliases(array('yaml:lint'))
->setDescription('Lints a file and outputs encountered errors') ->setDescription('Lints a file and outputs encountered errors')
->addArgument('filename', null, 'A file or a directory or STDIN') ->addArgument('filename', null, 'A file or a directory or STDIN')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt') ->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
@ -65,6 +66,10 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $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>');
}
$filename = $input->getArgument('filename'); $filename = $input->getArgument('filename');
if (!$filename) { if (!$filename) {

View File

@ -53,7 +53,7 @@
"symfony/finder": "For using the translation loader and cache warmer", "symfony/finder": "For using the translation loader and cache warmer",
"symfony/form": "For using forms", "symfony/form": "For using forms",
"symfony/validator": "For using validation", "symfony/validator": "For using validation",
"symfony/yaml": "For using the debug:config and yaml:lint commands", "symfony/yaml": "For using the debug:config and lint:yaml commands",
"doctrine/cache": "For using alternative cache drivers" "doctrine/cache": "For using alternative cache drivers"
}, },
"autoload": { "autoload": {

View File

@ -59,7 +59,7 @@ class LintCommand extends BaseLintCommand implements ContainerAwareInterface
Or all template files in a bundle: Or all template files in a bundle:
<info>php %command.full_name% @AcmeDemoBundle</info> <info>php %command.full_name% @AcmeDemoBundle</info>
EOF EOF
) )
; ;