hashicorp/serf — pull request #113 by ryanuber (2014-01-28 11:46:29+00:00)
Title: Output format

This enhancement will allow the `serf members` command to take a `-format` argument, with values of `text` (the default), `json`, or `xml`.

The original output of the `serf members` command is preserved, so there should be no incompatibility with people's current scripts that parse it with sed/awk etc. The `-format` option currently works on the `serf members` command, and I tried my best to make the output formatter reusable for more commands to use it as needed.

There was a bit of complexity in successfully mapping the same structure to both XML and JSON, but I feel like the output that I have now is correct:

```
$ serf members -format json
{
"members": [
{
"name": "a.cisco.com",
"addr": "10.77.5.101:7946",
"port": 7946,
"tags": {
"role": "web",
"x": "y"
},
"status": "alive",
"protocol": {
"min": 1,
"max": 3,
"version": 3
}
}
]
}

$ serf members -format xml

10.77.5.101:7946
7946

alive

1
3
3

```

This was been discussed in #55 and #97.

It ended up being more code than I thought it would be, and could maybe be more compact/effecient, so that's something to consider before any merging.

Tests are passing. Let me know what you think. This is my first dive into Go so any feedback is much appreciated.