Skip to main content
Home
Drupal life hacks

Main navigation

  • Drupal
  • React
  • WP
  • Contact
  • About
User account menu
  • Log in

Breadcrumb

  1. Home

Exploring Drush Output Formatting

By admin, 3 April, 2024

The `--format` parameter in Drush is used to specify the output format of the command results. It allows you to customize how the information returned by Drush commands is presented. Here's how it works:

1. **Text Format (`--format=text`)**: This is the default format for Drush commands. It displays the command output in a human-readable text format, with each item typically listed on a separate line. This format is suitable for viewing command output directly in the terminal.

2. **JSON Format (`--format=json`)**: When using the `--format=json` parameter, Drush returns the command output in JSON (JavaScript Object Notation) format. JSON is a lightweight data interchange format that is easy for machines to parse and generate, making it suitable for automated processing and integration with other tools and systems.

3. **YAML Format (`--format=yaml`)**: The `--format=yaml` parameter instructs Drush to output the command results in YAML (YAML Ain't Markup Language) format. YAML is a human-readable data serialization format that is commonly used for configuration files and data exchange between different programming languages.

4. **CSV Format (`--format=csv`)**: When using the `--format=csv` parameter, Drush formats the command output as Comma-Separated Values (CSV). CSV is a simple and widely supported format for tabular data, making it suitable for exporting command results to spreadsheets or other data analysis tools.

By specifying the `--format` parameter with one of the supported values, you can control how Drush presents the output of its commands, allowing you to choose the format that best suits your needs for viewing, processing, or exporting command results.

 

When using Drush with the `--format` parameter set to `var_export`, it outputs the result of a Drush command in a format that is compatible with PHP's `var_export` function. This means that the output is a PHP code snippet representing the result data structure.

For example, if you run a Drush command like `drush pm-list --format=var_export`, it will list all installed modules and themes in your Drupal site in the form of a PHP array, which can be directly copied into a PHP script and used as data.

The output might look something like this:

<?php
return array (
 'module' =>
 array (
   'admin_toolbar' =>
   array (
     'filename' => '/path/to/modules/admin_toolbar/admin_toolbar.module',
     'name' => 'Admin Toolbar',
     'status' => 'enabled',
     'weight' => 0,
     'description' => 'Provides a toolbar to allow easy navigation of the site.',
     'package' => 'Admin',
     'version' => '8.x-1.26',
     'core' => '8.x',
     'dependencies' =>
     array (
       0 => 'toolbar',
       1 => 'user',
     ),
     'php' => '>=5.5.9',
     'hidden' => false,
     'required' => false,
     'schema_version' => 8000,
     'project' => 'admin_toolbar',
   ),
   // More modules...
 ),
 'theme' =>
 array (
   'bartik' =>
   array (
     'filename' => '/path/to/themes/bartik/bartik.theme',
     'name' => 'Bartik',
     'status' => 'enabled',
     'description' => 'Bartik is the default core theme provided by Drupal.',
     'version' => '8.8.0',
     'core' => '8.x',
     'project' => 'bartik',
   ),
   // More themes...
 ),
);

This format is useful for capturing the output of Drush commands programmatically and integrating it directly into PHP scripts or applications.

Tags

  • #Drupal Planet
  • Drush

Comments

About text formats

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Powered by Drupal