@@ -165,33 +165,37 @@ func closeConnection(context *cli.Context) error {
165
165
return conn .Close ()
166
166
}
167
167
168
- func outputJSON (v interface {}) error {
169
- marshaledJSON , err := json .MarshalIndent (v , "" , " " )
168
+ func protobufObjectToJSON (obj proto.Message ) (string , error ) {
169
+ jsonpbMarshaler := jsonpb.Marshaler {EmitDefaults : true , Indent : " " }
170
+ marshaledJSON , err := jsonpbMarshaler .MarshalToString (obj )
170
171
if err != nil {
171
- return err
172
+ return "" , err
172
173
}
173
-
174
- fmt .Println (string (marshaledJSON ))
175
- return nil
174
+ return marshaledJSON , nil
176
175
}
177
176
178
- func outputYAML ( v interface {} ) error {
179
- marshaledYAML , err := yaml . Marshal ( v )
177
+ func outputProtobufObjAsJSON ( obj proto. Message ) error {
178
+ marshaledJSON , err := protobufObjectToJSON ( obj )
180
179
if err != nil {
181
180
return err
182
181
}
183
182
184
- fmt .Println (string ( marshaledYAML ) )
183
+ fmt .Println (marshaledJSON )
185
184
return nil
186
185
}
187
186
188
- func protobufObjectToJSON (obj proto.Message ) (string , error ) {
189
- jsonpbMarshaler := jsonpb.Marshaler {EmitDefaults : true , Indent : " " }
190
- marshaledJSON , err := jsonpbMarshaler .MarshalToString (obj )
187
+ func outputProtobufObjAsYAML (obj proto.Message ) error {
188
+ marshaledJSON , err := protobufObjectToJSON (obj )
191
189
if err != nil {
192
- return "" , err
190
+ return err
193
191
}
194
- return marshaledJSON , nil
192
+ marshaledYAML , err := yaml .JSONToYAML ([]byte (marshaledJSON ))
193
+ if err != nil {
194
+ return err
195
+ }
196
+
197
+ fmt .Println (string (marshaledYAML ))
198
+ return nil
195
199
}
196
200
197
201
func outputStatusInfo (status proto.Message , info map [string ]string , format string ) error {
0 commit comments