Add result parameter which will only printout the result contents

Change-Id: Ia033695472de42a1808bbecd2183ef790e6548f6
This commit is contained in:
Mark Hamzy 2016-10-30 13:44:05 -05:00
parent f6be130863
commit 9952754ce4
1 changed files with 25 additions and 2 deletions

View File

@ -328,6 +328,15 @@ if __name__ == "__main__":
dest="conf_dir",
help="The directory where configuration is stored")
parser.add_argument("-o",
"--output",
action="store",
type=str,
default="json",
dest="output",
help="The output should be json (the default)"
" or result (only the result string)")
subparsers = parser.add_subparsers(help="sub-command help")
# Register all decorated class functions by telling them argparse
@ -338,6 +347,14 @@ if __name__ == "__main__":
args = parser.parse_args()
output = args.output.upper().lower()
if output == "json":
pass
elif output == "result":
pass
else:
parser.error("Unknown output type %s" % (output, ))
if args.conf_dir:
if not os.path.isdir(args.conf_dir):
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
@ -355,7 +372,13 @@ if __name__ == "__main__":
mi.setup_argv(args)
mi.setup_parser(parser)
print(mi.get_response())
ret = mi.get_response()
json_ret = json.loads(ret)
if output == "json":
print(json_ret)
elif output == "result":
print(json_ret["result"])
try:
rc = mi.get_response_map()['status']
@ -366,4 +389,4 @@ if __name__ == "__main__":
if rc == 200:
exit(0)
else:
exit(1)
exit(rc)