From 80da58bd6fd6708af5494de515c85076bd39d8da Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 12 Jun 2025 13:45:38 +0100 Subject: [PATCH] add --id option, this allows a user to optionally show the source ids --- src/slobs_cli/audio.py | 8 +++++--- src/slobs_cli/cli.py | 2 +- src/slobs_cli/scene.py | 36 ++++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/slobs_cli/audio.py b/src/slobs_cli/audio.py index 1c46cce..30281d2 100644 --- a/src/slobs_cli/audio.py +++ b/src/slobs_cli/audio.py @@ -12,8 +12,9 @@ def audio(): @audio.command() +@click.option("--id", is_flag=True, help="Include audio source IDs in the output.") @click.pass_context -async def list(ctx: click.Context): +async def list(ctx: click.Context, id: bool = False): """List all audio sources.""" conn = ctx.obj["connection"] @@ -30,8 +31,9 @@ async def list(ctx: click.Context): for source in sources: model = await source.get_model() click.echo( - f"- {click.style(model.name, fg='blue')} (ID: {model.source_id}, " - f"Muted: {click.style('✅', fg='green') if model.muted else click.style('❌', fg='red')})" + f"- {click.style(model.name, fg='blue')} " + f"{f'ID: {model.source_id}, ' if id else ''}" + f"Muted: {click.style('✅', fg='green') if model.muted else click.style('❌', fg='red')}" ) conn.close() diff --git a/src/slobs_cli/cli.py b/src/slobs_cli/cli.py index 36b396e..c05a0fe 100644 --- a/src/slobs_cli/cli.py +++ b/src/slobs_cli/cli.py @@ -36,7 +36,7 @@ from .__about__ import __version__ as version version, "-v", "--version", message="%(prog)s version: %(version)s" ) @click.pass_context -async def cli(ctx: click.Context, domain: str, port: int, token: str | None): +async def cli(ctx: click.Context, domain: str, port: int, token: str): """Command line interface for Streamlabs Desktop.""" ctx.ensure_object(dict) config = ConnectionConfig( diff --git a/src/slobs_cli/scene.py b/src/slobs_cli/scene.py index 11eae07..8c86d12 100644 --- a/src/slobs_cli/scene.py +++ b/src/slobs_cli/scene.py @@ -12,8 +12,9 @@ def scene(): @scene.command() +@click.option("--id", is_flag=True, help="Include scene IDs in the output.") @click.pass_context -async def list(ctx: click.Context): +async def list(ctx: click.Context, id: bool = False): """List all available scenes.""" conn = ctx.obj["connection"] @@ -32,10 +33,14 @@ async def list(ctx: click.Context): for scene in scenes: if scene.id == active_scene.id: click.echo( - f"- {click.style(scene.name, fg='green')} (ID: {scene.id}) [Active]" + f"- {click.style(scene.name, fg='green')} " + f"{f'(ID: {scene.id})' if id else ''} [Active]" ) else: - click.echo(f"- {click.style(scene.name, fg='blue')} (ID: {scene.id})") + click.echo( + f"- {click.style(scene.name, fg='blue')} " + f"{f'(ID: {scene.id})' if id else ''}" + ) conn.close() @@ -45,8 +50,9 @@ async def list(ctx: click.Context): @scene.command() +@click.option("--id", is_flag=True, help="Include scene IDs in the output.") @click.pass_context -async def current(ctx: click.Context): +async def current(ctx: click.Context, id: bool = False): """Show the currently active scene.""" conn = ctx.obj["connection"] @@ -55,7 +61,8 @@ async def current(ctx: click.Context): async def _run(): active_scene = await ss.active_scene() click.echo( - f"Current active scene: {click.style(active_scene.name, fg='green')} (ID: {active_scene.id})" + f"Current active scene: {click.style(active_scene.name, fg='green')} " + f"{f'(ID: {active_scene.id})' if id else ''}" ) conn.close() @@ -65,6 +72,7 @@ async def current(ctx: click.Context): @scene.command() +@click.option("--id", is_flag=True, help="Include scene IDs in the output.") @click.argument("scene_name", type=str) @click.option( "--preview", @@ -72,7 +80,9 @@ async def current(ctx: click.Context): help="Switch the preview scene only.", ) @click.pass_context -async def switch(ctx: click.Context, scene_name: str, preview: bool = False): +async def switch( + ctx: click.Context, scene_name: str, preview: bool = False, id: bool = False +): """Switch to a scene by its name.""" conn = ctx.obj["connection"] @@ -89,23 +99,29 @@ async def switch(ctx: click.Context, scene_name: str, preview: bool = False): await ss.make_scene_active(scene.id) if preview: click.echo( - f"Switched to scene: {click.style(scene.name, fg='blue')} (ID: {scene.id}) in preview mode." + f"Switched to preview scene: {click.style(scene.name, fg='blue')} " + f"{f'(ID: {scene.id}).' if id else ''}" ) else: + click.echo( + f"Switched to scene: {click.style(scene.name, fg='blue')} " + f"{f'(ID: {scene.id}).' if id else ''}" + ) await ts.execute_studio_mode_transition() click.echo( - f"Switched to scene: {click.style(scene.name, fg='blue')} (ID: {scene.id}) in active mode." + "Executed studio mode transition to make the scene active." ) else: if preview: conn.close() raise SlobsCliError( - "Cannot switch to preview scene in non-studio mode." + "Cannot switch the preview scene in non-studio mode." ) await ss.make_scene_active(scene.id) click.echo( - f"Switched to scene: {click.style(scene.name, fg='blue')} (ID: {scene.id}) in active mode." + f"Switched to scene: {click.style(scene.name, fg='blue')} " + f"{f'(ID: {scene.id}).' if id else ''}" ) conn.close()