rename Settings to Config

This commit is contained in:
onyx-and-iris 2026-01-09 09:39:19 +00:00
parent f7e51f8488
commit 356684e5d4
2 changed files with 29 additions and 29 deletions

View File

@ -9,7 +9,7 @@ import typer
from obsws_cli.__about__ import __version__ as version
from . import console, settings, styles
from . import config, console, styles
from .alias import RootTyperAliasGroup
app = typer.Typer(cls=RootTyperAliasGroup)
@ -72,7 +72,7 @@ def main(
help='WebSocket host',
show_default='localhost',
),
] = settings.get('host'),
] = config.get('host'),
port: Annotated[
int,
typer.Option(
@ -82,7 +82,7 @@ def main(
help='WebSocket port',
show_default=4455,
),
] = settings.get('port'),
] = config.get('port'),
password: Annotated[
str,
typer.Option(
@ -92,7 +92,7 @@ def main(
help='WebSocket password',
show_default=False,
),
] = settings.get('password'),
] = config.get('password'),
timeout: Annotated[
int,
typer.Option(
@ -102,7 +102,7 @@ def main(
help='WebSocket timeout',
show_default=5,
),
] = settings.get('timeout'),
] = config.get('timeout'),
style: Annotated[
str,
typer.Option(
@ -113,7 +113,7 @@ def main(
show_default='disabled',
callback=validate_style,
),
] = settings.get('style'),
] = config.get('style'),
no_border: Annotated[
bool,
typer.Option(
@ -123,7 +123,7 @@ def main(
help='Disable table border styling in the CLI output',
show_default=False,
),
] = settings.get('style_no_border'),
] = config.get('style_no_border'),
version: Annotated[
bool,
typer.Option(
@ -147,7 +147,7 @@ def main(
callback=setup_logging,
hidden=True,
),
] = settings.get('debug'),
] = config.get('debug'),
):
"""obsws_cli is a command line interface for the OBS WebSocket API."""
ctx.ensure_object(dict)

View File

@ -5,21 +5,21 @@ from pathlib import Path
from dotenv import dotenv_values
SettingsValue = str | int
ConfigValue = str | int
class Settings(UserDict):
"""A class to manage settings for obsws-cli.
class Config(UserDict):
"""A class to manage config 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_'.
This class extends UserDict to provide a dictionary-like interface for config.
It loads config from environment variables and .env files.
The config values are expected to be in uppercase and should start with 'OBS_'.
Example:
-------
settings = Settings()
host = settings['OBS_HOST']
settings['OBS_PORT'] = 4455
config = Config()
host = config['OBS_HOST']
config['OBS_PORT'] = 4455
"""
@ -35,22 +35,22 @@ class Settings(UserDict):
)
super().__init__(*args, **kwargs)
def __getitem__(self, key: str) -> SettingsValue:
def __getitem__(self, key: str) -> ConfigValue:
"""Get a setting value by key."""
key = key.upper()
if not key.startswith(Settings.PREFIX):
key = f'{Settings.PREFIX}{key}'
if not key.startswith(Config.PREFIX):
key = f'{Config.PREFIX}{key}'
return self.data[key]
def __setitem__(self, key: str, value: SettingsValue):
def __setitem__(self, key: str, value: ConfigValue):
"""Set a setting value by key."""
key = key.upper()
if not key.startswith(Settings.PREFIX):
key = f'{Settings.PREFIX}{key}'
if not key.startswith(Config.PREFIX):
key = f'{Config.PREFIX}{key}'
self.data[key] = value
_settings = Settings(
_config = Config(
OBS_HOST='localhost',
OBS_PORT=4455,
OBS_PASSWORD='',
@ -61,20 +61,20 @@ _settings = Settings(
)
def get(key: str) -> SettingsValue:
def get(key: str) -> ConfigValue:
"""Get a setting value by key.
Args:
----
key (str): The key of the setting to retrieve.
key (str): The key of the config to retrieve.
Returns:
-------
The value of the setting.
The value of the config.
Raises:
------
KeyError: If the key does not exist in the settings.
KeyError: If the key does not exist in the config.
"""
return _settings[key]
return _config[key]