From 0636b4c672542e35c2d0ec77fabcca7cf6f0e9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Tue, 12 Nov 2019 22:43:16 +0100 Subject: [PATCH] [Yaml] Introduce yaml-lint binary --- src/Symfony/Component/Yaml/CHANGELOG.md | 5 ++ .../Component/Yaml/Resources/bin/yaml-lint | 55 +++++++++++++++++++ src/Symfony/Component/Yaml/composer.json | 3 + 3 files changed, 63 insertions(+) create mode 100755 src/Symfony/Component/Yaml/Resources/bin/yaml-lint diff --git a/src/Symfony/Component/Yaml/CHANGELOG.md b/src/Symfony/Component/Yaml/CHANGELOG.md index a3a7270166584..c7150badb07c3 100644 --- a/src/Symfony/Component/Yaml/CHANGELOG.md +++ b/src/Symfony/Component/Yaml/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.1.0 +----- + + * Added `yaml-lint` binary. + 5.0.0 ----- diff --git a/src/Symfony/Component/Yaml/Resources/bin/yaml-lint b/src/Symfony/Component/Yaml/Resources/bin/yaml-lint new file mode 100755 index 0000000000000..5020add6c9cb7 --- /dev/null +++ b/src/Symfony/Component/Yaml/Resources/bin/yaml-lint @@ -0,0 +1,55 @@ +#!/usr/bin/env php + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Runs the Yaml lint command. + * + * @author Jan Schädlich + */ + +use Psr\Log\LoggerInterface; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Logger\ConsoleLogger; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Yaml\Command\LintCommand; + +function includeIfExists(string $file): bool +{ + return file_exists($file) && include $file; +} + +if ( + !includeIfExists(__DIR__ . '/../../../../autoload.php') && + !includeIfExists(__DIR__ . '/../../vendor/autoload.php') && + !includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php') +) { + fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL); + exit(1); +} + +if (!class_exists(Application::class)) { + fwrite(STDERR, 'You need the "symfony/console" component in order to run the Yaml linter.'.PHP_EOL); + exit(1); +} + +$input = new ArgvInput(); +$output = new ConsoleOutput(); +$logger = interface_exists(LoggerInterface::class) ? new ConsoleLogger($output->getErrorOutput()) : null; + +$app = new Application(); + +$app->add($command = new LintCommand()) + ->getApplication() + ->setDefaultCommand($command->getName(), true) + ->run($input, $output) +; diff --git a/src/Symfony/Component/Yaml/composer.json b/src/Symfony/Component/Yaml/composer.json index 6a32ba97a215e..f28d00c84f2fe 100644 --- a/src/Symfony/Component/Yaml/composer.json +++ b/src/Symfony/Component/Yaml/composer.json @@ -34,6 +34,9 @@ "/Tests/" ] }, + "bin": [ + "Resources/bin/yaml-lint" + ], "minimum-stability": "dev", "extra": { "branch-alias": {