-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Option that is not required and prompts if specified without an arg #736
Comments
Thanks for your feedback! I don't see anyway to do that currently but it definitely seems like a good use case to me. import click
@click.command()
@click.option('--username')
@click.option('-p', '--password', prompt=True, prompt_required=False, hide_input=True)
def echoing(username, password):
click.echo(username)
click.echo(password)
echoing() |
@fdavis I understand where comes from you line of thought but wouldn't be better, semantically speaking, if we create a Using your example: import click
@click.command()
@click.option('--username')
# Keeps the current behavior
@click.option('-p', '--password', prompt=True, prompt_when_not_declared=True, hide_input=True)
# Prompts only if passed as argument to the command, maybe change this to be the default, I say why below
@click.option('-p', '--password', prompt=True, prompt_when_not_declared=False, hide_input=True)
def echoing(username, password):
click.echo(username)
click.echo(password)
echoing() When I was reading the docs I was carried to understand that as it is an option, it would only prompt if the option was passed to the command, but it prompts always. |
I'll be working on this issue! Just to clarify:
|
Discussed with @juped and thought the default should be |
Hi -
I am working on a ticket for mycli - the gist is that the team wants the '-p' flag to behave like th e mysql client - i.e. prompt if you don't pass an arg, but it is not required so do NOT prompt if the -p is not included. Today if I use standard click->prompt then scenario 2 gives an error. Below is the desired behavior:
HELLO WORLD
Please enter your password:
HELLO WORLD
It appears looking at the code there is no way to do this, but it seems desirable - before working on a PR I wanted to validate that it can't be done and get input on the usefulness of the feature.
Thanks for your guidance
John
The text was updated successfully, but these errors were encountered: