mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2026-01-10 16:07:50 +00:00
scene_in_scenes validation now a callback
This commit is contained in:
parent
3eaa3992a0
commit
329aec084c
@ -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(
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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(
|
||||
(
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user