github.com/psiphon-labs/goarista@v0.0.0-20160825065156-d002785f4c67/cmd/occli/main.go (about) 1 // Copyright (C) 2016 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 // The occli tool is a simple client to dump in JSON or text format the 6 // protobufs returned by the OpenConfig gRPC interface. 7 package main 8 9 import ( 10 "flag" 11 "fmt" 12 "sync" 13 14 "github.com/aristanetworks/goarista/openconfig" 15 "github.com/aristanetworks/goarista/openconfig/client" 16 "github.com/golang/protobuf/proto" 17 18 "github.com/aristanetworks/glog" 19 ) 20 21 var jsonFlag = flag.Bool("json", false, 22 "Print the output in JSON instead of protobuf") 23 24 func main() { 25 username, password, subscriptions, addrs, opts := client.ParseFlags() 26 27 publish := func(resp *openconfig.SubscribeResponse) { 28 if resp.GetHeartbeat() != nil && !glog.V(1) { 29 return // Log heartbeats with verbose logging only. 30 } 31 var respTxt string 32 var err error 33 if *jsonFlag { 34 respTxt, err = openconfig.SubscribeResponseToJSON(resp) 35 if err != nil { 36 glog.Fatal(err) 37 } 38 } else { 39 respTxt = proto.MarshalTextString(resp) 40 } 41 fmt.Println(respTxt) 42 } 43 44 wg := new(sync.WaitGroup) 45 for _, addr := range addrs { 46 wg.Add(1) 47 go client.Run(publish, wg, username, password, addr, subscriptions, opts) 48 } 49 wg.Wait() 50 }