From 2640dfedfa3a7ec84f5a1660a9b5cc9530452b60 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 | 49 +++++++++++++++++++ src/Symfony/Component/Yaml/composer.json | 3 ++ 3 files changed, 57 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 a3a727016658..c7150badb07c 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 000000000000..0c6497cfbdfb --- /dev/null +++ b/src/Symfony/Component/Yaml/Resources/bin/yaml-lint @@ -0,0 +1,49 @@ +#!/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); +} + +(new Application())->add($command = new LintCommand()) + ->getApplication() + ->setDefaultCommand($command->getName(), true) + ->run() +; diff --git a/src/Symfony/Component/Yaml/composer.json b/src/Symfony/Component/Yaml/composer.json index eb2957ca8588..7d22e7923374 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": {