Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating an option with prompt always prompts even if the option isn't added to command call #1015

Closed
reinaldorauch opened this issue May 15, 2018 · 3 comments · Fixed by #1618
Labels
f:prompt feature: prompt for input
Milestone

Comments

@reinaldorauch
Copy link

Hi, I'm having an issue when I add a prompt or password prompt option to my command. It will prompt even if the command doesn't have that option specified when calling the command in terminal.

I used this cookiecutter template to generate the boilerplate code:
https://github.com/nvie/cookiecutter-python-cli

And the default configs generate a working command that i used to test this:

  1. I added an password_prompt decorator in the main command at my_tool/cli.py:
import click


@click.command()
@click.option('--as-cowboy', '-c', is_flag=True, help='Greet as a cowboy.')
@click.password_option('--password', '-p', help='Input a password')
@click.argument('name', default='world', required=False)
def main(name, as_cowboy):
    """My Tool does one thing, and one thing well."""
    greet = 'Howdy' if as_cowboy else 'Hello'
    click.echo('{0}, {1}.'.format(greet, name))
  1. Installed in the project virtualenv with pip
pip install --editable .
  1. Calling the my-tool command in virtualenv makes click prompt for the password:
$ my-tool
Password:

As it is an option I thought that it wouldn't prompt it it isn't passed when calling the command.

There is something that I'm missing?

@LuckyJosh
Copy link

That is by design I would guess,
the documentation example shows this behaviour as well:
http://click.pocoo.org/5/options/#password-prompts

@LuckyJosh
Copy link

Just below the section I referenced above comes the section about callbacks, those might be usefull to you:

http://click.pocoo.org/5/options/#callbacks-and-eager-options

@fdavis
Copy link
Contributor

fdavis commented May 18, 2018

related to #736

@davidism davidism added this to the 8.0.0 milestone Aug 6, 2020
@davidism davidism added the f:prompt feature: prompt for input label Aug 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f:prompt feature: prompt for input
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants