Browse files

Added -json flag to info.

  • Loading branch information...
1 parent e41bf0c commit 7fed117ae069a554c0eaebfa1094c130d0c017bc @dustin dustin committed May 19, 2013
Showing with 12 additions and 3 deletions.
  1. +12 −3 cbfsclient/info.go
View
15 cbfsclient/info.go
@@ -47,6 +47,7 @@ type Nodes map[string]StorageNode
var infoFlags = flag.NewFlagSet("info", flag.ExitOnError)
var infoTemplate = infoFlags.String("t", "", "Display template")
var infoTemplateFile = infoFlags.String("T", "", "Display template filename")
+var infoJSON = infoFlags.Bool("json", false, "Dump as json")
const defaultInfoTemplate = `nodes:
{{ range $name, $nodeinfo := .Nodes }} {{$name}} up {{$nodeinfo.UptimeStr}} (age: {{$nodeinfo.HBAgeStr}})
@@ -138,8 +139,16 @@ func infoCommand(base string, args []string) {
wg.Wait()
- err = tmpl.Execute(os.Stdout, result)
- if err != nil {
- log.Fatalf("Error executing template: %v", err)
+ if *infoJSON {
+ data, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ log.Fatalf("Error marshaling rseult: %v", err)
+ }
+ os.Stdout.Write(data)
+ } else {
+ err = tmpl.Execute(os.Stdout, result)
+ if err != nil {
+ log.Fatalf("Error executing template: %v", err)
+ }
}
}

0 comments on commit 7fed117

Please sign in to comment.