def list(ctx, **kwargs):
resp = ctx.ecx_session.get(restype=ctx.restype, endpoint=ctx.endpoint)
list_field = kwargs.get('listfield') or resource_to_listfield.get(ctx.restype) or (ctx.restype + 's')
if ctx.json or list_field not in resp:
ctx.print_response(resp)
return
resources = resp[list_field]
if kwargs['fields']:
fields = [x.strip() for x in kwargs['fields'].split(',')]
else:
fields = ["name", "id"]
table_data = []
for res in resources:
row = []
for field in fields:
row.append(res.get(field, None))
table_data.append(row)
if not table_data:
return
print
click.echo_via_pager(tabulate(table_data, headers=fields))
print
评论列表
文章目录