Update modules.py to use new handle_api_result

Use the new function to properly handle error responses for all the
commands.

(cherry picked from commit b55b86d0b3)
This commit is contained in:
Brian C. Lane 2018-07-26 10:28:54 -07:00
parent 4e3044de20
commit 42ad6ad0cc

View File

@ -17,10 +17,9 @@
import logging import logging
log = logging.getLogger("composer-cli") log = logging.getLogger("composer-cli")
import json
from composer import http_client as client from composer import http_client as client
from composer.cli.help import modules_help from composer.cli.help import modules_help
from composer.cli.utilities import handle_api_result
def modules_cmd(opts): def modules_cmd(opts):
"""Process modules commands """Process modules commands
@ -39,10 +38,10 @@ def modules_cmd(opts):
api_route = client.api_url(opts.api_version, "/modules/list") api_route = client.api_url(opts.api_version, "/modules/list")
result = client.get_url_json(opts.socket, api_route) result = client.get_url_json(opts.socket, api_route)
if opts.json: (rc, exit_now) = handle_api_result(result, opts.show_json)
print(json.dumps(result, indent=4)) if exit_now:
return 0 return rc
print("Modules:\n" + "\n".join([" "+r["name"] for r in result["modules"]])) print("Modules:\n" + "\n".join([" "+r["name"] for r in result["modules"]]))
return 0 return rc