Support show_default string in prompts #3165
Open
+12
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2836
When
show_defaultis set to a string on anOptionwithprompt=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_defaultstring.