mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2026-01-10 16:07:50 +00:00
scene_collection validation logic now in callbacks
This commit is contained in:
parent
329aec084c
commit
f74ec9cd93
@ -53,16 +53,15 @@ def current(ctx: typer.Context):
|
||||
def switch(
|
||||
ctx: typer.Context,
|
||||
scene_collection_name: Annotated[
|
||||
str, typer.Argument(..., help='Name of the scene collection to switch to')
|
||||
str,
|
||||
typer.Argument(
|
||||
...,
|
||||
help='Name of the scene collection to switch to',
|
||||
callback=validate.scene_collection_in_scene_collections,
|
||||
),
|
||||
],
|
||||
):
|
||||
"""Switch to a scene collection."""
|
||||
if not validate.scene_collection_in_scene_collections(ctx, scene_collection_name):
|
||||
console.err.print(
|
||||
f'Scene collection [yellow]{scene_collection_name}[/yellow] not found.'
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
|
||||
current_scene_collection = (
|
||||
ctx.obj['obsws'].get_scene_collection_list().current_scene_collection_name
|
||||
)
|
||||
@ -82,16 +81,15 @@ def switch(
|
||||
def create(
|
||||
ctx: typer.Context,
|
||||
scene_collection_name: Annotated[
|
||||
str, typer.Argument(..., help='Name of the scene collection to create')
|
||||
str,
|
||||
typer.Argument(
|
||||
...,
|
||||
help='Name of the scene collection to create',
|
||||
callback=validate.scene_collection_not_in_scene_collections,
|
||||
),
|
||||
],
|
||||
):
|
||||
"""Create a new scene collection."""
|
||||
if validate.scene_collection_in_scene_collections(ctx, scene_collection_name):
|
||||
console.err.print(
|
||||
f'Scene collection [yellow]{scene_collection_name}[/yellow] already exists.'
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].create_scene_collection(scene_collection_name)
|
||||
console.out.print(
|
||||
f'Created scene collection {console.highlight(ctx, scene_collection_name)}.'
|
||||
|
||||
@ -43,12 +43,32 @@ def studio_mode_enabled(ctx: typer.Context) -> bool:
|
||||
|
||||
def scene_collection_in_scene_collections(
|
||||
ctx: typer.Context, scene_collection_name: str
|
||||
) -> bool:
|
||||
"""Check if a scene collection exists."""
|
||||
) -> str:
|
||||
"""Ensure a scene collection exists in the list of scene collections."""
|
||||
resp = ctx.obj['obsws'].get_scene_collection_list()
|
||||
return any(
|
||||
if not any(
|
||||
collection == scene_collection_name for collection in resp.scene_collections
|
||||
)
|
||||
):
|
||||
console.err.print(
|
||||
f'Scene collection [yellow]{scene_collection_name}[/yellow] not found.'
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
return scene_collection_name
|
||||
|
||||
|
||||
def scene_collection_not_in_scene_collections(
|
||||
ctx: typer.Context, scene_collection_name: str
|
||||
) -> str:
|
||||
"""Ensure a scene collection does not already exist in the list of scene collections."""
|
||||
resp = ctx.obj['obsws'].get_scene_collection_list()
|
||||
if any(
|
||||
collection == scene_collection_name for collection in resp.scene_collections
|
||||
):
|
||||
console.err.print(
|
||||
f'Scene collection [yellow]{scene_collection_name}[/yellow] already exists.'
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
return scene_collection_name
|
||||
|
||||
|
||||
def item_in_scene_item_list(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user