Debian Codegraph @

src/rich_click/__init__.py

raw
1 """
2 rich-click is a minimal Python module to combine the efforts of the excellent packages 'rich' and 'click'.
3
4 The intention is to provide attractive help output from click, formatted with rich, with minimal
5 customisation required.
6 """
7
8 __version__ = "1.6.0"
9
10 from typing import TYPE_CHECKING
11
12 from click import * # noqa: F401, F403
13 from click import command as click_command
14 from click import group as click_group
15
16 from . import rich_click # noqa: F401
17
18 from rich_click.rich_command import RichCommand
19 from rich_click.rich_group import RichGroup
20
21 # MyPy does not like star imports. Therefore when we are type checking, we import each individual module
22 # from click here. This way MyPy will recognize the import and not throw any errors. Furthermore, because of
23 # the TYPE_CHECKING check, it does not influence the start routine at all.
24 if TYPE_CHECKING:
25 from click import argument, Choice, option, Path, version_option # noqa: F401
26
27 __all__ = [
28 "argument",
29 "Choice",
30 "option",
31 "Path",
32 "version_option",
33 "group",
34 "command",
35 ]
36
37
38 def group(*args, cls=RichGroup, **kwargs):
39 """
40 Group decorator function.
41
42 Defines the group() function so that it uses the RichGroup class by default.
43 """
44 return click_group(*args, cls=cls, **kwargs)
45
46
47 def command(name=None, cls=RichCommand, **attrs):
48 """
49 Command decorator function.
50
51 Defines the command() function so that it uses the RichCommand class by default.
52 """
53 if callable(name) and cls:
54 return click_command(cls=cls, **attrs)(name)
55
56 return click_command(name, cls=cls, **attrs)