mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-27 22:10:29 +01:00
add hidden --debug flag for controlling logging output
patch bump
This commit is contained in:
parent
39f1b01926
commit
e5040d5ddd
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
__version__ = "0.16.9"
|
__version__ = "0.16.10"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Command line interface for the OBS WebSocket API."""
|
"""Command line interface for the OBS WebSocket API."""
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import logging
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
import obsws_python as obsws
|
import obsws_python as obsws
|
||||||
@ -44,6 +45,15 @@ def version_callback(value: bool):
|
|||||||
raise typer.Exit()
|
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()
|
@app.callback()
|
||||||
def main(
|
def main(
|
||||||
ctx: typer.Context,
|
ctx: typer.Context,
|
||||||
@ -60,7 +70,11 @@ def main(
|
|||||||
port: Annotated[
|
port: Annotated[
|
||||||
int,
|
int,
|
||||||
typer.Option(
|
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'),
|
] = settings.get('port'),
|
||||||
password: Annotated[
|
password: Annotated[
|
||||||
@ -94,6 +108,19 @@ def main(
|
|||||||
callback=version_callback,
|
callback=version_callback,
|
||||||
),
|
),
|
||||||
] = False,
|
] = 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."""
|
"""obsws_cli is a command line interface for the OBS WebSocket API."""
|
||||||
ctx.obj = ctx.with_resource(obsws.ReqClient(**ctx.params))
|
ctx.obj = ctx.with_resource(obsws.ReqClient(**ctx.params))
|
||||||
|
@ -22,6 +22,8 @@ class Settings(UserDict):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
PREFIX = 'OBS_'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize the Settings object."""
|
"""Initialize the Settings object."""
|
||||||
kwargs.update(
|
kwargs.update(
|
||||||
@ -34,19 +36,25 @@ class Settings(UserDict):
|
|||||||
|
|
||||||
def __getitem__(self, key: str) -> SettingsValue:
|
def __getitem__(self, key: str) -> SettingsValue:
|
||||||
"""Get a setting value by key."""
|
"""Get a setting value by key."""
|
||||||
if not key.startswith('OBS_'):
|
key = key.upper()
|
||||||
key = f'OBS_{key}'
|
if not key.startswith(Settings.PREFIX):
|
||||||
return self.data[key.upper()]
|
key = f'{Settings.PREFIX}{key}'
|
||||||
|
return self.data[key]
|
||||||
|
|
||||||
def __setitem__(self, key: str, value: SettingsValue):
|
def __setitem__(self, key: str, value: SettingsValue):
|
||||||
"""Set a setting value by key."""
|
"""Set a setting value by key."""
|
||||||
if not key.startswith('OBS_'):
|
key = key.upper()
|
||||||
key = f'OBS_{key}'
|
if not key.startswith(Settings.PREFIX):
|
||||||
self.data[key.upper()] = value
|
key = f'{Settings.PREFIX}{key}'
|
||||||
|
self.data[key] = value
|
||||||
|
|
||||||
|
|
||||||
_settings = Settings(
|
_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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user