drupal-console icon indicating copy to clipboard operation
drupal-console copied to clipboard

Provide --format=JSON for debug:container and other debug commands

Open amaisano opened this issue 3 years ago • 0 comments

Provide --format=JSON for debug:container and other debug commands

[ console ] The original symfony/console package allows output in JSON format.

Problem/Motivation

There are some extensions that rely on the output of drupal debug:container --format=JSON, which we currently cannot get with the drupal console. Parsing a JSON response is 10x easier than parsing multiline table output.

Details to include:

  • See above.

How to reproduce

drupal debug:container

Details to include:

  • Drupal version (you can obtain this by running drupal site:status). 8.8.8
  • Console version (you can obtain this by running composer show | grep drupal/console). 1.9
  • Console Launcher version (you can obtain this by running outside of a drupal site drupal --version).
  • Steps to reproduce
    • Create a new symfony/symfony-standard project
    • Run console debug:container --format=JSON
P2024440:my_project_name amaisano$ bin/console debug:container --format=json
{
    "definitions": {
        "AppBundle\\Controller\\DefaultController": {
            "class": "AppBundle\\Controller\\DefaultController",
            "public": true,
            "synthetic": false,
            "lazy": false,
            "shared": true,
            "abstract": false,
            "autowire": true,
            "autoconfigure": true,
            "file": null,
            "tags": [
                {
                    "name": "controller.service_arguments",
                    "parameters": []
                }
            ]
        },
        "Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController": {
            "class": "Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController",
            "public": true,
            "synthetic": false,
            "lazy": false,
            "shared": true,
            "abstract": false,
            "autowire": false,
            "autoconfigure": false,
            "file": null,
            "tags": []
        },
        "Symfony\\Bundle\\FrameworkBundle\\Controller\\TemplateController": {
            "class": "Symfony\\Bundle\\FrameworkBundle\\Controller\\TemplateController",
            "public": true,
            "synthetic": false,
            "lazy": false,
            "shared": true,
            "abstract": false,
            "autowire": false,
            "autoconfigure": false,
            "file": null,
            "tags": []
        },
        "abstract.instanceof.AppBundle\\Controller\\DefaultController": {
            "class": "AppBundle\\Controller\\DefaultController",
            "public": true,
            "synthetic": false,
            "lazy": false,
            "shared": true,
            "abstract": true,
            "autowire": true,
            "autoconfigure": true,
            "file": null,
            "tags": []
        },
        "cache.app": {
            "class": "Symfony\\Component\\Cache\\Adapter\\TraceableAdapter",
            "public": true,
            "synthetic": false,
            "lazy": false,
            "shared": true,
            "abstract": false,
            "autowire": false,
            "autoconfigure": false,
            "file": null,
            "tags": [
                {
                    "name": "cache.pool",
                    "parameters": []
                },
                {
                    "name": "kernel.reset",
                    "parameters": {
                        "method": "reset"
                    }
                }
            ]
        },

Solution

Use the same formatters the symfony/console project uses.

Details to include:

  • See https://github.com/symfony/console/blob/master/Descriptor/JsonDescriptor.php

amaisano avatar Jul 29 '20 19:07 amaisano