Skip to content

Commit

Permalink
reinstate CommandCollection support
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Oct 7, 2023
1 parent 5b09dc2 commit 93213e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rich_click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# We need to manually import these instead of `from click import *` to force mypy to recognize a few type annotation overrides for the rich_click decorators.
from click.core import Argument as Argument
from click.core import Command as Command
from click.core import CommandCollection as CommandCollection
from click.core import Context as Context
from click.core import Group as Group
from click.core import Option as Option
Expand Down Expand Up @@ -76,6 +77,7 @@
from rich_click.decorators import pass_context as pass_context
from rich_click.decorators import rich_config as rich_config
from rich_click.rich_command import RichCommand as RichCommand
from rich_click.rich_command import RichCommandCollection as RichCommandCollection
from rich_click.rich_command import RichGroup as RichGroup
from rich_click.rich_context import RichContext as RichContext
from rich_click.rich_help_configuration import RichHelpConfiguration as RichHelpConfiguration
Expand Down
14 changes: 14 additions & 0 deletions src/rich_click/rich_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,17 @@ def command(
# (The command_class ClassVar was not added until 8.0.)
kwargs.setdefault("cls", self.command_class)
return super().command(*args, **kwargs) # type: ignore[no-any-return]


class RichCommandCollection(RichGroup, click.CommandCollection):
"""Richly formatted click CommandCollection.
Inherits click.CommandCollection and overrides help and error methods
to print richly formatted output.
"""

@wraps(click.CommandCollection.__init__)
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Initialize RichCommandCollection class."""
click.CommandCollection.__init__(self, *args, **kwargs)
self._register_rich_context_settings_from_callback()

0 comments on commit 93213e0

Please sign in to comment.