Skip to content

Conversation

@MirrorDNA-Reflection-Protocol

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

  1. _build_prompt(): Updated to accept str | bool for show_default. When it's a string, display it in parentheses (matching the help text format).

  2. prompt(): Updated signature to accept str | bool for show_default parameter, and updated docstring.

  3. Option.prompt_for_value(): Now passes show_default to prompt() 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.

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)]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show_default as a string isn't used in prompts as the default shown

1 participant