Given the following option:
@cli.command()
@click.option('--param', default=lambda: get_value(), prompt="Enter Param")
Normal behavior is for click to show a prompt to enter a value for param
and display the default value (and you can just ENTER through it to preserve that).
Instead I'd like the param
prompt to only show if get_value()
returns None
or some pre-defined "show" value, but for any Truthy/Other value for get_value()
click will not show the prompt for this option and run the command or move to the next prompt.
This can be done by over riding the
click.Option.get_default()
and theclick.Option.prompt_for_value()
methods like:Custom Class:
Using Custom Class:
Then to use the custom class, pass it as the cls argument to the option decorator like:
Test Code:
Result:
Usage: