Skip to content
Myr

Hide default value when show_default is False (#2509)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Patrick Hayes · committed by GitHub · parent 1a4d8c1 · Browse files · 3 files+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Andreas Backx <andreas@backx.org>

Diff stats

3 files+21 added−0 removed

  • tests:+12 added−0 removed
  • other:+9 added−0 removed

3 files+21 added−0 removed

modified:src/click/core.py+7 added
2793 unmodified lines
2794 # differently.2795 if self.is_bool_flag:2796 return confirm(self.prompt, default)27972798 # If show_default is set to True/False, provide this to `prompt` as well. For2799 # non-bool values of `show_default`, we use `prompt`'s default behavior2800 prompt_kwargs: t.Any = {}2801 if isinstance(self.show_default, bool):2802 prompt_kwargs["show_default"] = self.show_default28032804 return prompt(2805 self.prompt,2806 default=default,2807 type=self.type,2808 hide_input=self.hide_input,2809 show_choices=self.show_choices,2810 confirmation_prompt=self.confirmation_prompt,2811 value_proc=lambda x: self.process_value(ctx, x),2812 **prompt_kwargs,2813 )28142815 def resolve_envvar_value(self, ctx: Context) -> str | None:2816 rv = super().resolve_envvar_value(ctx)
169 unmodified lines
modified:tests/test_termui.py+12 added
445 unmodified lines
446 assert result.return_value == expect447448 if prompt == "Confirm Password":449 assert "Confirm Password: " in result.output450451452def test_false_show_default_cause_no_default_display_in_prompt(runner):453 @click.command()454 @click.option("--arg1", show_default=False, prompt=True, default="my-default-value")455 def cmd(arg1):456 pass457458 # Confirm that the default value is not included in the output when `show_default`459 # is False460 result = runner.invoke(cmd, input="my-input", standalone_mode=False)461 assert "my-default-value" not in result.output
modified:CHANGES.rst+2 added
32 unmodified lines
33 :issue:`2322`34- Show the ``types.ParamType.name`` for ``types.Choice`` options within35 ``--help`` message if ``show_choices=False`` is specified.36 :issue:`2356`37- Do not display default values in prompts when ``Option.show_default`` is38 ``False``. :pr:`2509`394041Version 8.1.842-------------
1116 unmodified lines