We can improve our output when emitting csv-list output over a list of sites. For example, I did a pml over @sites and one line is

.Users.moshe.weitzman.htd.d7#sq3 >> Views,Views UI (views_ui),Module,Not installed,7.x-3.0-rc1.

Ideally, .Users.moshe.weitzman.htd.d7#sq3 would be the first column in the csv output instead of a hard-to-parse prefix

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

@Greg - any thoughts about how to improve make this data more parseable? I'll note that if you use --format=json you get one big json array for each site which might be easier for folks to parse. Still, moving the site into the data is ideal.

greg.1.anderson’s picture

Sorry, I couldn't answer that question off the top of my head the first time (beyond a cursory "I think the code can do that..."), and then I forgot to go back to it.

What you want can be accomplished with the following:

$ drush @sites pml --#label-separator=',' --strict=0 --format=csv

Since that's a little gruesome, I have a patch (attached below) that cleans it up to:

$ drush @sites pml --label-separator=',' --format=csv

We can rename --label-separator to something else (perhaps something more specific-sounding) if you'd like. Nothing comes immediately to mind, though.

greg.1.anderson’s picture

Status: Active » Needs review
FileSize
2.85 KB

And here is the patch.

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. Thanks.

Some follow-ups for a rainy day:

  1. Document @sites. I don't see it mentioned anywhere
  2. Automatically set the label-separator so it matches the list-separator when CSV is detected
roball’s picture

Document @sites. I don't see it mentioned anywhere

This was requested 2 1/2 years ago here: #1031170: Invalid argument supplied for foreach() backend.inc:709 on "drush @sites ups", but never implemented. There, also a patch was posted to "to document the @sites alias in aliases example file". At least, 'drush sa' should include "@sites" (or "sites"). Currently, its output is just:

[root@server ~]# drush sa
none
self
moshe weitzman’s picture

Turns out that we did add docs to example.aliases.drushrc.php (see below).

* If you would like to see all of the Drupal sites at a specified
 * root directory, use the built-in alias "@sites":
 *
 *   $ drush -r /path/to/drupal site-alias @sites
 

Implementation thoughts or patches for "Automatically set the label-separator so it matches the list-separator when CSV is detected" are welcome

greg.1.anderson’s picture

Title: Site lists and output formats (CSV) » Automatically set the label-separator so it matches the list-separator when CSV is detected
Status: Fixed » Active

I'd put the code to automatically set the label separator in drush_preflight_command_dispatch, just before the drush_invoke_process.

Simple way:

if ((drush_get_option('format') == 'csv') && !isset($multi_options['label-separator'])) {
  $multi_options['label-separator'] = ',';
}

That would work admirably, but wouldn't help much if you wanted to support this feature for other output formats as well.

If you want to be more flexible, then perhaps the code should instead call $formatter = drush_get_outputformat(), and we could add a multi-site-defauit-label-separator field to output formats. I haven't really traced through this code, though; drush_preflight_command_dispatch is called really early, which means that it might be necessary to do some awkward pre-initialization before calling drush_get_outputformat(). But then again, maybe it would just work.

greg.1.anderson’s picture

Oh, #7 should look up the list-separator, of course.

greg.1.anderson’s picture

Oh, looking up the list-separator is going to involve calling $formatter = drush_get_outputformat(). More investigation needed; probably would work out.

greg.1.anderson’s picture

Status: Active » Closed (duplicate)

Migrated to GitHub issue queue: https://github.com/drush-ops/drush/issues/52