Skip to content

Commit

Permalink
Merge pull request #2084 from pallets/count-type-help
Browse files Browse the repository at this point in the history
count help doesn't show default range type
  • Loading branch information
davidism authored Oct 7, 2021
2 parents 3e88d3d + 3d029e0 commit f74dbbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Unreleased
:issue:`2062`
- Fix overline and italic styles, which were incorrectly added when
adding underline. :pr:`2058`
- An option with ``count=True`` will not show "[x>=0]" in help text.
:issue:`2072`


Version 8.0.1
Expand Down
6 changes: 5 additions & 1 deletion src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,11 @@ def _write_opts(opts: t.Sequence[str]) -> str:
if default_string:
extra.append(_("default: {default}").format(default=default_string))

if isinstance(self.type, types._NumberRangeBase):
if (
isinstance(self.type, types._NumberRangeBase)
# skip count with default range type
and not (self.count and self.type.min == 0 and self.type.max is None)
):
range_str = self.type._describe_range()

if range_str:
Expand Down
12 changes: 10 additions & 2 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,21 @@ def cmd(username):
(click.IntRange(max=32), "x<=32"),
],
)
def test_intrange_default_help_text(runner, type, expect):
option = click.Option(["--count"], type=type, show_default=True, default=2)
def test_intrange_default_help_text(type, expect):
option = click.Option(["--num"], type=type, show_default=True, default=2)
context = click.Context(click.Command("test"))
result = option.get_help_record(context)[1]
assert expect in result


def test_count_default_type_help():
"""A count option with the default type should not show >=0 in help."""
option = click.Option(["--couunt"], count=True, help="some words")
context = click.Context(click.Command("test"))
result = option.get_help_record(context)[1]
assert result == "some words"


def test_toupper_envvar_prefix(runner):
@click.command()
@click.option("--arg")
Expand Down

0 comments on commit f74dbbb

Please sign in to comment.