mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-05-16 06:20:23 +01:00
add validation logic to clean up the trace stacks
This commit is contained in:
parent
9901a6b295
commit
c0dc55724f
@ -1,6 +1,5 @@
|
||||
"""module containing commands for manipulating scene collections."""
|
||||
|
||||
import obsws_python as obsws
|
||||
import typer
|
||||
|
||||
from .alias import AliasGroup
|
||||
@ -27,9 +26,23 @@ def current(ctx: typer.Context):
|
||||
typer.echo(resp.current_scene_collection_name)
|
||||
|
||||
|
||||
def _scene_collection_in_scene_collections(
|
||||
ctx: typer.Context, scene_collection_name: str
|
||||
) -> bool:
|
||||
"""Check if a scene collection exists."""
|
||||
resp = ctx.obj['obsws'].get_scene_collection_list()
|
||||
return any(
|
||||
collection == scene_collection_name for collection in resp.scene_collections
|
||||
)
|
||||
|
||||
|
||||
@app.command('switch | set')
|
||||
def switch(ctx: typer.Context, scene_collection_name: str):
|
||||
"""Switch to a scene collection."""
|
||||
if not _scene_collection_in_scene_collections(ctx, scene_collection_name):
|
||||
typer.echo(f"Scene collection '{scene_collection_name}' not found.", err=True)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
current_scene_collection = (
|
||||
ctx.obj['obsws'].get_scene_collection_list().current_scene_collection_name
|
||||
)
|
||||
@ -39,28 +52,18 @@ def switch(ctx: typer.Context, scene_collection_name: str):
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
try:
|
||||
ctx.obj['obsws'].set_current_scene_collection(scene_collection_name)
|
||||
typer.echo(f'Switched to scene collection {scene_collection_name}')
|
||||
except obsws.error.OBSSDKRequestError as e:
|
||||
if e.code == 600:
|
||||
typer.echo(
|
||||
f'Scene collection "{scene_collection_name}" does not exist.',
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=e.code)
|
||||
ctx.obj['obsws'].set_current_scene_collection(scene_collection_name)
|
||||
typer.echo(f"Switched to scene collection '{scene_collection_name}'")
|
||||
|
||||
|
||||
@app.command('create | new')
|
||||
def create(ctx: typer.Context, scene_collection_name: str):
|
||||
"""Create a new scene collection."""
|
||||
try:
|
||||
ctx.obj['obsws'].create_scene_collection(scene_collection_name)
|
||||
typer.echo(f'Created scene collection {scene_collection_name}')
|
||||
except obsws.error.OBSSDKRequestError as e:
|
||||
if e.code == 601:
|
||||
typer.echo(
|
||||
f'Scene collection "{scene_collection_name}" already exists.',
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=e.code)
|
||||
if _scene_collection_in_scene_collections(ctx, scene_collection_name):
|
||||
typer.echo(
|
||||
f"Scene collection '{scene_collection_name}' already exists.", err=True
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
ctx.obj['obsws'].create_scene_collection(scene_collection_name)
|
||||
typer.echo(f'Created scene collection {scene_collection_name}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user