cmd_resource.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:ecxclient 作者: catalogicsoftware 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号