Skip to content

Commit

Permalink
Show suricata-check version on help action
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen1999 committed Jan 18, 2025
1 parent 1d22203 commit 19dd384
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion suricata_check/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_version() -> str:
git_dir = os.path.join(SURICATA_CHECK_DIR, "..", ".git")
if os.path.exists(git_dir):
try:
v = setuptools_git_versioning.get_version()
v = str(setuptools_git_versioning.get_version())
_logger.debug("Detected suricata-check version using setuptools_git_versioning: %s", v)
except: # noqa: E722
v = __get_git_revision_short_hash()
Expand Down
3 changes: 2 additions & 1 deletion suricata_check/suricata_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from suricata_check import __version__, get_dependency_versions # noqa: E402
from suricata_check.checkers.interface import CheckerInterface # noqa: E402
from suricata_check.checkers.interface.dummy import DummyChecker # noqa: E402
from suricata_check.utils._click import ClickHandler # noqa: E402
from suricata_check.utils._click import ClickHandler, ClickHelpOption # noqa: E402
from suricata_check.utils._path import find_rules_file # noqa: E402
from suricata_check.utils.checker import check_rule_option_recognition # noqa: E402
from suricata_check.utils.checker_typing import ( # noqa: E402
Expand Down Expand Up @@ -153,6 +153,7 @@
show_default=True,
multiple=True,
)
@click.help_option("-h", "--help", cls=ClickHelpOption)
def main( # noqa: PLR0913, PLR0915
rules: str = ".",
single_rule: Optional[str] = None,
Expand Down
10 changes: 10 additions & 0 deletions suricata_check/utils/_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

import click

from suricata_check._version import get_version


class ClickHelpOption(click.HelpOption):
@staticmethod
def show_help(ctx: click.Context, param: click.Parameter, value: bool) -> None:
click.echo("suricata-check {}\n".format(get_version()))

click.HelpOption.show_help(ctx, param, value)


class ClickHandler(logging.Handler):
"""Handler to color and write logging messages for the click module."""
Expand Down

0 comments on commit 19dd384

Please sign in to comment.