From c4172ab0731f95cfedae838b7ddcfc0e43a53111 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 12 Sep 2016 22:49:01 +0200 Subject: [PATCH 1/3] Yaml] Add lint:yaml command usage --- components/yaml.rst | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/components/yaml.rst b/components/yaml.rst index e26f7c70736..ec8b750c4a8 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -293,6 +293,53 @@ flag:: // Line // String +Syntax Validation +~~~~~~~~~~~~~~~~~ + +The syntax of YAML contents can be validated through the CLI using the +:class:`Symfony\\Component\\Yaml\\Command\\LintCommand` command. + +First, install the Console component: + +.. code-block:: bash + + $ composer require symfony/console + +Create a console application with ``lint:yaml`` as its only command:: + +.. code-block:: php + + // lint.php + + use Symfony\Component\Console\Application; + use Symfony\Component\Yaml\Command\LintCommand; + + (new Application('yaml/lint')) + ->add(new LintCommand()) + ->getApplication() + ->setDefaultCommand('lint:yaml', true) + ->run(); + +Then, execute the script for validating contents: + +.. code-block:: bash + + # validates a single file + $ php lint.php path/to/file.yml + + # or all the files in a directory + $ php lint.php path/to/directory + + # or contents passed to STDIN + $ cat path/to/file.yml | php lint.php + +The result is written to STDOUT and uses a plain text format by default. +Add the ``--format`` option to get the output in JSON format: + +.. code-block:: bash + + $ php lint.php path/to/file.yml --format json + Learn More ---------- From 2999306f4a6e20a0ca4a2a0c908bbc012a1a3a58 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 22 Nov 2016 09:47:25 +0100 Subject: [PATCH 2/3] Use `terminal` instead of `bash` for console code --- components/yaml.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/yaml.rst b/components/yaml.rst index ec8b750c4a8..1f468d29a1e 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -301,7 +301,7 @@ The syntax of YAML contents can be validated through the CLI using the First, install the Console component: -.. code-block:: bash +.. code-block:: terminal $ composer require symfony/console @@ -322,7 +322,7 @@ Create a console application with ``lint:yaml`` as its only command:: Then, execute the script for validating contents: -.. code-block:: bash +.. code-block:: terminal # validates a single file $ php lint.php path/to/file.yml @@ -336,7 +336,7 @@ Then, execute the script for validating contents: The result is written to STDOUT and uses a plain text format by default. Add the ``--format`` option to get the output in JSON format: -.. code-block:: bash +.. code-block:: terminal $ php lint.php path/to/file.yml --format json From b06735287dc3ab8939b18da4183ad13fbbef276f Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 22 Nov 2016 09:48:10 +0100 Subject: [PATCH 3/3] Remove an unneeded code directive --- components/yaml.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/yaml.rst b/components/yaml.rst index 1f468d29a1e..a04ad7afe35 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -307,8 +307,6 @@ First, install the Console component: Create a console application with ``lint:yaml`` as its only command:: -.. code-block:: php - // lint.php use Symfony\Component\Console\Application;