hechoendrupal / drupal-console

The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
http://drupalconsole.com
GNU General Public License v2.0
938 stars 557 forks source link

Support multiple output formats #3268

Open nvaken opened 7 years ago

nvaken commented 7 years ago

Currently, processing any data from the output of DC is a cumbersome task. Nothing is formatted in a decent way, except for human reading. I'd expect a --format flag in which you're able to define which output format you're expecting.

For example, running site:debug could look like following:

$ drupal site:debug --format=json site_name
{
    "root": "/var/www/html/site.ext/",
    "user": "foobar",
        "host": "site.ext"
}

Or:

$ drupal site:debug --format=yaml site_name
---
root: /var/www/html/site.ext/
user: foobar
host: site.ext

Of course, this should not be limited to site:debug and I think this should be a global flag. Though, this might have a lot of implications for the global structure of DC? Not sure.

Suggested formats

jmolivas commented 7 years ago

@nvaken We implemented something like this on the site:status command

> drupal site:status --format=json

{
    "system": {
        "Drupal": "8.3.0",
        "Access to update.php": "Protected",
        "Configuration files": "Protected",
        "Cron maintenance tasks": "Last run 18 hours 6 minutes ago",
        "Database system": "MySQL, MariaDB, Percona Server, or equivalent",
        "Database system version": "5.7.16",
        "Database updates": "Up to date",
        "Drupal core update status": "Up to date",
        "Entity\/field definitions": "Up to date",
        "File system": "Writable (public download method)",
        "GD library": "bundled (2.1.0 compatible)",
        "GD library PNG support": "bundled (2.1.0 compatible)",
        "Image toolkit": "gd",
        "Node Access Permissions": "Disabled",
        "PHP": "5.6.29 (more information)",
        "PHP extensions": "Enabled",
        "PHP memory limit": "2048M",
        "PHP OPcode caching": "Not enabled",
        "Random number generation": "Successful",
        "Search index progress": "100% (0 remaining)",
        "Trusted Host Settings": "Not enabled",
        "Unicode library": "PHP Mbstring Extension",
        "Update notifications": "Enabled",
        "Upload progress": "Not enabled",
        "Web server": "",
        "Hash salt": "zbwXd94_PJlSKxYg0zE73pwqZ4lzHPq1cKYdt_vB8Fsj4BKYSKfu-MZgJOw0m4zjK23yJ8GwSg",
        "Drupal Console": "1.0.0-rc16"
    },
    "database": {
        "Driver": "mysql",
        "Host": "127.0.0.1",
        "Database connection": "drupal",
        "Port": "3306",
        "Username": "root",
        "Connection": "mysql\/\/root:root@127.0.0.1:3306\/drupal"
    },
    "theme": {
        "theme_default": "bartik",
        "theme_admin": "seven"
    },
    "directory": {
        "Site root directory": "\/Users\/jmolivas\/develop\/drupal\/sites\/drupal.dev\/web",
        "Site temporary directory": "\/tmp",
        "Default theme directory": "\/core\/themes\/bartik",
        "Admin theme directory": "\/core\/themes\/seven"
    }
}
jmolivas commented 7 years ago

I am really interested on implement this feature globally.

I will do some investigation about extending the output component.

nvaken commented 7 years ago

Just to add another use case (of many). We'd be interested in fetching the output from user:login:url to use after deployment simulation we run locally, so we allow our developers to quickly sign into the setup. But currently, the output shows:

[OK] One-time login for "[USER]":
      "[ONE-TIME-LOGIN-URL]"

Which is really awful to parse.

jmolivas commented 7 years ago

@nvaken This totally make sense to support --format=json for some of the commands we can probably create a list of the commands we want to have fixed and assigned them a priority.