Support show_default string in prompts
Summary
Fixes #2836
When show_default is set to a string on an Option with prompt=True, the string was only used in the help text but not in the actual prompt. Now the custom string is also displayed in the prompt, matching the behavior of help text.
Before
@click.option('--name', default='default', show_default='show_default', prompt=True)
Help: --name TEXT [default: (show_default)] ✓
Prompt: Name [default]: ✗ (shows actual default, not custom string)
After
Help: --name TEXT [default: (show_default)] ✓
Prompt: Name [(show_default)]: ✓ (now shows custom string)
Changes
-
_build_prompt(): Updated to acceptstr | boolforshow_default. When it's a string, display it in parentheses (matching the help text format). -
prompt(): Updated signature to acceptstr | boolforshow_defaultparameter, and updated docstring. -
Option.prompt_for_value(): Now passesshow_defaulttoprompt()regardless of type (previously only passed it when it was a bool).
Testing
Manually tested with the reproduction case from the issue. The prompt now correctly shows the custom show_default string.