diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-26 23:02:47 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-26 23:02:47 +0300 |
| commit | ed73cfbd95b9222c57950ff727397e251ebca247 (patch) | |
| tree | 3c0bd4a24db102f73a9843cea5e63ebd0b77e056 /examples | |
| parent | 0609ae5b62947b0d55505dec23b9b4d3a5909d89 (diff) | |
Refactor Formatters, use functional approach
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/custom_formatter.py | 20 |
1 files changed, 8 insertions, 12 deletions
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 |
