Skip to content
Myr

show correct value for flag default when using default_map

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

authored by Chris Pappalardo · committed by David Lord · parent 5b1624b · Browse files · 3 files+28 added−1 removed
This commit

State

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

Diff stats

3 files+28 added−1 removed

  • tests:+25 added−0 removed
  • other:+3 added−1 removed

3 files+28 added−1 removed

modified:src/click/core.py+1 added-1 removed
2798 unmodified lines
2799 elif self.is_bool_flag and self.secondary_opts:2800 # For boolean flags that have distinct True/False opts,2801 # use the opt without prefix instead of the value.2802 default_string = split_opt(2803 (self.opts if self.default else self.secondary_opts)[0]2803 (self.opts if default_value else self.secondary_opts)[0]2804 )[1]2805 elif self.is_bool_flag and not self.secondary_opts and not default_value:2806 default_string = ""2807 elif default_value == "":
225 unmodified lines
modified:tests/test_defaults.py+25 added
57 unmodified lines
58 assert result.return_value == ((), (), ())5960 result = runner.invoke(cli, ["-y", "-n", "-f", "-v", "-q"], standalone_mode=False)61 assert result.return_value == ((True, False), (True,), (1, -1))626364def test_flag_default_map(runner):65 """test flag with default map"""6667 @click.group()68 def cli():69 pass7071 @cli.command()72 @click.option("--name/--no-name", is_flag=True, show_default=True, help="name flag")73 def foo(name):74 click.echo(name)7576 result = runner.invoke(cli, ["foo"])77 assert "False" in result.output7879 result = runner.invoke(cli, ["foo", "--help"])80 assert "default: no-name" in result.output8182 result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": True}})83 assert "True" in result.output8485 result = runner.invoke(cli, ["foo", "--help"], default_map={"foo": {"name": True}})86 assert "default: name" in result.output
modified:CHANGES.rst+2 added
10 unmodified lines
11- Fixed issue that prevented a default value of ``""`` from being displayed in12 the help for an option. :issue:`2500`13- The test runner handles stripping color consistently on Windows.14 :issue:`2705`15- Show correct value for flag default when using ``default_map``.16 :issue:`2632`171819Version 8.1.720-------------
1102 unmodified lines