From 436e4d5345a06e0233ad36bb8272bd38b08cbe34 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 24 Jul 2025 04:21:40 +0100 Subject: [PATCH] remove alias, settings --- obsws_cli/alias.py | 73 --------------------------------------- obsws_cli/settings.py | 80 ------------------------------------------- 2 files changed, 153 deletions(-) delete mode 100644 obsws_cli/alias.py delete mode 100644 obsws_cli/settings.py diff --git a/obsws_cli/alias.py b/obsws_cli/alias.py deleted file mode 100644 index 359891d..0000000 --- a/obsws_cli/alias.py +++ /dev/null @@ -1,73 +0,0 @@ -"""module defining a custom group class for handling command name aliases.""" - -import re - -import typer - - -class RootTyperAliasGroup(typer.core.TyperGroup): - """A custom group class to handle command name aliases for the root typer.""" - - def __init__(self, *args, **kwargs): - """Initialize the AliasGroup.""" - super().__init__(*args, **kwargs) - self.no_args_is_help = True - - def get_command(self, ctx, cmd_name): - """Get a command by name.""" - match cmd_name: - case 'f': - cmd_name = 'filter' - case 'g': - cmd_name = 'group' - case 'hk': - cmd_name = 'hotkey' - case 'i': - cmd_name = 'input' - case 'prf': - cmd_name = 'profile' - case 'prj': - cmd_name = 'projector' - case 'rc': - cmd_name = 'record' - case 'rb': - cmd_name = 'replaybuffer' - case 'sc': - cmd_name = 'scene' - case 'scc': - cmd_name = 'scenecollection' - case 'si': - cmd_name = 'sceneitem' - case 'ss': - cmd_name = 'screenshot' - case 'st': - cmd_name = 'stream' - case 'sm': - cmd_name = 'studiomode' - case 't': - cmd_name = 'text' - case 'vc': - cmd_name = 'virtualcam' - return super().get_command(ctx, cmd_name) - - -class SubTyperAliasGroup(typer.core.TyperGroup): - """A custom group class to handle command name aliases for sub typers.""" - - _CMD_SPLIT_P = re.compile(r' ?[,|] ?') - - def __init__(self, *args, **kwargs): - """Initialize the AliasGroup.""" - super().__init__(*args, **kwargs) - self.no_args_is_help = True - - def get_command(self, ctx, cmd_name): - """Get a command by name.""" - cmd_name = self._group_cmd_name(cmd_name) - return super().get_command(ctx, cmd_name) - - def _group_cmd_name(self, default_name): - for cmd in self.commands.values(): - if cmd.name and default_name in self._CMD_SPLIT_P.split(cmd.name): - return cmd.name - return default_name diff --git a/obsws_cli/settings.py b/obsws_cli/settings.py deleted file mode 100644 index e2085bc..0000000 --- a/obsws_cli/settings.py +++ /dev/null @@ -1,80 +0,0 @@ -"""module for settings management for obsws-cli.""" - -from collections import UserDict -from pathlib import Path - -from dotenv import dotenv_values - -SettingsValue = str | int - - -class Settings(UserDict): - """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 - - """ - - PREFIX = 'OBS_' - - def __init__(self, *args, **kwargs): - """Initialize the Settings object.""" - kwargs.update( - { - **dotenv_values('.env'), - **dotenv_values(Path.home() / '.config' / 'obsws-cli' / 'obsws.env'), - } - ) - super().__init__(*args, **kwargs) - - def __getitem__(self, key: str) -> SettingsValue: - """Get a setting value by key.""" - 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.""" - 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_DEBUG=False, - OBS_STYLE='disabled', - OBS_STYLE_NO_BORDER=False, -) - - -def get(key: str) -> SettingsValue: - """Get a setting value by key. - - Args: - ---- - key (str): The key of the setting to retrieve. - - Returns: - ------- - The value of the setting. - - Raises: - ------ - KeyError: If the key does not exist in the settings. - - """ - return _settings[key]