Hi Mitchell,

Can you provide a few more details to help clarify how to parse the machine 
readable output.  Mostly making explicit what I assume to be true or 
correcting my mistaken assumptions.

I assume I should parse lines like a finite set which are a response to a 
specific command.  This means that I expect that only certain line types 
are valid in a response to a particular command, and that I won't have 
duplicate lines with different data.  For example, if I call `vagrant box 
list --machine-readable`, I expect to only get lines of type 'box-name', 
'box-provider', 'box-version' (<- not yet documented at 
http://docs.vagrantup.com/v2/cli/machine-readable.html), and perhaps 
'error-exit'.

I am assuming that there are relationships between lines that group them 
together.  For example, if I call `vagrant status --machine-readable`, and 
I get a 'provider-name' line for a particular target, I'm expecting to also 
get 'state', 'state-human-long', and 'state-human-short' lines for that 
target.

I also assume that there is semantically a difference between lines with an 
empty target that target the default VM name (e.g. 'state' lines) and lines 
that are global to vagrant, like 'box-name' lines.  I assume line Types 
labeled as 'targetted' (spelling? should it be targeted?) always refer to a 
VM, and other line types are always related to Vagrant globally.

Can there be multiple 'error-exit' lines in a response?

Unlike status response lines, that can be grouped with a particular target, 
box list response lines are all associated with the empty target.  I assume 
then that box list response lines come in sequential triples of type 
'box-name', 'box-provider', 'box-version', all of which are keyed to the 
box name.  True?  Or can there be multiple versions of a box-name?

In general, some guidelines as to how to group lines, would help in knowing 
whether I should parse data into lists or maps/dicts/objects, and what to 
key those dicts on.

Thanks for any help you can provide in straightening out my understanding.

Best,
Todd


On Saturday, March 22, 2014 4:48:41 PM UTC-4, Todd DeLuca wrote:
>
> Ok.  Thanks, Mitchell.
>
> On Friday, March 21, 2014 5:01:51 PM UTC-4, Mitchell Hashimoto wrote:
>>
>> Todd, 
>>
>> The core is very unfriendly to this sort of output and is very much 
>> line-oriented. Instead, it might be better for a separate library to 
>> parse the Vagrant machine readable output and turn it into JSON. 
>>
>> Best, 
>> Mitchell 
>>
>> On Fri, Mar 21, 2014 at 1:59 PM, Todd DeLuca <[email protected]> wrote: 
>> > Hi Mitchell, et al., 
>> > 
>> > What do you think about using JSON as a machine readable output? 
>> > 
>> > The current machine readable output format burdens users with parsing a 
>> > sparsely documented ad hoc format, albeit one that is more structured 
>> than 
>> > the default vagrant output.  Without very thorough documentation it is 
>> > difficult to know if one is parsing the machine readable output 
>> correctly. 
>> > This makes it only slightly better than the default (non-machine 
>> readable) 
>> > sparsely documented ad hoc output, at least for my purposes.  (I 
>> maintain 
>> > python-vagrant: https://github.com/todddeluca/python-vagrant). 
>> > 
>> > Contrast this with JSON.  JSON requires no parsing, assuming you have a 
>> JSON 
>> > parser for your language of choice.  It can easily represent complex 
>> nested 
>> > data structures.  If a user wants to process the output using command 
>> line 
>> > tools, they can use jq (http://stedolan.github.io/jq/), which is like 
>> sed 
>> > for JSON, according to its docs. 
>> > 
>> > Here is an example of machine readable output: 
>> > 
>> > $ vagrant box list --machine-readable 
>> > 1395431215,,box-name,precise32 
>> > 1395431215,,box-provider,virtualbox 
>> > 1395431215,,box-version,0 
>> > 1395431216,,box-name,precise64 
>> > 1395431216,,box-provider,virtualbox 
>> > 1395431216,,box-version,0 
>> > 1395431216,,box-name,python-vagrant-base 
>> > 1395431216,,box-provider,virtualbox 
>> > 1395431216,,box-version,0 
>> > 1395431216,,box-name,trusty64 
>> > 1395431216,,box-provider,virtualbox 
>> > 1395431216,,box-version,0 
>> > 
>> > Since the information for one box is spread across multiple lines, the 
>> > parsing required is more sophisticated than that for a simple CSV 
>> table. 
>> > With no begin and end tags, to parse the data you must intimately 
>> understand 
>> > how each line relates to the others. 
>> > 
>> > Here is a hypothetical JSON version of the box output above: 
>> > 
>> > $ vagrant box list --json 
>> > [ 
>> >   { 
>> >     "target": null, 
>> >     "timestamp": 1395431215, 
>> >     "box-name": "precise32", 
>> >     "box-version": "0", 
>> >     "type": "box-list", 
>> >     "box-provider": "virtualbox" 
>> >   }, 
>> >   { 
>> >     "target": null, 
>> >     "timestamp": 1395431216, 
>> >     "box-name": "precise64", 
>> >     "box-version": "0", 
>> >     "type": "box-list", 
>> >     "box-provider": "virtualbox" 
>> >   }, 
>> >   { 
>> >     "target": null, 
>> >     "timestamp": 1395431216, 
>> >     "box-name": "python-vagrant-base", 
>> >     "box-version": "0", 
>> >     "type": "box-list", 
>> >     "box-provider": "virtualbox" 
>> >   }, 
>> >   { 
>> >     "target": null, 
>> >     "timestamp": 1395431216, 
>> >     "box-name": "trusty64", 
>> >     "box-version": "0", 
>> >     "type": "box-list", 
>> >     "box-provider": "virtualbox" 
>> >   } 
>> > ] 
>> > 
>> > And to demonstrate how `jq` can manipulate this data on the command 
>> line, 
>> > here is an example using `jq` to select the "trusty64" box: 
>> > 
>> > $ vagrant box list --json | jq '.[] | select(.["box-name"] == 
>> "trusty64")' 
>> > { 
>> >   "box-provider": "virtualbox", 
>> >   "type": "box-list", 
>> >   "box-version": "0", 
>> >   "box-name": "trusty64", 
>> >   "timestamp": 1395431216, 
>> >   "target": null 
>> > } 
>> > 
>> > Is this the right place to make these feature requests?  Should I open 
>> an 
>> > issue on GitHub? 
>> > 
>> > Regards, 
>> > Todd 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "Vagrant" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to [email protected]. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to