use isinstance to detect whether result is protobuf message

pull/25/head
Pavol Rusnak 7 years ago
parent 1727b9a9b6
commit 5ffc700f0c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -75,8 +75,8 @@ def cli(ctx, transport, path, verbose, is_json):
@cli.resultcallback()
def print_result(res, transport, path, verbose, is_json):
if is_json:
if hasattr(res, '__module__') and res.__module__ == 'messages_pb2':
from google.protobuf import json_format
from google.protobuf import json_format, message
if isinstance(res, message.Message):
click.echo(json_format.MessageToJson(res, preserving_proto_field_name=True))
else:
click.echo(json.dumps(res, sort_keys=True, indent=4))

Loading…
Cancel
Save