From 39a42220212fff53786abe13a9f8d370f7b21ba5 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Sun, 18 Apr 2021 09:45:12 +0200 Subject: [PATCH] feat: add option to list users to group cmd --- alertaclient/commands/cmd_group.py | 14 ++++++++++++-- alertaclient/commands/cmd_user.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/alertaclient/commands/cmd_group.py b/alertaclient/commands/cmd_group.py index e2e3396..ebe6d0d 100644 --- a/alertaclient/commands/cmd_group.py +++ b/alertaclient/commands/cmd_group.py @@ -1,17 +1,27 @@ import sys import click +from tabulate import tabulate @click.command('group', short_help='Create user group') +@click.option('--id', '-i', metavar='UUID', help='Group ID') @click.option('--name', help='Group name') @click.option('--text', help='Description of user group') +@click.option('--users', '-U', is_flag=True, metavar='ID', help='Get list of group users') @click.option('--delete', '-D', metavar='ID', help='Delete user group using ID') @click.pass_obj -def cli(obj, name, text, delete): +def cli(obj, id, name, text, users, delete): """Create or delete a user group.""" client = obj['client'] - if delete: + if users: + group_users = client.get_group_users(id) + timezone = obj['timezone'] + headers = {'id': 'ID', 'name': 'USER', 'email': 'EMAIL', 'roles': 'ROLES', 'status': 'STATUS', + 'text': 'TEXT', 'createTime': 'CREATED', 'updateTime': 'LAST UPDATED', + 'lastLogin': 'LAST LOGIN', 'email_verified': 'VERIFIED'} + click.echo(tabulate([gu.tabular(timezone) for gu in group_users], headers=headers, tablefmt=obj['output'])) + elif delete: client.delete_group(delete) else: try: diff --git a/alertaclient/commands/cmd_user.py b/alertaclient/commands/cmd_user.py index fa34fff..7016f07 100644 --- a/alertaclient/commands/cmd_user.py +++ b/alertaclient/commands/cmd_user.py @@ -28,7 +28,7 @@ def parse_args(self, ctx, args): @click.option('--role', 'roles', multiple=True, help='List of roles') @click.option('--text', help='Description of user') @click.option('--email-verified/--email-not-verified', default=None, help='Email address verified flag') -@click.option('--groups', '-g', is_flag=True, help='Get list of user groups') +@click.option('--groups', '-G', is_flag=True, help='Get list of user groups') @click.option('--delete', '-D', metavar='ID', help='Delete user using ID') @click.pass_obj def cli(obj, id, name, email, password, status, roles, text, email_verified, groups, delete):