cmd/lncli: properly pretty print json response

This commit is contained in:
Olaoluwa Osuntokun 2015-12-29 20:58:58 -06:00
parent f2d3c2455b
commit d3da6e8f42

View File

@ -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)
}