diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-29 16:08:04 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-29 16:08:04 +0300 |
| commit | 5686cf61469e638c87cacfdeee192fda991cb0c0 (patch) | |
| tree | a9287f89f08c350eccef6a368761dc03b4f36582 /examples | |
| parent | f216136c111fed140b897da35037ce1541219fe5 (diff) | |
| parent | e92919ce1b402e024933528f99e4c13b065f19fa (diff) | |
Merge branch 'main' into rework-severity-calculation
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 |
