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

View File

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