use SettingsConfigDict

add Optional annotations

patch bump
This commit is contained in:
onyx-and-iris 2025-04-30 00:36:59 +01:00
parent 4b359cbfc0
commit fff41e1895
3 changed files with 34 additions and 32 deletions

View File

@ -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.10.0" __version__ = "0.10.1"

View File

@ -1,12 +1,11 @@
"""Command line interface for the OBS WebSocket API.""" """Command line interface for the OBS WebSocket API."""
from pathlib import Path from pathlib import Path
from typing import Annotated from typing import Annotated, Optional
import obsws_python as obsws import obsws_python as obsws
import typer import typer
from pydantic import ConfigDict from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic_settings import BaseSettings
from . import ( from . import (
group, group,
@ -27,7 +26,7 @@ from .alias import AliasGroup
class Settings(BaseSettings): class Settings(BaseSettings):
"""Settings for the OBS WebSocket client.""" """Settings for the OBS WebSocket client."""
model_config = ConfigDict( model_config = SettingsConfigDict(
env_file=( env_file=(
'.env', '.env',
Path.home() / '.config' / 'obsws-cli' / 'obsws.env', Path.home() / '.config' / 'obsws-cli' / 'obsws.env',
@ -71,10 +70,10 @@ def version(ctx: typer.Context):
@app.callback() @app.callback()
def main( def main(
ctx: typer.Context, ctx: typer.Context,
host: Annotated[str, typer.Option(help='WebSocket host')] = None, host: Annotated[Optional[str], typer.Option(help='WebSocket host')] = None,
port: Annotated[int, typer.Option(help='WebSocket port')] = None, port: Annotated[Optional[int], typer.Option(help='WebSocket port')] = None,
password: Annotated[str, typer.Option(help='WebSocket password')] = None, password: Annotated[Optional[str], typer.Option(help='WebSocket password')] = None,
timeout: Annotated[int, typer.Option(help='WebSocket timeout')] = None, timeout: Annotated[Optional[int], typer.Option(help='WebSocket timeout')] = None,
): ):
"""obsws_cli is a command line interface for the OBS WebSocket API.""" """obsws_cli is a command line interface for the OBS WebSocket API."""
settings = Settings() settings = Settings()

View File

@ -1,7 +1,7 @@
"""module containing commands for manipulating items in scenes.""" """module containing commands for manipulating items in scenes."""
from collections.abc import Callable from collections.abc import Callable
from typing import Annotated from typing import Annotated, Optional
import typer import typer
@ -34,7 +34,10 @@ def _validate_scene_name_and_item_name(
"""Validate the scene name and item name.""" """Validate the scene name and item name."""
def wrapper( def wrapper(
ctx: typer.Context, scene_name: str, item_name: str, parent: bool = False ctx: typer.Context,
scene_name: str,
item_name: str,
parent: Optional[str] = None,
): ):
if not validate.scene_in_scenes(ctx, scene_name): if not validate.scene_in_scenes(ctx, scene_name):
typer.echo(f"Scene '{scene_name}' not found.") typer.echo(f"Scene '{scene_name}' not found.")
@ -57,7 +60,7 @@ def _validate_scene_name_and_item_name(
def _get_scene_name_and_item_id( def _get_scene_name_and_item_id(
ctx: typer.Context, scene_name: str, item_name: str, parent: str ctx: typer.Context, scene_name: str, item_name: str, parent: Optional[str] = None
): ):
if parent: if parent:
resp = ctx.obj.get_group_scene_item_list(parent) resp = ctx.obj.get_group_scene_item_list(parent)
@ -82,7 +85,7 @@ def show(
ctx: typer.Context, ctx: typer.Context,
scene_name: str, scene_name: str,
item_name: str, item_name: str,
parent: Annotated[str, typer.Option(help='Parent group name')] = None, parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None,
): ):
"""Show an item in a scene.""" """Show an item in a scene."""
scene_name, scene_item_id = _get_scene_name_and_item_id( scene_name, scene_item_id = _get_scene_name_and_item_id(
@ -104,7 +107,7 @@ def hide(
ctx: typer.Context, ctx: typer.Context,
scene_name: str, scene_name: str,
item_name: str, item_name: str,
parent: Annotated[str, typer.Option(help='Parent group name')] = None, parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None,
): ):
"""Hide an item in a scene.""" """Hide an item in a scene."""
scene_name, scene_item_id = _get_scene_name_and_item_id( scene_name, scene_item_id = _get_scene_name_and_item_id(
@ -126,7 +129,7 @@ def toggle(
ctx: typer.Context, ctx: typer.Context,
scene_name: str, scene_name: str,
item_name: str, item_name: str,
parent: Annotated[str, typer.Option(help='Parent group name')] = None, parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None,
): ):
"""Toggle an item in a scene.""" """Toggle an item in a scene."""
if not validate.scene_in_scenes(ctx, scene_name): if not validate.scene_in_scenes(ctx, scene_name):
@ -169,7 +172,7 @@ def visible(
ctx: typer.Context, ctx: typer.Context,
scene_name: str, scene_name: str,
item_name: str, item_name: str,
parent: Annotated[str, typer.Option(help='Parent group name')] = None, parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None,
): ):
"""Check if an item in a scene is visible.""" """Check if an item in a scene is visible."""
if parent: if parent:
@ -211,51 +214,51 @@ def transform(
ctx: typer.Context, ctx: typer.Context,
scene_name: str, scene_name: str,
item_name: str, item_name: str,
parent: Annotated[str, typer.Option(help='Parent group name')] = None, parent: Annotated[Optional[str], typer.Option(help='Parent group name')] = None,
alignment: Annotated[ alignment: Annotated[
int, typer.Option(help='Alignment of the item in the scene') Optional[int], typer.Option(help='Alignment of the item in the scene')
] = None, ] = None,
bounds_alignment: Annotated[ bounds_alignment: Annotated[
int, typer.Option(help='Bounds alignment of the item in the scene') Optional[int], typer.Option(help='Bounds alignment of the item in the scene')
] = None, ] = None,
bounds_height: Annotated[ bounds_height: Annotated[
float, typer.Option(help='Height of the item in the scene') Optional[float], typer.Option(help='Height of the item in the scene')
] = None, ] = None,
bounds_type: Annotated[ bounds_type: Annotated[
str, typer.Option(help='Type of bounds for the item in the scene') Optional[str], typer.Option(help='Type of bounds for the item in the scene')
] = None, ] = None,
bounds_width: Annotated[ bounds_width: Annotated[
float, typer.Option(help='Width of the item in the scene') Optional[float], typer.Option(help='Width of the item in the scene')
] = None, ] = None,
crop_to_bounds: Annotated[ crop_to_bounds: Annotated[
bool, typer.Option(help='Crop the item to the bounds') Optional[bool], typer.Option(help='Crop the item to the bounds')
] = None, ] = None,
crop_bottom: Annotated[ crop_bottom: Annotated[
float, typer.Option(help='Bottom crop of the item in the scene') Optional[float], typer.Option(help='Bottom crop of the item in the scene')
] = None, ] = None,
crop_left: Annotated[ crop_left: Annotated[
float, typer.Option(help='Left crop of the item in the scene') Optional[float], typer.Option(help='Left crop of the item in the scene')
] = None, ] = None,
crop_right: Annotated[ crop_right: Annotated[
float, typer.Option(help='Right crop of the item in the scene') Optional[float], typer.Option(help='Right crop of the item in the scene')
] = None, ] = None,
crop_top: Annotated[ crop_top: Annotated[
float, typer.Option(help='Top crop of the item in the scene') Optional[float], typer.Option(help='Top crop of the item in the scene')
] = None, ] = None,
position_x: Annotated[ position_x: Annotated[
float, typer.Option(help='X position of the item in the scene') Optional[float], typer.Option(help='X position of the item in the scene')
] = None, ] = None,
position_y: Annotated[ position_y: Annotated[
float, typer.Option(help='Y position of the item in the scene') Optional[float], typer.Option(help='Y position of the item in the scene')
] = None, ] = None,
rotation: Annotated[ rotation: Annotated[
float, typer.Option(help='Rotation of the item in the scene') Optional[float], typer.Option(help='Rotation of the item in the scene')
] = None, ] = None,
scale_x: Annotated[ scale_x: Annotated[
float, typer.Option(help='X scale of the item in the scene') Optional[float], typer.Option(help='X scale of the item in the scene')
] = None, ] = None,
scale_y: Annotated[ scale_y: Annotated[
float, typer.Option(help='Y scale of the item in the scene') Optional[float], typer.Option(help='Y scale of the item in the scene')
] = None, ] = None,
): ):
"""Set the transform of an item in a scene.""" """Set the transform of an item in a scene."""