convert scenecollection commands

This commit is contained in:
onyx-and-iris 2025-07-24 02:34:15 +01:00
parent a3dff0f739
commit e8664f0117
2 changed files with 44 additions and 36 deletions

View File

@ -32,6 +32,7 @@ for sub_app in (
'record', 'record',
'replaybuffer', 'replaybuffer',
'scene', 'scene',
'scenecollection',
): ):
module = importlib.import_module(f'.{sub_app}', package=__package__) module = importlib.import_module(f'.{sub_app}', package=__package__)
app.command(module.app) app.command(module.app)

View File

@ -2,33 +2,33 @@
from typing import Annotated from typing import Annotated
import typer from cyclopts import App, Argument, Parameter
from rich.table import Table from rich.table import Table
from . import console, validate from . import console, validate
from .alias import SubTyperAliasGroup from .context import Context
from .enum import ExitCode
from .error import OBSWSCLIError
app = typer.Typer(cls=SubTyperAliasGroup) app = App(
name='scenecollection', help='Commands for controlling scene collections in OBS.'
)
@app.callback() @app.command(name=['list', 'ls'])
def main(): def list_(
"""Control scene collections in OBS.""" *,
ctx: Annotated[Context, Parameter(parse=False)],
):
@app.command('list | ls')
def list_(ctx: typer.Context):
"""List all scene collections.""" """List all scene collections."""
resp = ctx.obj['obsws'].get_scene_collection_list() resp = ctx.client.get_scene_collection_list()
table = Table( table = Table(
title='Scene Collections', title='Scene Collections',
padding=(0, 2), padding=(0, 2),
border_style=ctx.obj['style'].border, border_style=ctx.style.border,
)
table.add_column(
'Scene Collection Name', justify='left', style=ctx.obj['style'].column
) )
table.add_column('Scene Collection Name', justify='left', style=ctx.style.column)
for scene_collection_name in resp.scene_collections: for scene_collection_name in resp.scene_collections:
table.add_row(scene_collection_name) table.add_row(scene_collection_name)
@ -36,59 +36,66 @@ def list_(ctx: typer.Context):
console.out.print(table) console.out.print(table)
@app.command('current | get') @app.command(name=['current', 'get'])
def current(ctx: typer.Context): def current(
*,
ctx: Annotated[Context, Parameter(parse=False)],
):
"""Get the current scene collection.""" """Get the current scene collection."""
resp = ctx.obj['obsws'].get_scene_collection_list() resp = ctx.client.get_scene_collection_list()
console.out.print( console.out.print(
f'Current scene collection: {console.highlight(ctx, resp.current_scene_collection_name)}' f'Current scene collection: {console.highlight(ctx, resp.current_scene_collection_name)}'
) )
@app.command('switch | set') @app.command(name=['switch', 'set'])
def switch( def switch(
ctx: typer.Context,
scene_collection_name: Annotated[ scene_collection_name: Annotated[
str, typer.Argument(..., help='Name of the scene collection to switch to') str, Argument(hint='Name of the scene collection to switch to')
], ],
/,
*,
ctx: Annotated[Context, Parameter(parse=False)],
): ):
"""Switch to a scene collection.""" """Switch to a scene collection."""
if not validate.scene_collection_in_scene_collections(ctx, scene_collection_name): if not validate.scene_collection_in_scene_collections(ctx, scene_collection_name):
console.err.print( raise OBSWSCLIError(
f'Scene collection [yellow]{scene_collection_name}[/yellow] not found.' f'Scene collection [yellow]{scene_collection_name}[/yellow] not found.',
exit_code=ExitCode.ERROR,
) )
raise typer.Exit(1)
current_scene_collection = ( current_scene_collection = (
ctx.obj['obsws'].get_scene_collection_list().current_scene_collection_name ctx.client.get_scene_collection_list().current_scene_collection_name
) )
if scene_collection_name == current_scene_collection: if scene_collection_name == current_scene_collection:
console.err.print( raise OBSWSCLIError(
f'Scene collection [yellow]{scene_collection_name}[/yellow] is already active.' f'Scene collection [yellow]{scene_collection_name}[/yellow] is already active.',
exit_code=ExitCode.ERROR,
) )
raise typer.Exit(1)
ctx.obj['obsws'].set_current_scene_collection(scene_collection_name) ctx.client.set_current_scene_collection(scene_collection_name)
console.out.print( console.out.print(
f'Switched to scene collection {console.highlight(ctx, scene_collection_name)}.' f'Switched to scene collection {console.highlight(ctx, scene_collection_name)}.'
) )
@app.command('create | new') @app.command(name=['create', 'new'])
def create( def create(
ctx: typer.Context,
scene_collection_name: Annotated[ scene_collection_name: Annotated[
str, typer.Argument(..., help='Name of the scene collection to create') str, Argument(hint='Name of the scene collection to create')
], ],
/,
*,
ctx: Annotated[Context, Parameter(parse=False)],
): ):
"""Create a new scene collection.""" """Create a new scene collection."""
if validate.scene_collection_in_scene_collections(ctx, scene_collection_name): if validate.scene_collection_in_scene_collections(ctx, scene_collection_name):
console.err.print( raise OBSWSCLIError(
f'Scene collection [yellow]{scene_collection_name}[/yellow] already exists.' f'Scene collection [yellow]{scene_collection_name}[/yellow] already exists.',
exit_code=ExitCode.ERROR,
) )
raise typer.Exit(1)
ctx.obj['obsws'].create_scene_collection(scene_collection_name) ctx.client.create_scene_collection(scene_collection_name)
console.out.print( console.out.print(
f'Created scene collection {console.highlight(ctx, scene_collection_name)}.' f'Created scene collection {console.highlight(ctx, scene_collection_name)}.'
) )