From d3da6e8f42c6cf4775260e306027d2f0916af265 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 29 Dec 2015 20:58:58 -0600 Subject: [PATCH] cmd/lncli: properly pretty print json response --- cmd/lncli/commands.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index f5fa29bb..71f57275 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -1,14 +1,26 @@ package main import ( + "bytes" "encoding/json" - "fmt" + "os" "github.com/codegangsta/cli" "golang.org/x/net/context" "li.lan/labs/plasma/rpcprotos" ) +func printRespJson(resp interface{}) { + b, err := json.Marshal(resp) + if err != nil { + fatal(err) + } + + var out bytes.Buffer + json.Indent(&out, b, "", "\t") + out.WriteTo(os.Stdout) +} + var NewAddressCommand = cli.Command{ Name: "newaddress", Usage: "gets the next address in the HD chain", @@ -24,7 +36,7 @@ func newAddress(ctx *cli.Context) { fatal(err) } - fmt.Println(json.Marshal(addr)) + printRespJson(addr) } var SendManyCommand = cli.Command{ @@ -37,15 +49,11 @@ var SendManyCommand = cli.Command{ func sendMany(ctx *cli.Context) { var amountToAddr map[string]int64 - fmt.Println(ctx.Args()) - jsonMap := ctx.Args().Get(0) if err := json.Unmarshal([]byte(jsonMap), &amountToAddr); err != nil { fatal(err) } - fmt.Println("map: %v", amountToAddr) - ctxb := context.Background() client := getClient(ctx) @@ -54,5 +62,5 @@ func sendMany(ctx *cli.Context) { fatal(err) } - fmt.Println(json.Marshal(txid)) + printRespJson(txid) }