From ed73cfbd95b9222c57950ff727397e251ebca247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 23:02:47 +0300 Subject: Refactor Formatters, use functional approach --- examples/custom_formatter.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/custom_formatter.py b/examples/custom_formatter.py index d3cb98d..f246404 100644 --- a/examples/custom_formatter.py +++ b/examples/custom_formatter.py @@ -3,21 +3,17 @@ from __future__ import annotations import robusta_krr -from robusta_krr.api.formatters import BaseFormatter +from robusta_krr.api import formatters from robusta_krr.api.models import Result -class CustomFormatter(BaseFormatter): - # This is the name that will be used to reference the formatter in the CLI - __display_name__ = "my_formatter" - - # This will pass the result to Rich Console for formatting. - # By default, the result is passed to `print` function. - # See https://rich.readthedocs.io/en/latest/ for more info - __rich_console__ = True - - def format(self, result: Result) -> str: - return "Custom formatter" +# This is a custom formatter +# It will be available to the CLI as `my_formatter` +# Rich console will be enabled in this case, so the output will be colored and formatted +@formatters.register(rich_console=True) +def my_formatter(result: Result) -> str: + # Return custom formatter + return "Custom formatter" # Running this file will register the formatter and make it available to the CLI -- cgit v1.2.3