Symfony News

New in Symfony 3.3: Improved command descriptors

Roland Franssen

Contributed by
Roland Franssen
in #20866 and #20867.

One of the most unknown features of the Symfony Console commands is that they can provide alternative output formats, such as XML, JSON, Markdown, etc. For example, to get the YAML lint results in JSON format:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ ./bin/console lint:twig app/Resources/ --format=json

[
    {
        "file": "app/Resources/views/base.html.twig",
        "valid": true
    },
    {
        "file": "app/Resources/views/blog/index.html.twig",
        "valid": true
    },
    ...
]

You can also get for example the information about any route in XML format:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$ ./bin/console debug:router homepage --format=xml

<?xml version="1.0" encoding="UTF-8"?>
<route name="homepage" class="Symfony\Component\Routing\Route">
  <path regex="#^/(?P&lt;_locale&gt;en|fr|de|es|cs|nl|ru|uk|ro|pt_BR|pl|it|ja|id|ca|sl)?$#s">/{_locale}</path>
  <defaults>
    <default key="_controller">FrameworkBundle:Template:template</default>
    <default key="template">default/homepage.html.twig</default>
    <default key="_locale">en</default>
  </defaults>
  <requirements>
    <requirement key="_locale">en|fr|de|es|cs|nl|ru|uk|ro|pt_BR|pl|it|ja|id|ca|sl</requirement>
  </requirements>
  <options>
    <option key="compiler_class">Symfony\Component\Routing\RouteCompiler</option>
  </options>
</route>

In Symfony 3.3 we improved some of these command descriptors. For example, when using JSON to describe an application, you'll now get the full name and version of the application:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{
    "application": {
        "name": "My Symfony application",
        "version": "v1.0"
    },
    "commands": [
        {
            "name": "help",
            "usage": [
                "help [--format FORMAT] [--raw] [--] [<command_name>]"
            ]
        },
        ...
    ]
}

In addition, when using Markdown as the output format, the contents will be formatted much better.

Before:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
UNKNOWN
=======

* help
* list

help
----

* Description: Displays help for a command
* Usage:

  * `help [--format FORMAT] [--raw] [--] [<command_name>]`

...

After:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Console Tool
============

* `help`
* `list`

`help`
------

Displays help for a command

### Usage

* `help [--format FORMAT] [--raw] [--] [<command_name>]`

Be trained by Symfony experts - 2017-01-09 Paris - 2017-01-09 Paris - 2017-01-11 Paris


About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Resources

Find us on Twitter

Find us on Facebook