From 01e71c81006bb59c2b30bf026873666ced45158f Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Sun, 14 Jun 2015 14:15:47 +0900 Subject: [PATCH] cli: handle json option for monitor commands Signed-off-by: ISHIDA Wataru --- gobgp/monitor.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gobgp/monitor.go b/gobgp/monitor.go index 578162ce..d21de0f3 100644 --- a/gobgp/monitor.go +++ b/gobgp/monitor.go @@ -16,6 +16,7 @@ package main import ( + "encoding/json" "fmt" "github.com/osrg/gobgp/api" "github.com/spf13/cobra" @@ -52,7 +53,12 @@ func NewMonitorCmd() *cobra.Command { fmt.Println(err) os.Exit(1) } - showRoute([]*api.Path{p}, false, false, true) + if globalOpts.Json { + j, _ := json.Marshal(p) + fmt.Println(string(j)) + } else { + showRoute([]*api.Path{p}, false, false, true) + } } }, @@ -88,7 +94,12 @@ func NewMonitorCmd() *cobra.Command { fmt.Println(err) os.Exit(1) } - fmt.Printf("[NEIGH] %s fsm: %s admin: %s\n", s.Conf.RemoteIp, s.Info.BgpState, s.Info.AdminState) + if globalOpts.Json { + j, _ := json.Marshal(s) + fmt.Println(string(j)) + } else { + fmt.Printf("[NEIGH] %s fsm: %s admin: %s\n", s.Conf.RemoteIp, s.Info.BgpState, s.Info.AdminState) + } } }, }