From e658819719b520f37505016b11236457f7bb2fdc Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 24 Jul 2025 02:14:38 +0100 Subject: [PATCH] convert profile commands --- obsws_cli/app.py | 1 + obsws_cli/profile.py | 97 +++++++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 8809d04..06bba97 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -26,6 +26,7 @@ for sub_app in ( 'group', 'hotkey', 'input', + 'profile', 'filter', 'scene', ): diff --git a/obsws_cli/profile.py b/obsws_cli/profile.py index 81ec825..d34b004 100644 --- a/obsws_cli/profile.py +++ b/obsws_cli/profile.py @@ -2,31 +2,29 @@ from typing import Annotated -import typer +from cyclopts import App, Argument, Parameter from rich.table import Table from rich.text import Text from . import console, util, 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='profile', help='Commands for managing profiles in OBS') -@app.callback() -def main(): - """Control profiles in OBS.""" - - -@app.command('list | ls') -def list_(ctx: typer.Context): +@app.command(name=['list', 'ls']) +def list_( + *, + ctx: Annotated[Context, Parameter(parse=False)], +): """List profiles.""" - resp = ctx.obj['obsws'].get_profile_list() + resp = ctx.client.get_profile_list() - table = Table( - title='Profiles', padding=(0, 2), border_style=ctx.obj['style'].border - ) + table = Table(title='Profiles', padding=(0, 2), border_style=ctx.style.border) columns = [ - (Text('Profile Name', justify='center'), 'left', ctx.obj['style'].column), + (Text('Profile Name', justify='center'), 'left', ctx.style.column), (Text('Current', justify='center'), 'center', None), ] for heading, justify, style in columns: @@ -43,70 +41,85 @@ def list_(ctx: typer.Context): console.out.print(table) -@app.command('current | get') -def current(ctx: typer.Context): +@app.command(name=['current', 'get']) +def current( + *, + ctx: Annotated[Context, Parameter(parse=False)], +): """Get the current profile.""" - resp = ctx.obj['obsws'].get_profile_list() + resp = ctx.client.get_profile_list() console.out.print( f'Current profile: {console.highlight(ctx, resp.current_profile_name)}' ) -@app.command('switch | set') +@app.command(name=['switch', 'set']) def switch( - ctx: typer.Context, profile_name: Annotated[ str, - typer.Argument( - ..., show_default=False, help='Name of the profile to switch to' - ), + Argument(hint='Name of the profile to switch to'), ], + /, + *, + ctx: Annotated[Context, Parameter(parse=False)], ): """Switch to a profile.""" if not validate.profile_exists(ctx, profile_name): console.err.print(f'Profile [yellow]{profile_name}[/yellow] not found.') - raise typer.Exit(1) - - resp = ctx.obj['obsws'].get_profile_list() - if resp.current_profile_name == profile_name: - console.err.print( - f'Profile [yellow]{profile_name}[/yellow] is already the current profile.' + raise OBSWSCLIError( + f'Profile [yellow]{profile_name}[/yellow] not found.', + code=ExitCode.ERROR, ) - raise typer.Exit(1) - ctx.obj['obsws'].set_current_profile(profile_name) + resp = ctx.client.get_profile_list() + if resp.current_profile_name == profile_name: + raise OBSWSCLIError( + f'Profile [yellow]{profile_name}[/yellow] is already the current profile.', + code=ExitCode.ERROR, + ) + + ctx.client.set_current_profile(profile_name) console.out.print(f'Switched to profile {console.highlight(ctx, profile_name)}.') -@app.command('create | new') +@app.command(name=['create', 'new']) def create( - ctx: typer.Context, profile_name: Annotated[ str, - typer.Argument(..., show_default=False, help='Name of the profile to create.'), + Argument(hint='Name of the profile to create.'), ], + /, + *, + ctx: Annotated[Context, Parameter(parse=False)], ): """Create a new profile.""" if validate.profile_exists(ctx, profile_name): - console.err.print(f'Profile [yellow]{profile_name}[/yellow] already exists.') - raise typer.Exit(1) + raise OBSWSCLIError( + f'Profile [yellow]{profile_name}[/yellow] already exists.', + code=ExitCode.ERROR, + ) - ctx.obj['obsws'].create_profile(profile_name) + ctx.client.create_profile(profile_name) console.out.print(f'Created profile {console.highlight(ctx, profile_name)}.') -@app.command('remove | rm') +@app.command(name=['remove', 'rm']) def remove( - ctx: typer.Context, profile_name: Annotated[ str, - typer.Argument(..., show_default=False, help='Name of the profile to remove.'), + Argument(hint='Name of the profile to remove.'), ], + /, + *, + ctx: Annotated[Context, Parameter(parse=False)], ): """Remove a profile.""" if not validate.profile_exists(ctx, profile_name): console.err.print(f'Profile [yellow]{profile_name}[/yellow] not found.') - raise typer.Exit(1) + raise OBSWSCLIError( + f'Profile [yellow]{profile_name}[/yellow] not found.', + code=ExitCode.ERROR, + ) - ctx.obj['obsws'].remove_profile(profile_name) + ctx.client.remove_profile(profile_name) console.out.print(f'Removed profile {console.highlight(ctx, profile_name)}.')