Pretty prints node output from kad lookup tool (#762)

* Pretty prints node output from kad lookup tool

* Linter fix
This commit is contained in:
Dylan Lott 2018-12-04 17:23:39 -07:00 committed by GitHub
parent c6d790d58e
commit 69281552b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -205,7 +205,7 @@ func LookupNode(cmd *cobra.Command, args []string) (err error) {
return ErrInspectorDial.Wrap(err)
}
node, err := i.client.LookupNode(context.Background(), &pb.LookupNodeRequest{
n, err := i.client.LookupNode(context.Background(), &pb.LookupNodeRequest{
Id: args[0],
})
@ -213,11 +213,20 @@ func LookupNode(cmd *cobra.Command, args []string) (err error) {
return ErrRequest.Wrap(err)
}
fmt.Printf("%+v\n", node)
fmt.Println(prettyPrintNode(n))
return nil
}
func prettyPrintNode(n *pb.LookupNodeResponse) string {
m := jsonpb.Marshaler{Indent: " ", EmitDefaults: false}
s, err := m.MarshalToString(n)
if err != nil {
zap.S().Error("error marshaling node: %s", n)
}
return s
}
func prettyPrintBucket(b *pb.GetBucketResponse) string {
m := jsonpb.Marshaler{Indent: " ", EmitDefaults: false}
s, err := m.MarshalToString(b)

View File

@ -138,10 +138,7 @@ func (srv *Server) LookupNode(ctx context.Context, req *pb.LookupNodeRequest) (*
}
return &pb.LookupNodeResponse{
Node: &pb.Node{
Id: node.Id,
},
Meta: nil,
Node: &node,
}, nil
}