Support show_default string in prompts#3165
Support show_default string in prompts#3165MirrorDNA-Reflection-Protocol wants to merge 3 commits intopallets:stablefrom
show_default string in prompts#3165Conversation
show_default string in prompts
3f4eb62 to
bf4b0bb
Compare
|
Just added some tests on top of the original PR, including edge-cases and This PR is ready to be merged upstream on top of |
bf4b0bb to
f20eb46
Compare
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)]:
f20eb46 to
c29e83f
Compare
|
AI generated |
|
@davidism : this PR may have been initially AI generated, but still fix a legitimate issue. That's why I took over it 2 weeks ago to amend and fix its slop. See the comment history. Now that 8.3.2 has been release, I propose to start the 8.3.3 merging phase with this PR first: it is addressing an issue that a lot of AI have tried to solve in the past few weeks. So merging this will cut all the AI generated siblings. |
|
I'm not interested in cleaning up AI generated code. I don't want those contributions. I'm sorry you put time into this, but I'd rather that time be spent on creating a PR by hand rather than laundering an AI contribution Look at the users contribution graph. It's obvious that they're not putting time into anything they're doing. I'm not interested in encouraging that behavior. |
I understand. When I started working on that issue I realized we had a human-contributed solution at #2837. But the initial user deleted his forked repository so I could not rework its contribution within the #2837 PR. So I defaulted to the oldest PR which is this one. I wasn't 100% sure this PR was AI-generated so with the benefits of the doubt, and to not erase the original author commit infos, I decided to build on top of it. I can recreate a clean PR with my modifications to fix #2836 once and for all. |
|
You can still get the patch for a PR, even if the branch has been deleted by appending .patch to the URL. You can apply that in a new branch to re-create the PR while preserving that users credit. |
|
This PR has been superseded by #3328. |
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.