Skip to content

Commit

Permalink
Use LocaleResolver in monrun_checks_keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaroff committed Aug 3, 2023
1 parent c6a4f5f commit ea6de1b
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/ch_tools/monrun_checks_keeper/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import logging
import os
from functools import wraps
from typing import Optional

import click
from click import group, option, pass_context
import cloup

from ch_tools import __version__
from ch_tools.common.cli.context_settings import CONTEXT_SETTINGS
from ch_tools.common.cli.locale_resolver import LocaleResolver
from ch_tools.common.result import Status
from ch_tools.monrun_checks_keeper.keeper_commands import (
alive_command,
Expand All @@ -22,12 +26,18 @@
LOG_FILE = "/var/log/keeper-monitoring/keeper-monitoring.log"


class KeeperChecks(click.Group):
def add_command(self, cmd, name=None):
class KeeperChecks(cloup.Group):
def add_command(
self,
cmd: click.Command,
name: Optional[str] = None,
section: Optional[cloup.Section] = None,
fallback_to_default_section: bool = True,
):
cmd_callback = cmd.callback

@wraps(cmd_callback)
@click.pass_context
@cloup.pass_context
def wrapper(ctx, *a, **kw):
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
logging.basicConfig(
Expand Down Expand Up @@ -58,28 +68,39 @@ def wrapper(ctx, *a, **kw):
status.report()

cmd.callback = wrapper
super().add_command(cmd, name=name)
super().add_command(
cmd,
name=name,
section=section,
fallback_to_default_section=fallback_to_default_section,
)


@group(cls=KeeperChecks, context_settings={"help_option_names": ["-h", "--help"]})
@option("-r", "--retries", "retries", type=int, default=3, help="Number of retries")
@option(
@cloup.group(
cls=KeeperChecks,
context_settings=CONTEXT_SETTINGS,
)
@cloup.option(
"-r", "--retries", "retries", type=int, default=3, help="Number of retries"
)
@cloup.option(
"-t",
"--timeout",
"timeout",
type=float,
default=0.5,
help="Connection timeout (in seconds)",
)
@option(
@cloup.option(
"-n",
"--no-verify-ssl-certs",
"no_verify_ssl_certs",
is_flag=True,
default=False,
help="Allow unverified SSL certificates, e.g. self-signed ones",
)
@pass_context
@cloup.version_option(__version__)
@cloup.pass_context
def cli(ctx, retries, timeout, no_verify_ssl_certs):
ctx.obj = dict(
retries=retries, timeout=timeout, no_verify_ssl_certs=no_verify_ssl_certs
Expand Down Expand Up @@ -108,5 +129,9 @@ def main():
"""
Program entry point.
"""
# pylint: disable=no-value-for-parameter
cli()
LocaleResolver.resolve()
cli.main()


if __name__ == "__main__":
main()

0 comments on commit ea6de1b

Please sign in to comment.