|
1 | 1 | import sys |
2 | 2 |
|
3 | 3 | import click |
| 4 | +from tabulate import tabulate |
4 | 5 |
|
5 | 6 |
|
6 | 7 | class CommandWithOptionalPassword(click.Command): |
@@ -30,23 +31,29 @@ def parse_args(self, ctx, args): |
30 | 31 | @click.option('--delete', '-D', metavar='UUID', help='Delete user using ID') |
31 | 32 | @click.pass_obj |
32 | 33 | def cli(obj, id, name, email, password, status, roles, text, email_verified, delete): |
33 | | - """Create user or update user details, including password reset.""" |
| 34 | + """Create user, show or update user details, including password reset.""" |
34 | 35 | client = obj['client'] |
35 | 36 | if delete: |
36 | 37 | client.delete_user(delete) |
37 | 38 | elif id: |
38 | 39 | if not any([name, email, password, status, roles, text, (email_verified is not None)]): |
39 | | - click.echo('Nothing to update.') |
40 | | - sys.exit(1) |
41 | | - try: |
42 | | - user = client.update_user( |
43 | | - id, name=name, email=email, password=password, status=status, |
44 | | - roles=roles, attributes=None, text=text, email_verified=email_verified |
45 | | - ) |
46 | | - except Exception as e: |
47 | | - click.echo('ERROR: {}'.format(e), err=True) |
48 | | - sys.exit(1) |
49 | | - click.echo(user.id) |
| 40 | + user = client.get_user(id) |
| 41 | + timezone = obj['timezone'] |
| 42 | + headers = {'id': 'ID', 'name': 'USER', 'email': 'EMAIL', 'roles': 'ROLES', 'status': 'STATUS', |
| 43 | + 'text': 'TEXT', |
| 44 | + 'createTime': 'CREATED', 'updateTime': 'LAST UPDATED', 'lastLogin': 'LAST LOGIN', |
| 45 | + 'email_verified': 'VERIFIED'} |
| 46 | + click.echo(tabulate([user.tabular(timezone)], headers=headers, tablefmt=obj['output'])) |
| 47 | + else: |
| 48 | + try: |
| 49 | + user = client.update_user( |
| 50 | + id, name=name, email=email, password=password, status=status, |
| 51 | + roles=roles, attributes=None, text=text, email_verified=email_verified |
| 52 | + ) |
| 53 | + except Exception as e: |
| 54 | + click.echo('ERROR: {}'.format(e), err=True) |
| 55 | + sys.exit(1) |
| 56 | + click.echo(user.id) |
50 | 57 | else: |
51 | 58 | if not email: |
52 | 59 | raise click.UsageError('Need "--email" to create user.') |
|
0 commit comments