From 329aec084cc18606fcb309c86d0c8d27eb82f424 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 9 Jan 2026 23:07:06 +0000 Subject: [PATCH] scene_in_scenes validation now a callback --- obsws_cli/group.py | 52 +++++++++++++++++++++++------------------- obsws_cli/scene.py | 11 +++++---- obsws_cli/sceneitem.py | 5 +--- obsws_cli/validate.py | 7 ++++-- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/obsws_cli/group.py b/obsws_cli/group.py index 3279203..8ac2073 100644 --- a/obsws_cli/group.py +++ b/obsws_cli/group.py @@ -26,6 +26,7 @@ def list_( typer.Argument( show_default='The current scene', help='Scene name to list groups for', + callback=validate.scene_in_scenes, ), ] = None, ): @@ -33,10 +34,6 @@ def list_( if not scene_name: scene_name = ctx.obj['obsws'].get_current_program_scene().scene_name - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f"Scene '{scene_name}' not found.") - raise typer.Exit(1) - resp = ctx.obj['obsws'].get_scene_item_list(scene_name) groups = [ (item.get('sceneItemId'), item.get('sourceName'), item.get('sceneItemEnabled')) @@ -92,17 +89,18 @@ def show( ctx: typer.Context, scene_name: Annotated[ str, - typer.Argument(..., show_default=False, help='Scene name the group is in'), + typer.Argument( + ..., + show_default=False, + help='Scene name the group is in', + callback=validate.scene_in_scenes, + ), ], group_name: Annotated[ str, typer.Argument(..., show_default=False, help='Group name to show') ], ): """Show a group in a scene.""" - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f"Scene '{scene_name}' not found.") - raise typer.Exit(1) - resp = ctx.obj['obsws'].get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: console.err.print( @@ -123,17 +121,19 @@ def show( def hide( ctx: typer.Context, scene_name: Annotated[ - str, typer.Argument(..., show_default=False, help='Scene name the group is in') + str, + typer.Argument( + ..., + show_default=False, + help='Scene name the group is in', + callback=validate.scene_in_scenes, + ), ], group_name: Annotated[ str, typer.Argument(..., show_default=False, help='Group name to hide') ], ): """Hide a group in a scene.""" - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f'Scene [yellow]{scene_name}[/yellow] not found.') - raise typer.Exit(1) - resp = ctx.obj['obsws'].get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: console.err.print( @@ -154,17 +154,19 @@ def hide( def toggle( ctx: typer.Context, scene_name: Annotated[ - str, typer.Argument(..., show_default=False, help='Scene name the group is in') + str, + typer.Argument( + ..., + show_default=False, + help='Scene name the group is in', + callback=validate.scene_in_scenes, + ), ], group_name: Annotated[ str, typer.Argument(..., show_default=False, help='Group name to toggle') ], ): """Toggle a group in a scene.""" - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f'Scene [yellow]{scene_name}[/yellow] not found.') - raise typer.Exit(1) - resp = ctx.obj['obsws'].get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: console.err.print( @@ -189,17 +191,19 @@ def toggle( def status( ctx: typer.Context, scene_name: Annotated[ - str, typer.Argument(..., show_default=False, help='Scene name the group is in') + str, + typer.Argument( + ..., + show_default=False, + help='Scene name the group is in', + callback=validate.scene_in_scenes, + ), ], group_name: Annotated[ str, typer.Argument(..., show_default=False, help='Group name to check status') ], ): """Get the status of a group in a scene.""" - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f'Scene [yellow]{scene_name}[/yellow] not found.') - raise typer.Exit(1) - resp = ctx.obj['obsws'].get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: console.err.print( diff --git a/obsws_cli/scene.py b/obsws_cli/scene.py index 850168e..5758e84 100644 --- a/obsws_cli/scene.py +++ b/obsws_cli/scene.py @@ -94,7 +94,12 @@ def current( def switch( ctx: typer.Context, scene_name: Annotated[ - str, typer.Argument(..., help='Name of the scene to switch to') + str, + typer.Argument( + ..., + help='Name of the scene to switch to', + callback=validate.scene_in_scenes, + ), ], preview: Annotated[ bool, @@ -106,10 +111,6 @@ def switch( console.err.print('Studio mode is not enabled, cannot set the preview scene.') raise typer.Exit(1) - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f'Scene [yellow]{scene_name}[/yellow] not found.') - raise typer.Exit(1) - if preview: ctx.obj['obsws'].set_current_preview_scene(scene_name) console.out.print( diff --git a/obsws_cli/sceneitem.py b/obsws_cli/sceneitem.py index 134e0ab..1cffbda 100644 --- a/obsws_cli/sceneitem.py +++ b/obsws_cli/sceneitem.py @@ -24,6 +24,7 @@ def list_( typer.Argument( show_default='The current scene', help='Scene name to list items for', + callback=validate.scene_in_scenes, ), ] = None, uuid: Annotated[bool, typer.Option(help='Show UUIDs of scene items')] = False, @@ -32,10 +33,6 @@ def list_( if not scene_name: scene_name = ctx.obj['obsws'].get_current_program_scene().scene_name - if not validate.scene_in_scenes(ctx, scene_name): - console.err.print(f'Scene [yellow]{scene_name}[/yellow] not found.') - raise typer.Exit(1) - resp = ctx.obj['obsws'].get_scene_item_list(scene_name) items = sorted( ( diff --git a/obsws_cli/validate.py b/obsws_cli/validate.py index 02c2a20..e16a317 100644 --- a/obsws_cli/validate.py +++ b/obsws_cli/validate.py @@ -26,10 +26,13 @@ def input_not_in_inputs(ctx: typer.Context, input_name: str) -> bool: return input_name -def scene_in_scenes(ctx: typer.Context, scene_name: str) -> bool: +def scene_in_scenes(ctx: typer.Context, scene_name: str) -> str: """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) + if not any(scene.get('sceneName') == scene_name for scene in resp.scenes): + console.err.print(f'Scene [yellow]{scene_name}[/yellow] not found.') + raise typer.Exit(1) + return scene_name def studio_mode_enabled(ctx: typer.Context) -> bool: