add hidden --debug flag for controlling logging output

patch bump
This commit is contained in:
onyx-and-iris 2025-06-20 02:13:50 +01:00
parent 39f1b01926
commit e5040d5ddd
3 changed files with 44 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
#
# SPDX-License-Identifier: MIT
__version__ = "0.16.9"
__version__ = "0.16.10"

View File

@ -1,6 +1,7 @@
"""Command line interface for the OBS WebSocket API."""
import importlib
import logging
from typing import Annotated
import obsws_python as obsws
@ -44,6 +45,15 @@ def version_callback(value: bool):
raise typer.Exit()
def setup_logging(debug: bool):
"""Set up logging for the application."""
log_level = logging.DEBUG if debug else logging.CRITICAL
logging.basicConfig(
level=log_level,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)
@app.callback()
def main(
ctx: typer.Context,
@ -60,7 +70,11 @@ def main(
port: Annotated[
int,
typer.Option(
'--port', '-P', envvar='OBS_PORT', help='WebSocket port', show_default=4455
'--port',
'-P',
envvar='OBS_PORT',
help='WebSocket port',
show_default=4455,
),
] = settings.get('port'),
password: Annotated[
@ -94,6 +108,19 @@ def main(
callback=version_callback,
),
] = False,
debug: Annotated[
bool,
typer.Option(
'--debug',
'-d',
envvar='OBS_DEBUG',
is_eager=True,
help='Enable debug logging',
show_default=False,
callback=setup_logging,
hidden=True,
),
] = settings.get('debug'),
):
"""obsws_cli is a command line interface for the OBS WebSocket API."""
ctx.obj = ctx.with_resource(obsws.ReqClient(**ctx.params))

View File

@ -22,6 +22,8 @@ class Settings(UserDict):
"""
PREFIX = 'OBS_'
def __init__(self, *args, **kwargs):
"""Initialize the Settings object."""
kwargs.update(
@ -34,19 +36,25 @@ class Settings(UserDict):
def __getitem__(self, key: str) -> SettingsValue:
"""Get a setting value by key."""
if not key.startswith('OBS_'):
key = f'OBS_{key}'
return self.data[key.upper()]
key = key.upper()
if not key.startswith(Settings.PREFIX):
key = f'{Settings.PREFIX}{key}'
return self.data[key]
def __setitem__(self, key: str, value: SettingsValue):
"""Set a setting value by key."""
if not key.startswith('OBS_'):
key = f'OBS_{key}'
self.data[key.upper()] = value
key = key.upper()
if not key.startswith(Settings.PREFIX):
key = f'{Settings.PREFIX}{key}'
self.data[key] = value
_settings = Settings(
OBS_HOST='localhost', OBS_PORT=4455, OBS_PASSWORD='', OBS_TIMEOUT=5
OBS_HOST='localhost',
OBS_PORT=4455,
OBS_PASSWORD='',
OBS_TIMEOUT=5,
OBS_DEBUG=False,
)