Skip to content

Commit

Permalink
Merge pull request #51 from Res260/verboseerrorconvert
Browse files Browse the repository at this point in the history
Add a `--verbose` option to `sigma convert`.
  • Loading branch information
thomaspatzke committed Jul 7, 2024
2 parents 308eb0a + a8e50a6 commit d4ad467
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions sigma/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Sequence

import click

from sigma.cli.rules import load_rules
from sigma.conversion.base import Backend
from sigma.exceptions import (
SigmaError,
Expand All @@ -12,8 +14,6 @@
)
from sigma.plugins import InstalledSigmaPlugins

from sigma.cli.rules import load_rules

plugins = InstalledSigmaPlugins.autodiscover()
backends = plugins.backends
pipelines = plugins.pipelines
Expand Down Expand Up @@ -163,6 +163,14 @@ def fail(self, message: str, param, ctx):
required=True,
type=click.Path(exists=True, allow_dash=True, path_type=pathlib.Path),
)
@click.option(
"--verbose",
required=False,
is_flag=True,
default=False,
type=click.BOOL,
help="Verbose output.",
)
def convert(
target,
pipeline,
Expand All @@ -178,6 +186,7 @@ def convert(
backend_option,
input,
file_pattern,
verbose,
):
"""
Convert Sigma rules into queries. INPUT can be multiple files or directories. This command automatically recurses
Expand Down Expand Up @@ -321,9 +330,17 @@ def convert(
f"Backend returned unexpected format {str(type(result))}"
)
except SigmaError as e:
raise click.ClickException("Error while conversion: " + str(e))
if verbose:
click.echo('Error while converting')
raise e
else:
raise click.ClickException("Error while converting: " + str(e))
except NotImplementedError as e:
raise click.ClickException("Feature required for conversion of Sigma rule is not supported by backend: " + str(e))
if verbose:
click.echo('Feature required for conversion of Sigma rule is not supported by backend')
raise e
else:
raise click.ClickException("Feature required for conversion of Sigma rule is not supported by backend: " + str(e))

if len(backend.errors) > 0:
click.echo("\nIgnored errors:", err=True)
Expand Down

0 comments on commit d4ad467

Please sign in to comment.