Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable CLI pretty printing #129

Merged
merged 1 commit into from May 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 26 additions & 20 deletions conduce/cli.py
Expand Up @@ -17,6 +17,30 @@
from . import ingest


def isstr(arg):
return isinstance(arg, ("".__class__, u"".__class__))


def print_response(response):
responseStr = response
try:
if isinstance(response, bytes):
responseStr = response.decode()
except:
pass
# if isinstance(response, str):
if isstr(responseStr):
try:
print(json.dumps(json.loads(responseStr), indent=2))
except:
print(responseStr)
else:
try:
print(json.dumps(responseStr, indent=2))
except:
print(responseStr)


def list_from_args(args):
object_to_list = args.object_to_list
del vars(args)['object_to_list']
Expand Down Expand Up @@ -852,27 +876,9 @@ def error(self, message):
if hasattr(result, 'headers'):
print(result.headers)
if hasattr(result, 'content'):
if isinstance(result.content, str):
try:
print(json.dumps(json.loads(result.content), indent=2))
except:
print(result.content)
else:
try:
print(json.dumps(result.content, indent=2))
except:
print(result.content)
print_response(result.content)
else:
if isinstance(result, str):
try:
print(json.dumps(json.loads(result), indent=2))
except:
print(result)
else:
try:
print(json.dumps(result, indent=2))
except:
print(result)
print_response(result)
except requests.exceptions.HTTPError as e:
print(e)
print(e.response.text)
Expand Down