mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-07 20:20:32 +01:00
print sceneitem list as rich table
scene_name arg now optional upd README
This commit is contained in:
parent
fd3c020c3f
commit
5988f450b4
@ -96,7 +96,10 @@ obsws-cli scene switch LIVE
|
|||||||
#### Scene Item
|
#### Scene Item
|
||||||
|
|
||||||
- list: List all items in a scene.
|
- list: List all items in a scene.
|
||||||
|
|
||||||
|
*optional*
|
||||||
- args: <scene_name>
|
- args: <scene_name>
|
||||||
|
- defaults to current scene
|
||||||
|
|
||||||
```console
|
```console
|
||||||
obsws-cli sceneitem list LIVE
|
obsws-cli sceneitem list LIVE
|
||||||
|
@ -4,11 +4,15 @@ from collections.abc import Callable
|
|||||||
from typing import Annotated, Optional
|
from typing import Annotated, Optional
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
from . import validate
|
from . import validate
|
||||||
from .alias import AliasGroup
|
from .alias import AliasGroup
|
||||||
|
|
||||||
app = typer.Typer(cls=AliasGroup)
|
app = typer.Typer(cls=AliasGroup)
|
||||||
|
out_console = Console()
|
||||||
|
err_console = Console(stderr=True)
|
||||||
|
|
||||||
|
|
||||||
@app.callback()
|
@app.callback()
|
||||||
@ -17,15 +21,34 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
@app.command('list | ls')
|
@app.command('list | ls')
|
||||||
def list(ctx: typer.Context, scene_name: str):
|
def list(
|
||||||
|
ctx: typer.Context,
|
||||||
|
scene_name: str = typer.Argument(
|
||||||
|
None, help='Scene name (optional, defaults to current scene)'
|
||||||
|
),
|
||||||
|
):
|
||||||
"""List all items in a scene."""
|
"""List all items in a scene."""
|
||||||
|
if not scene_name:
|
||||||
|
scene_name = ctx.obj.get_current_program_scene().scene_name
|
||||||
|
|
||||||
if not validate.scene_in_scenes(ctx, scene_name):
|
if not validate.scene_in_scenes(ctx, scene_name):
|
||||||
typer.echo(f"Scene '{scene_name}' not found.", err=True)
|
err_console.print(f"Scene '{scene_name}' not found.")
|
||||||
typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
resp = ctx.obj.get_scene_item_list(scene_name)
|
resp = ctx.obj.get_scene_item_list(scene_name)
|
||||||
items = (item.get('sourceName') for item in resp.scene_items)
|
items = [item.get('sourceName') for item in resp.scene_items]
|
||||||
typer.echo('\n'.join(items))
|
|
||||||
|
if not items:
|
||||||
|
err_console.print(f"No items found in scene '{scene_name}'.")
|
||||||
|
raise typer.Exit(1)
|
||||||
|
|
||||||
|
table = Table(title=f'Items in Scene: {scene_name}')
|
||||||
|
table.add_column('Item Name', justify='left', style='cyan')
|
||||||
|
|
||||||
|
for item in items:
|
||||||
|
table.add_row(item)
|
||||||
|
|
||||||
|
out_console.print(table)
|
||||||
|
|
||||||
|
|
||||||
def _validate_scene_name_and_item_name(
|
def _validate_scene_name_and_item_name(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user