Skip to content

Commit

Permalink
Handle incompatabilities with click v7, require >= v7
Browse files Browse the repository at this point in the history
See #16
  • Loading branch information
ewels committed Feb 28, 2022
1 parent 8378cdd commit 646b8ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Added support for `HEADER_TEXT` and `FOOTER_TEXT` to go before and after help output
- Catch Abort exceptions from `cmd+c` and print nicely using `ABORTED_TEXT`
- Handle missing `click.types._NumberRangeBase` in click 7x
- Require at least click v7.0 (released 2018)

## Version 1.0.0 (2022-02-18)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name="rich-click",
install_requires=[
"click",
"click>=7.0",
"rich",
],
)
12 changes: 8 additions & 4 deletions src/rich_click/rich_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,18 @@ def rich_format_help(obj, ctx, formatter):
metavar.append(metavar_str)

# Range - from https://github.com/pallets/click/blob/c63c70dabd3f86ca68678b4f00951f78f52d0270/src/click/core.py#L2698-L2706
if (
try:
if (
isinstance(param.type, click.types._NumberRangeBase)
# skip count with default range type
and not (param.count and param.type.min == 0 and param.type.max is None)
):
range_str = param.type._describe_range()
if range_str:
metavar.append(RANGE_STRING.format(range_str))
range_str = param.type._describe_range()
if range_str:
metavar.append(RANGE_STRING.format(range_str))
except AttributeError:
# click.types._NumberRangeBase is only in Click 8x onwards
pass

# Required asterisk
required = ""
Expand Down

0 comments on commit 646b8ff

Please sign in to comment.