Skip to content

Commit a636897

Browse files
committed
[Yaml] Add lint:yaml command usage
1 parent 463f9db commit a636897

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

components/yaml.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,52 @@ flag::
292292
// Multiple
293293
// Line
294294
// String
295+
Syntax Validation
296+
~~~~~~~~~~~~~~~~~
297+
298+
The syntax of YAML contents can be validated through the CLI using the
299+
:class:`Symfony\\Component\\Yaml\\Command\\LintCommand` command.
300+
301+
First, install the Console component:
302+
303+
.. code-block:: bash
304+
305+
$ composer require symfony/console
306+
307+
Create a script containing a console application:
308+
309+
.. code-block:: php
310+
311+
// lint.php
312+
313+
use Symfony\Component\Console\Application;
314+
use Symfony\Component\Yaml\Command\LintCommand;
315+
316+
(new Application('yaml/lint'))
317+
->add(new LintCommand())
318+
->getApplication()
319+
->setDefaultCommand('lint:yaml', true)
320+
->run();
321+
322+
Then, execute the script for validating contents:
323+
324+
.. code-block:: bash
325+
326+
# validates a single file
327+
$ php lint.php path/to/file.yml
328+
329+
# or all the files in a directory
330+
$ php lint.php path/to/directory
331+
332+
# or contents passed to STDIN
333+
$ cat path/to/file.yml | php lint.php
334+
335+
The result will be written on STDOUT, default in TXT format.
336+
For a JSON output, use the ``format`` option:
337+
338+
.. code-block:: bash
339+
340+
$ php lint.php path/to/file.yml --format json
295341
296342
Learn More
297343
----------

0 commit comments

Comments
 (0)