Skip to content

Commit

Permalink
fix users command json format borken
Browse files Browse the repository at this point in the history
  • Loading branch information
amalfra committed Jun 25, 2022
1 parent d9a49f1 commit e84b9f4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/commands/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ def run(docker_hub_client, args):
""" The command to user profile from docker hub """
resp = docker_hub_client.get_users(args.username)
if resp['code'] == 200:
rows = []
rows = [[]] if args.format == 'json' else []
header = []
for key in resp['content']:
if key == 'date_joined':
formatted_date = dateutil.parser \
.parse(resp['content'][key])
formatted_date = formatted_date.strftime("%Y-%m-%d %H:%M")
resp['content'][key] = formatted_date
rows.append([key, resp['content'][key]])
if args.format == 'json':
rows[0].append(resp['content'][key])
header.append(key)
else:
rows.append([key, resp['content'][key]])
heading = f'User profile of {args.username}'
print_result(args.format, rows, heading=heading, count=1)
print_result(args.format, rows, header, heading=heading, count=1)
else:
print('Error fetching profile for: ' + args.username)

0 comments on commit e84b9f4

Please sign in to comment.