Support show_default string in prompts#3165
Open
MirrorDNA-Reflection-Protocol wants to merge 1 commit intopallets:mainfrom
Open
Support show_default string in prompts#3165MirrorDNA-Reflection-Protocol wants to merge 1 commit intopallets:mainfrom
MirrorDNA-Reflection-Protocol wants to merge 1 commit intopallets:mainfrom
Conversation
Fixes pallets#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 shown in the prompt. Changes: - Update _build_prompt() to accept str | bool for show_default - When show_default is a string, display it in parentheses like the help text - Update prompt() signature to accept str | bool for show_default - Pass show_default to prompt() regardless of type (was only passing bool) Before: Help: --name TEXT [default: (show_default)] Prompt: Name [default]: After: Help: --name TEXT [default: (show_default)] Prompt: Name [(show_default)]:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.