mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-05-15 22:10:23 +01:00
add group commands toggle and status
add group unit tests minor version bump
This commit is contained in:
parent
31838800ef
commit
58429a1ccb
14
README.md
14
README.md
@ -192,6 +192,20 @@ obsws-cli group show START "test_group"
|
||||
obsws-cli group hide START "test_group"
|
||||
```
|
||||
|
||||
- toggle: Toggle a group in a scene.
|
||||
- args: <scene_name> <group_name>
|
||||
|
||||
```console
|
||||
obsws-cli group toggle START "test_group"
|
||||
```
|
||||
|
||||
- status: Get the status of a group in a scene.
|
||||
- args: <scene_name> <group_name>
|
||||
|
||||
```console
|
||||
obsws-cli group status START "test_group"
|
||||
```
|
||||
|
||||
#### Input
|
||||
|
||||
- list: List all inputs.
|
||||
|
@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = "0.6.9"
|
||||
__version__ = "0.7.0"
|
||||
|
@ -68,6 +68,8 @@ def show(ctx: typer.Context, scene_name: str, group_name: str):
|
||||
enabled=True,
|
||||
)
|
||||
|
||||
typer.echo(f"Group '{group_name}' is now visible.")
|
||||
|
||||
|
||||
@app.command()
|
||||
def hide(ctx: typer.Context, scene_name: str, group_name: str):
|
||||
@ -92,3 +94,63 @@ def hide(ctx: typer.Context, scene_name: str, group_name: str):
|
||||
item_id=int(group.get('sceneItemId')),
|
||||
enabled=False,
|
||||
)
|
||||
|
||||
typer.echo(f"Group '{group_name}' is now hidden.")
|
||||
|
||||
|
||||
@app.command('toggle | tg')
|
||||
def toggle(ctx: typer.Context, scene_name: str, group_name: str):
|
||||
"""Toggle a group in a scene."""
|
||||
if not validate.scene_in_scenes(ctx, scene_name):
|
||||
typer.echo(
|
||||
f"Scene '{scene_name}' not found.",
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
||||
if (group := _get_group(group_name, resp)) is None:
|
||||
typer.echo(
|
||||
f"Group '{group_name}' not found in scene {scene_name}.",
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
enabled = ctx.obj['obsws'].get_scene_item_enabled(
|
||||
scene_name=scene_name,
|
||||
item_id=int(group.get('sceneItemId')),
|
||||
)
|
||||
|
||||
if enabled.scene_item_enabled:
|
||||
ctx.invoke(hide, ctx=ctx, scene_name=scene_name, group_name=group_name)
|
||||
else:
|
||||
ctx.invoke(show, ctx=ctx, scene_name=scene_name, group_name=group_name)
|
||||
|
||||
|
||||
@app.command()
|
||||
def status(ctx: typer.Context, scene_name: str, group_name: str):
|
||||
"""Get the status of a group in a scene."""
|
||||
if not validate.scene_in_scenes(ctx, scene_name):
|
||||
typer.echo(
|
||||
f"Scene '{scene_name}' not found.",
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
||||
if (group := _get_group(group_name, resp)) is None:
|
||||
typer.echo(
|
||||
f"Group '{group_name}' not found in scene {scene_name}.",
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
enabled = ctx.obj['obsws'].get_scene_item_enabled(
|
||||
scene_name=scene_name,
|
||||
item_id=int(group.get('sceneItemId')),
|
||||
)
|
||||
|
||||
if enabled.scene_item_enabled:
|
||||
typer.echo(f"Group '{group_name}' is now visible.")
|
||||
else:
|
||||
typer.echo(f"Group '{group_name}' is now hidden.")
|
||||
|
@ -32,6 +32,8 @@ def pytest_sessionstart(session):
|
||||
)
|
||||
print(' '.join(out))
|
||||
|
||||
session.obsws.set_current_scene_collection('test-collection')
|
||||
|
||||
session.obsws.create_scene('pytest')
|
||||
session.obsws.create_input(
|
||||
sceneName='pytest',
|
||||
|
43
tests/test_group.py
Normal file
43
tests/test_group.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Unit tests for the group command in the OBS WebSocket CLI."""
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from obsws_cli.app import app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_group_list():
|
||||
"""Test the group list command."""
|
||||
result = runner.invoke(app, ['group', 'list', 'pytest00'])
|
||||
assert result.exit_code == 0
|
||||
assert 'test_group' in result.stdout
|
||||
|
||||
|
||||
def test_group_show():
|
||||
"""Test the group show command."""
|
||||
result = runner.invoke(app, ['group', 'show', 'pytest00', 'test_group'])
|
||||
assert result.exit_code == 0
|
||||
assert "Group 'test_group' is now visible." in result.stdout
|
||||
|
||||
|
||||
def test_group_toggle():
|
||||
"""Test the group toggle command."""
|
||||
result = runner.invoke(app, ['group', 'hide', 'pytest00', 'test_group'])
|
||||
assert result.exit_code == 0
|
||||
assert "Group 'test_group' is now hidden." in result.stdout
|
||||
|
||||
result = runner.invoke(app, ['group', 'toggle', 'pytest00', 'test_group'])
|
||||
assert result.exit_code == 0
|
||||
assert "Group 'test_group' is now visible." in result.stdout
|
||||
|
||||
|
||||
def test_group_status():
|
||||
"""Test the group status command."""
|
||||
result = runner.invoke(app, ['group', 'show', 'pytest00', 'test_group'])
|
||||
assert result.exit_code == 0
|
||||
assert "Group 'test_group' is now visible." in result.stdout
|
||||
|
||||
result = runner.invoke(app, ['group', 'status', 'pytest00', 'test_group'])
|
||||
assert result.exit_code == 0
|
||||
assert "Group 'test_group' is now visible." in result.stdout
|
Loading…
x
Reference in New Issue
Block a user