Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added -json flag to info.

  • Loading branch information...
commit 7fed117ae069a554c0eaebfa1094c130d0c017bc 1 parent e41bf0c
@dustin dustin authored
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)
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.