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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With