mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-07 20:20:32 +01:00
ensure set/get both enforce OBS_ prefix
add class docstring patch bump
This commit is contained in:
parent
ab71414d27
commit
0bcfc2ae14
@ -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.2"
|
__version__ = "0.16.3"
|
||||||
|
@ -56,13 +56,13 @@ def main(
|
|||||||
help='WebSocket host',
|
help='WebSocket host',
|
||||||
show_default='localhost',
|
show_default='localhost',
|
||||||
),
|
),
|
||||||
] = settings.get('OBS_HOST'),
|
] = settings.get('host'),
|
||||||
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('OBS_PORT'),
|
] = settings.get('port'),
|
||||||
password: Annotated[
|
password: Annotated[
|
||||||
str,
|
str,
|
||||||
typer.Option(
|
typer.Option(
|
||||||
@ -72,7 +72,7 @@ def main(
|
|||||||
help='WebSocket password',
|
help='WebSocket password',
|
||||||
show_default='',
|
show_default='',
|
||||||
),
|
),
|
||||||
] = settings.get('OBS_PASSWORD'),
|
] = settings.get('password'),
|
||||||
timeout: Annotated[
|
timeout: Annotated[
|
||||||
int,
|
int,
|
||||||
typer.Option(
|
typer.Option(
|
||||||
@ -82,7 +82,7 @@ def main(
|
|||||||
help='WebSocket timeout',
|
help='WebSocket timeout',
|
||||||
show_default=5,
|
show_default=5,
|
||||||
),
|
),
|
||||||
] = settings.get('OBS_TIMEOUT'),
|
] = settings.get('timeout'),
|
||||||
version: Annotated[
|
version: Annotated[
|
||||||
bool,
|
bool,
|
||||||
typer.Option(
|
typer.Option(
|
||||||
|
@ -5,9 +5,22 @@ from pathlib import Path
|
|||||||
|
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
|
|
||||||
|
SettingsValue = str | int
|
||||||
|
|
||||||
|
|
||||||
class Settings(UserDict):
|
class Settings(UserDict):
|
||||||
"""Settings for the OBS WebSocket client."""
|
"""A class to manage settings for obsws-cli.
|
||||||
|
|
||||||
|
This class extends UserDict to provide a dictionary-like interface for settings.
|
||||||
|
It loads settings from environment variables and .env files.
|
||||||
|
The settings are expected to be in uppercase and should start with 'OBS_'.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
settings = Settings()
|
||||||
|
host = settings['OBS_HOST']
|
||||||
|
settings['OBS_PORT'] = 4455
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize the Settings object."""
|
"""Initialize the Settings object."""
|
||||||
@ -19,15 +32,17 @@ class Settings(UserDict):
|
|||||||
)
|
)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key: str) -> SettingsValue:
|
||||||
"""Get a setting value by key."""
|
"""Get a setting value by key."""
|
||||||
if not key.startswith('OBS_'):
|
if not key.startswith('OBS_'):
|
||||||
key = f'OBS_{key.upper()}'
|
key = f'OBS_{key}'
|
||||||
return self.data[key]
|
return self.data[key.upper()]
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key: str, value: SettingsValue):
|
||||||
"""Set a setting value by key."""
|
"""Set a setting value by key."""
|
||||||
self.data[key] = value
|
if not key.startswith('OBS_'):
|
||||||
|
key = f'OBS_{key}'
|
||||||
|
self.data[key.upper()] = value
|
||||||
|
|
||||||
|
|
||||||
_settings = Settings(
|
_settings = Settings(
|
||||||
@ -35,7 +50,7 @@ _settings = Settings(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get(key: str):
|
def get(key: str) -> SettingsValue:
|
||||||
"""Get a setting value by key.
|
"""Get a setting value by key.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user