From 12bcbf437486599350c3a6a9a46d4acd4c887399 Mon Sep 17 00:00:00 2001 From: mobrine1 <33225846+mobrine1@users.noreply.github.com> Date: Tue, 2 Feb 2021 15:40:33 -0500 Subject: [PATCH 1/3] #4289 printing json output Adding --json flag to print json output --- scripts/rest_client.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/rest_client.py b/scripts/rest_client.py index 2232b8421..6a3b2126b 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -331,6 +331,13 @@ def add_arguments(): default=[] ) + parser.add_argument('--json', + help='Output data in json form rather than a python dict', + dest='json', + action='store_true', + default=False + ) + args = parser.parse_args() return vars(args) @@ -379,8 +386,11 @@ def main(args): print_commands() return - print(getattr(client, command)(*args["command_arguments"])) - + output = getattr(client, command)(*args["command_arguments"]) + if args['json']: + print(json.dumps(output)) + else: + print(output) if __name__ == "__main__": args = add_arguments() From 56569690d978b03ee23f3b7d24d9ceb04a8681fc Mon Sep 17 00:00:00 2001 From: mobrine1 <33225846+mobrine1@users.noreply.github.com> Date: Tue, 2 Feb 2021 15:59:48 -0500 Subject: [PATCH 2/3] Update rest_client.py --- scripts/rest_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/rest_client.py b/scripts/rest_client.py index 6a3b2126b..b214acda3 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -392,6 +392,7 @@ def main(args): else: print(output) + if __name__ == "__main__": args = add_arguments() main(args) From 06b56544a8f51e4e87646acabe14ef166c0638b8 Mon Sep 17 00:00:00 2001 From: mobrine1 <33225846+mobrine1@users.noreply.github.com> Date: Wed, 3 Feb 2021 03:27:54 -0500 Subject: [PATCH 3/3] printing json by default now --- scripts/rest_client.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/scripts/rest_client.py b/scripts/rest_client.py index b214acda3..b6e66cfa4 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -331,13 +331,6 @@ def add_arguments(): default=[] ) - parser.add_argument('--json', - help='Output data in json form rather than a python dict', - dest='json', - action='store_true', - default=False - ) - args = parser.parse_args() return vars(args) @@ -386,11 +379,7 @@ def main(args): print_commands() return - output = getattr(client, command)(*args["command_arguments"]) - if args['json']: - print(json.dumps(output)) - else: - print(output) + print(json.dumps(getattr(client, command)(*args["command_arguments"]))) if __name__ == "__main__":