Debian Codegraph @

src/rich_click/rich_group.py

raw
1 import sys
2
3 import click
4
5 from rich_click.rich_click import rich_abort_error, rich_format_error, rich_format_help
6 from rich_click.rich_command import RichCommand
7
8
9 class RichGroup(click.Group):
10 """Richly formatted click Group.
11
12 Inherits click.Group and overrides help and error methods
13 to print richly formatted output.
14 """
15
16 command_class = RichCommand
17 group_class = type
18
19 def main(self, *args, standalone_mode: bool = True, **kwargs):
20 try:
21 rv = super().main(*args, standalone_mode=False, **kwargs)
22 if not standalone_mode:
23 return rv
24 except click.ClickException as e:
25 if not standalone_mode:
26 raise
27 rich_format_error(e)
28 sys.exit(e.exit_code)
29 except click.exceptions.Abort:
30 if not standalone_mode:
31 raise
32 rich_abort_error()
33 sys.exit(1)
34
35 def format_help(self, ctx: click.Context, formatter: click.HelpFormatter):
36 rich_format_help(self, ctx, formatter)