Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#3 | drush-site-lists-and-output-1963480-3.patch | 2.85 KB | greg.1.anderson |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commented@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.
Comment #2
greg.1.anderson CreditAttribution: greg.1.anderson commentedSorry, 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:
Since that's a little gruesome, I have a patch (attached below) that cleans it up to:
We can rename --label-separator to something else (perhaps something more specific-sounding) if you'd like. Nothing comes immediately to mind, though.
Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commentedAnd here is the patch.
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedCommitted. Thanks.
Some follow-ups for a rainy day:
Comment #5
roball CreditAttribution: roball commentedThis 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:
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedTurns out that we did add docs to example.aliases.drushrc.php (see below).
Implementation thoughts or patches for "Automatically set the label-separator so it matches the list-separator when CSV is detected" are welcome
Comment #7
greg.1.anderson CreditAttribution: greg.1.anderson commentedI'd put the code to automatically set the label separator in drush_preflight_command_dispatch, just before the drush_invoke_process.
Simple way:
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.Comment #8
greg.1.anderson CreditAttribution: greg.1.anderson commentedOh, #7 should look up the list-separator, of course.
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedOh, looking up the list-separator is going to involve calling
$formatter = drush_get_outputformat()
. More investigation needed; probably would work out.Comment #10
greg.1.anderson CreditAttribution: greg.1.anderson commentedMigrated to GitHub issue queue: https://github.com/drush-ops/drush/issues/52