December 22, 2016 Javier Eguiluz

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 Twig 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<_locale>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 \C omponent \R outing \R outeCompiler</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: