diff --git a/obsws_cli/__about__.py b/obsws_cli/__about__.py index 2525e84..fb70b53 100644 --- a/obsws_cli/__about__.py +++ b/obsws_cli/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2025-present onyx-and-iris # # SPDX-License-Identifier: MIT -__version__ = "0.16.9" +__version__ = "0.16.10" diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 36b2b0c..b17bd32 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -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)) diff --git a/obsws_cli/settings.py b/obsws_cli/settings.py index 47164a0..f784aea 100644 --- a/obsws_cli/settings.py +++ b/obsws_cli/settings.py @@ -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, )