click icon indicating copy to clipboard operation
click copied to clipboard

Support show_default string in prompts

Open MirrorDNA-Reflection-Protocol opened this issue 2 months ago • 0 comments

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.