From 9cdbc657fa97e001509f28cfb827f0b74e47deb6 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 9 Jan 2026 23:19:49 +0000 Subject: [PATCH] profile_exists validation log now callbacks --- obsws_cli/profile.py | 31 ++++++++++++++++--------------- obsws_cli/validate.py | 18 +++++++++++++++--- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/obsws_cli/profile.py b/obsws_cli/profile.py index a856c58..1b7ee81 100644 --- a/obsws_cli/profile.py +++ b/obsws_cli/profile.py @@ -62,15 +62,14 @@ def switch( profile_name: Annotated[ str, typer.Argument( - ..., show_default=False, help='Name of the profile to switch to' + ..., + show_default=False, + help='Name of the profile to switch to', + callback=validate.profile_exists, ), ], ): """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( @@ -87,14 +86,15 @@ def create( ctx: typer.Context, profile_name: Annotated[ str, - typer.Argument(..., show_default=False, help='Name of the profile to create.'), + typer.Argument( + ..., + show_default=False, + help='Name of the profile to create.', + callback=validate.profile_not_exists, + ), ], ): """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) - ctx.obj['obsws'].create_profile(profile_name) console.out.print(f'Created profile {console.highlight(ctx, profile_name)}.') @@ -104,13 +104,14 @@ def remove( ctx: typer.Context, profile_name: Annotated[ str, - typer.Argument(..., show_default=False, help='Name of the profile to remove.'), + typer.Argument( + ..., + show_default=False, + help='Name of the profile to remove.', + callback=validate.profile_exists, + ), ], ): """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) - ctx.obj['obsws'].remove_profile(profile_name) console.out.print(f'Removed profile {console.highlight(ctx, profile_name)}.') diff --git a/obsws_cli/validate.py b/obsws_cli/validate.py index feb1915..c0f82b8 100644 --- a/obsws_cli/validate.py +++ b/obsws_cli/validate.py @@ -79,10 +79,22 @@ def item_in_scene_item_list( return any(item.get('sourceName') == item_name for item in resp.scene_items) -def profile_exists(ctx: typer.Context, profile_name: str) -> bool: - """Check if a profile exists.""" +def profile_exists(ctx: typer.Context, profile_name: str) -> str: + """Ensure a profile exists.""" resp = ctx.obj['obsws'].get_profile_list() - return any(profile == profile_name for profile in resp.profiles) + if not any(profile == profile_name for profile in resp.profiles): + console.err.print(f'Profile [yellow]{profile_name}[/yellow] not found.') + raise typer.Exit(1) + return profile_name + + +def profile_not_exists(ctx: typer.Context, profile_name: str) -> str: + """Ensure a profile does not exist.""" + resp = ctx.obj['obsws'].get_profile_list() + if any(profile == profile_name for profile in resp.profiles): + console.err.print(f'Profile [yellow]{profile_name}[/yellow] already exists.') + raise typer.Exit(1) + return profile_name def monitor_exists(ctx: typer.Context, monitor_index: int) -> bool: