Skip to content

Commit

Permalink
Merge pull request #37 from frack113/color_cli
Browse files Browse the repository at this point in the history
Add Color to check issue output
  • Loading branch information
thomaspatzke authored Dec 8, 2023
2 parents 98b3bff + fcd26b3 commit f1dc6db
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion sigma/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from sys import stderr
from textwrap import fill

from dataclasses import fields

import click
from prettytable import PrettyTable

Expand All @@ -14,6 +16,8 @@
plugins = InstalledSigmaPlugins.autodiscover()
validators = plugins.validators

severity_color = {"low": "green", "medium": "yellow", "high": "red"}


@click.command()
@click.option(
Expand Down Expand Up @@ -123,7 +127,38 @@ def check(
if issue_count > 0:
click.echo("=== Issues ===")
for issue in issues:
click.echo(issue)
# Need to split SigmaValidationIssue __str__
rules = ", ".join(
[
str(rule.source)
if rule.source is not None
else str(rule.id) or rule.title
for rule in issue.rules
]
)
additional_fields = " ".join(
[
f"{field.name}={click.style(issue.__getattribute__(field.name) or '-', bold=True, fg='blue')}"
for field in fields(issue)
if field.name not in ("rules", "severity", "description")
]
)

click.echo(
"issue="
+ click.style(issue.__class__.__name__, bold=True, fg="cyan")
+ " severity="
+ click.style(
issue.severity.name.lower(),
bold=True,
fg=severity_color[issue.severity.name.lower()],
)
+ " description="
+ click.style(issue.description, bold=True, fg="blue")
+ " rule="
+ click.style(rules, bold=True, fg="blue")
+ f" {additional_fields}"
)
issue_counter.update((issue.__class__,))

# TODO: From Python 3.10 the commented line below can be used.
Expand Down

0 comments on commit f1dc6db

Please sign in to comment.