Skip to content

Commit

Permalink
Prompt for password if not given when changing user passwords (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly committed Jan 13, 2019
1 parent 79415a8 commit 8e48dc4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions alertaclient/commands/cmd_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
import click


@click.command('user', short_help='Update user')
class CommandWithOptionalPassword(click.Command):

def parse_args(self, ctx, args):
for i, a in enumerate(args):
if args[i] == '--password':
try:
password = args[i + 1] if not args[i + 1].startswith('--') else None
except IndexError:
password = None
if not password:
password = click.prompt('Password', hide_input=True, confirmation_prompt=True)
args.insert(i + 1, password)
return super().parse_args(ctx, args)


@click.command('user', cls=CommandWithOptionalPassword, short_help='Update user')
@click.option('--id', '-i', metavar='UUID', help='User ID')
@click.option('--name', help='Name of user')
@click.option('--email', help='Email address (login username)')
@click.option('--password', help='Password')
@click.option('--password', help='Password (will prompt if not supplied)')
@click.option('--status', help='Status eg. active, inactive')
@click.option('--role', 'roles', multiple=True, help='List of roles')
@click.option('--text', help='Description of user')
Expand Down

0 comments on commit 8e48dc4

Please sign in to comment.