Reduce the number of similar sounding formats that we expose to users.

Comments

moshe weitzman’s picture

Also, I am not seeing any line breaks in the CSV which is a violation of that format (obviously).

greg.1.anderson’s picture

The format you want is:

dr pml --format=csv-list --fields=package,name,type

The format 'csv' is always a single-dimensional list of elements; 'csv-list' is a list of records, with the fields of each record being separated by a comma.

There are a number of format pairs where the single-dimensional variant has a corresponding list-of-records format (e.g. 'ini' and 'ini-sections'). I have considered some ways where Drush might autodetect situations where the user says "csv" but "means" "csv-list", and then automatically "promote" the request to the more logical, richer data type. However, there are some existing cases from Drush 5 where the pipe format devolves to the one-dimensional data format; to support that, I automatically convert two-dimensional records down to one-dimensional lists containing just the record keys, which is what you are seeing.

If we loosen up on backwards compatibility a bit, and/or implement dr pml --pipe slightly differently, then things might be able to get a little bit better in the average cases.

moshe weitzman’s picture

Title: pml command has only 1 field by default » Reduce number of formats and/or do better guessing about what format user meant to use.

I think breaking backwards compat is fine for Drush6. Further, I am still a little unhappy that we have so many formats that are so similar. Some are similar in name, others in output. Would be good if we could make some assumptions as you are suggesting.

moshe weitzman’s picture

Category: bug » task
Priority: Normal » Major
Issue tags: +Release blocker

I'm marking this a release blocker. I really think we can ditch backward compat and simplify, from an end user perspective.I don't like the -list variants much.

I'll study the code and make a more concrete suggestion. Lets keep discussing here.

greg.1.anderson’s picture

I agree that csv-list et. al. are terrible, at least in name. It is, however, necessary to differentiate between csv and csv-list formatters, at least at the plugin level. This is because the data structure that csv-list takes is quite different than what csv needs.

I would suggest renaming 'cvs-list' to 'csv', and give the old 'csv' some other name (no suggestion at the moment). If the user passes a data structure that only works with the primitive comma-separated value data structure to the list of csv formatters, it could detect that fact and revert to using the primitive formatter instead of using the list. It might be necessary to put a function callback name into the list of csv formatter that names the function to detect that formatter simplification is needed, as the algorithm for csv-list -> csv is perhaps different than what is needed for ini-sections -> ini.

greg.1.anderson’s picture

Postponed #1993796: Various issues noticed with outputformats until we are done here.

greg.1.anderson’s picture

What we discussed:

1. Remove or hide 'csv' and 'ini' formats. I think you can just delete 'csv', but you'll need to keep the other csv-like formats ('nested-csv' and 'csv-or-string'), as these are used by csv-list.

2. Rename 'csv-list' to 'csv'. Just before foreach ($input as $label => $data) { in list.inc, you are going to want to detect data like array('a', 'b', 'c') and turn it into array(array('a', 'b', 'c')).

3. Rename 'ini-sections' to 'ini', and do the same operation as #2 when an 'ini' data structure is passed to ini-sections. Detecting simple csv arrays is as easy as checking to see if the first element is -not- an array; testing ini vs ini-sections may be more involved. You'll probably need to add the name of a fn to do this detection, as suggested in #5.

4. Just get rid of key-value and key-value-list everywhere they appear, and replace them with tables. This is what we discussed, but I'm not sure how well this will work in practice. The data structure for a table is an array of rows, each of which is an array of key:value pairs, with the keys corresponding with the column ids. A key-value-list, on the other hand, is an array of key-value sections, with each of these containing a label:value pair. The big difference between key-value-list / key-value vs. a table is that the "columns" are laid out horizontally in a table, whereas they are laid out vertically in key-value lists. It would not work to just rotate the drush status or pm-info output, and have the status values laid out horizontally; you'd quickly run out of horizontal space in the terminal window. One thing that might work here would be to make Drush automatically pivot table data into the vertical format whenever the column widths got too narrow. The affect of that is that if you typed 'drush status', and for some reason it only returned a couple of values, they would be rendered side-by-side instead of on separate lines (this would never happen in practice for the status command). Also, if you ran drush pm-updatestatus in a very narrow terminal, then the projects to be upgraded would print out one after another, like drush pm-info a b c d (pmi with multiple modules). I think this could work; it would get rid of key-value-list and key-value, and would pretty much just do the right thing for the user. Rather than rotating the data structures, it might be easier to keep but hide the key-value formats, and automatically switch to those formatters when there are too many columns.

moshe weitzman’s picture

I performed the steps in #1 and #2 and am a bit stuck. When I do a drush pml --format=csv I go into an infinite loop as I keep doing subengine formatting on line 139 of list.inc which is $formatted_item = $this->sub_engine->format($data, $metameta);

I pushed my changes to a new branch called outputformat (http://drupalcode.org/project/drush.git/shortlog/refs/heads/outputformat). Hopefully Greg can commit a fix in that branch or point me in the right direction.

In general, I'm fine with solutions that simply hide formatters for internal use. My goal is mostly simplification for end users.

greg.1.anderson’s picture

Don't know that I will have time to look at this soon. I think I know what is going on with the infinite loop. I thought that csv was not being used as a subformat (that only 'nested-csv' and 'csv-or-string' are), but it looks like it is. The reference to 'csv' as a subformat needs to be changed to something else ('csv-internal-use-only'?). Maybe 'csv-or-string' calls through to 'csv' if the input is not a string.

If I don't weigh in here in a couple of weeks, please bump the issue. I'll try to remember to check on my assigned issues.

moshe weitzman’s picture

Priority: Major » Normal
Issue tags: -Release blocker

I just pushed two commits which do the following

  1. Rename csv-list to csv. I fixed my earlier problem by simply not doing Step 2) from #7. That fixed the infinite loop and I see no ill repurcussions.
  2. Remove ini and ini-section output formatters. I don't see much need for these, given that we have json and yaml as output formats. ini was just used in --pipe situations and I have replaced those with json. I think yaml would be fine as well, if folks prefer. I commented out a few Drupal tests that were using ini because my regex sucks and I didn't want to convert them to something else. I'm not convinced yet of the usefulness of the Drupal tests. I think we could do pure Unit tests of the engines and not do any Drupal tests at all.

Not sure if I will tackle key-value.

Feedback welcome.

moshe weitzman’s picture

I broke some tests. Will fix this weekend. Code reviews are still welcome.

moshe weitzman’s picture

Fixed the tests, mostly by changing them from expecting ini to expecting JSON.

outputformat tests got a bit commented out as i ran out of time to fix them. i switched the non-drupal ones to to use Drush_UnitTestCase and also use @dataProvider annotation.

Stil not sure about key/value. Also, I'd like to make visible YAML and json formatters on all command help. Any objection?

moshe weitzman’s picture

Status: Active » Fixed

Added a commit which shows yaml and json by default. I hid key-value and key-value-list since those aren't likely to be selected by an end user.

I also renamed export to var_export for a little more clarity.

I'm marking this fixed. We should keep on discussing improvements in other issues, or reopen this one if that makes sense.

StephenBrown’s picture

A bit late, but I for one will miss the ini-sections output, as it is in my opinion the best balance between human readability and machine parsability. And I was already using it for such in one of my scripts, yes a --pipe implementation, but I can probably rework that to use json instead.

greg.1.anderson’s picture

We could add ini output to drush_extras, perhaps. Patches welcome.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.