mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-08-03 10:31:46 +00:00
remove alias, settings
This commit is contained in:
parent
2ef89be184
commit
436e4d5345
@ -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
|
@ -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]
|
Loading…
x
Reference in New Issue
Block a user