From dae982cff675007178a810f125df1f591257837e Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 24 Nov 2024 23:16:52 +0530 Subject: [PATCH] fix/exception-in-console --- src/rich_click/rich_command.py | 8 ++++---- src/rich_click/rich_context.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rich_click/rich_command.py b/src/rich_click/rich_command.py index a3f9d3e..7cbfa34 100644 --- a/src/rich_click/rich_command.py +++ b/src/rich_click/rich_command.py @@ -167,10 +167,10 @@ def main( if not standalone_mode: raise if ctx is not None: - config = ctx.help_config + formatter = ctx.formatter else: config = self._generate_rich_help_config() - formatter = self.context_class.formatter_class(config=config, file=sys.stderr) + formatter = self.context_class.formatter_class(config=config, file=sys.stderr) from rich_click.rich_help_rendering import rich_format_error rich_format_error(e, formatter) @@ -192,10 +192,10 @@ def main( raise try: if ctx is not None: - config = ctx.help_config + formatter = ctx.formatter else: config = self._generate_rich_help_config() - formatter = self.context_class.formatter_class(config=config) + formatter = self.context_class.formatter_class(config=config) except Exception: click.echo("Aborted!", file=sys.stderr) else: diff --git a/src/rich_click/rich_context.py b/src/rich_click/rich_context.py index dad0eab..c3447cd 100644 --- a/src/rich_click/rich_context.py +++ b/src/rich_click/rich_context.py @@ -64,6 +64,8 @@ def __init__( else: self.help_config = rich_help_config + self.formatter = self.make_formatter() + def make_formatter(self) -> RichHelpFormatter: """Create the Rich Help Formatter.""" formatter = self.formatter_class(