Skip to content

kamihi.cli.commands.run ⚓︎

Kamihi framework project execution.

License

MIT

Functions:

Name Description
host_callback

Ensure the host value is valid.

run

Run a project with the Kamihi framework.

host_callback ⚓︎

host_callback(value: str | None) -> str | None

Ensure the host value is valid.

Parameters:

Name Type Description Default

value ⚓︎

str | None

The host value.

required

Returns:

Type Description
str | None

str | None: The validated host value.

Source code in src/kamihi/cli/commands/run.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def host_callback(
    value: str | None,
) -> str | None:
    """
    Ensure the host value is valid.

    Args:
        value (str | None): The host value.

    Returns:
        str | None: The validated host value.

    """
    if value and isinstance(hostname(value, may_have_port=False), ValidationError):
        raise typer.BadParameter("Invalid host value")
    return value

run ⚓︎

run(
    ctx: Context,
    log_level: Annotated[
        LogLevel | None,
        Option(
            --log - level,
            -l,
            help="Set the logging level for console loggers.",
            show_default=INFO,
        ),
    ] = None,
    web_host: Annotated[
        str | None,
        Option(
            ...,
            --host,
            -h,
            help="Host of the admin web panel",
            callback=host_callback,
            show_default=localhost,
        ),
    ] = None,
    web_port: Annotated[
        int | None,
        Option(
            ...,
            --port,
            -p,
            help="Port of the admin web panel",
            min=1024,
            max=65535,
            show_default=4242,
        ),
    ] = None,
) -> None

Run a project with the Kamihi framework.

Source code in src/kamihi/cli/commands/run.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@app.command()
def run(
    ctx: typer.Context,
    log_level: Annotated[
        LogLevel | None,
        typer.Option(
            "--log-level", "-l", help="Set the logging level for console loggers.", show_default=LogLevel.INFO
        ),
    ] = None,
    web_host: Annotated[
        str | None,
        typer.Option(
            ..., "--host", "-h", help="Host of the admin web panel", callback=host_callback, show_default="localhost"
        ),
    ] = None,
    web_port: Annotated[
        int | None,
        typer.Option(..., "--port", "-p", help="Port of the admin web panel", min=1024, max=65535, show_default="4242"),
    ] = None,
) -> None:
    """Run a project with the Kamihi framework."""
    settings = get_settings()
    if web_host:
        settings.web.host = web_host
    if web_port:
        settings.web.port = web_port
    if log_level:
        settings.log.stdout_level = log_level
        settings.log.stderr_level = log_level
        settings.log.file_level = log_level
        settings.log.notification_level = log_level

    # Ignore the "If 'per_message=False', ..." warning for CallbackQueryHandler
    # https://github.com/python-telegram-bot/python-telegram-bot/wiki/Frequently-Asked-Questions#what-do-the-per_-settings-in-conversationhandler-do
    filterwarnings(action="ignore", message=r".*CallbackQueryHandler", category=PTBUserWarning)

    bot = init_bot()

    import_questions(ctx.obj.cwd / "questions")
    import_actions(ctx.obj.cwd / "actions")
    logger.bind(folder=str(ctx.obj.cwd / "actions")).debug("Imported actions")

    bot.start()