diff --git a/obsws_cli/group.py b/obsws_cli/group.py index 139d7cb..b619cab 100644 --- a/obsws_cli/group.py +++ b/obsws_cli/group.py @@ -2,6 +2,7 @@ import typer +from . import validate from .alias import AliasGroup from .protocols import DataclassProtocol @@ -13,16 +14,10 @@ def main(): """Control groups in OBS scenes.""" -def _scene_in_scenes(ctx: typer.Context, scene_name: str) -> bool: - """Check if a scene exists in the list of scenes.""" - resp = ctx.obj['obsws'].get_scene_list() - return any(scene.get('sceneName') == scene_name for scene in resp.scenes) - - @app.command('list | ls') def list(ctx: typer.Context, scene_name: str): """List groups in a scene.""" - if not _scene_in_scenes(ctx, scene_name): + if not validate.scene_in_scenes(ctx, scene_name): typer.echo( f"Scene '{scene_name}' not found.", err=True, @@ -52,7 +47,7 @@ def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None: @app.command() def show(ctx: typer.Context, scene_name: str, group_name: str): """Show a group in a scene.""" - if not _scene_in_scenes(ctx, scene_name): + if not validate.scene_in_scenes(ctx, scene_name): typer.echo( f"Scene '{scene_name}' not found.", err=True, @@ -77,7 +72,7 @@ def show(ctx: typer.Context, scene_name: str, group_name: str): @app.command() def hide(ctx: typer.Context, scene_name: str, group_name: str): """Hide a group in a scene.""" - if not _scene_in_scenes(ctx, scene_name): + if not validate.scene_in_scenes(ctx, scene_name): typer.echo( f"Scene '{scene_name}' not found.", err=True, diff --git a/obsws_cli/input.py b/obsws_cli/input.py index 68ae9b0..143a25e 100644 --- a/obsws_cli/input.py +++ b/obsws_cli/input.py @@ -4,6 +4,7 @@ from typing import Annotated import typer +from . import validate from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) @@ -39,16 +40,10 @@ def list( typer.echo('\n'.join(input_.get('inputName') for input_ in inputs)) -def _input_in_inputs(ctx: typer.Context, input_name: str) -> bool: - """Check if an input is in the input list.""" - inputs = ctx.obj['obsws'].get_input_list().inputs - return any(input_.get('inputName') == input_name for input_ in inputs) - - @app.command() def mute(ctx: typer.Context, input_name: str): """Mute an input.""" - if not _input_in_inputs(ctx, input_name): + if not validate.input_in_inputs(ctx, input_name): typer.echo( f"Input '{input_name}' not found.", err=True, @@ -64,7 +59,7 @@ def mute(ctx: typer.Context, input_name: str): @app.command() def unmute(ctx: typer.Context, input_name: str): """Unmute an input.""" - if not _input_in_inputs(ctx, input_name): + if not validate.input_in_inputs(ctx, input_name): typer.echo( f"Input '{input_name}' not found.", err=True, @@ -80,7 +75,7 @@ def unmute(ctx: typer.Context, input_name: str): @app.command('toggle | tg') def toggle(ctx: typer.Context, input_name: str): """Toggle an input.""" - if not _input_in_inputs(ctx, input_name): + if not validate.input_in_inputs(ctx, input_name): typer.echo( f"Input '{input_name}' not found.", err=True, diff --git a/obsws_cli/scene.py b/obsws_cli/scene.py index b39046b..a5b469e 100644 --- a/obsws_cli/scene.py +++ b/obsws_cli/scene.py @@ -23,12 +23,6 @@ def list(ctx: typer.Context): typer.echo('\n'.join(scenes)) -def _studio_mode_enabled(ctx: typer.Context) -> bool: - """Check if studio mode is enabled.""" - resp = ctx.obj['obsws'].get_studio_mode_enabled() - return resp.studio_mode_enabled - - @app.command('current | get') def current( ctx: typer.Context, @@ -37,7 +31,7 @@ def current( ] = False, ): """Get the current program scene or preview scene.""" - if preview and not _studio_mode_enabled(ctx): + if preview and not validate.studio_mode_enabled(ctx): typer.echo('Studio mode is not enabled, cannot get preview scene.') raise typer.Exit(1) @@ -59,7 +53,7 @@ def switch( ] = False, ): """Switch to a scene.""" - if preview and not _studio_mode_enabled(ctx): + if preview and not validate.studio_mode_enabled(ctx): typer.echo('Studio mode is not enabled, cannot set the preview scene.') raise typer.Exit(1)