Python Click module, how to take in a username and password as arguments

  authentication, click, python, python-3.x

I’ve created a very simple CLI application that takes in a username and password as arguments using Click. Using @click.password_option() I’m able to mask the password and have the user confirm their password without any code from my end, which is great.

Though, I noticed that the email field is being slurped in as None. I believe this is because I am using password.option()

Does anyone have a workaround for this? I’ve tried using Click’s Context.invoke() and Context.forward() to pass in the email field but that was no help.

@cli.command()
@click.argument("email", type=str, required=True)
@click.password_option()
def register(email, password):
        click.echo(f"{email} {password}")
Output:
> None test

Source: Python Questions

LEAVE A COMMENT