Reputation: 317
I'm using the click library for a CLI application. I have various options that the user can specify, and most of them have prompts turned on. However, even if an option isn't required, if you set click to prompt for the option, it won't accept an empty response (like just hitting enter). For example:
@click.option('-n', '--name', required=True, prompt=True)
@click.option('-d', '--description', required=False, prompt=True)
>>> myscript -n Joe
>>> Description: [Enter pressed]
>>> Description: [Enter pressed; click doesn't accept an empty parameter]
Is there a way to get around this, or would this require a feature request?
Upvotes: 5
Views: 7259
Reputation: 11573
when you add default=""
then an empty string is also accepted:
@click.option('-d', '--description', prompt=True, default="")
Note that required
is not a possible argument for option, at least according to the docs
Upvotes: 11