mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-07 20:20:32 +01:00
print scene collection list as rich table
This commit is contained in:
parent
b21ed78bfa
commit
fd3c020c3f
@ -1,11 +1,15 @@
|
||||
"""module containing commands for manipulating scene collections."""
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
from . import validate
|
||||
from .alias import AliasGroup
|
||||
|
||||
app = typer.Typer(cls=AliasGroup)
|
||||
out_console = Console()
|
||||
err_console = Console(stderr=True)
|
||||
|
||||
|
||||
@app.callback()
|
||||
@ -17,44 +21,49 @@ def main():
|
||||
def list(ctx: typer.Context):
|
||||
"""List all scene collections."""
|
||||
resp = ctx.obj.get_scene_collection_list()
|
||||
typer.echo('\n'.join(resp.scene_collections))
|
||||
|
||||
table = Table(title='Scene Collections')
|
||||
table.add_column('Scene Collection Name', justify='left', style='cyan')
|
||||
|
||||
for scene_collection_name in resp.scene_collections:
|
||||
table.add_row(scene_collection_name)
|
||||
|
||||
out_console.print(table)
|
||||
|
||||
|
||||
@app.command('current | get')
|
||||
def current(ctx: typer.Context):
|
||||
"""Get the current scene collection."""
|
||||
resp = ctx.obj.get_scene_collection_list()
|
||||
typer.echo(resp.current_scene_collection_name)
|
||||
out_console.print(resp.current_scene_collection_name)
|
||||
|
||||
|
||||
@app.command('switch | set')
|
||||
def switch(ctx: typer.Context, scene_collection_name: str):
|
||||
"""Switch to a scene collection."""
|
||||
if not validate.scene_collection_in_scene_collections(ctx, scene_collection_name):
|
||||
typer.echo(f"Scene collection '{scene_collection_name}' not found.", err=True)
|
||||
err_console.print(f"Scene collection '{scene_collection_name}' not found.")
|
||||
raise typer.Exit(1)
|
||||
|
||||
current_scene_collection = (
|
||||
ctx.obj.get_scene_collection_list().current_scene_collection_name
|
||||
)
|
||||
if scene_collection_name == current_scene_collection:
|
||||
typer.echo(
|
||||
f'Scene collection "{scene_collection_name}" is already active.', err=True
|
||||
err_console.print(
|
||||
f'Scene collection "{scene_collection_name}" is already active.'
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj.set_current_scene_collection(scene_collection_name)
|
||||
typer.echo(f"Switched to scene collection '{scene_collection_name}'")
|
||||
out_console.print(f"Switched to scene collection '{scene_collection_name}'")
|
||||
|
||||
|
||||
@app.command('create | new')
|
||||
def create(ctx: typer.Context, scene_collection_name: str):
|
||||
"""Create a new scene collection."""
|
||||
if validate.scene_collection_in_scene_collections(ctx, scene_collection_name):
|
||||
typer.echo(
|
||||
f"Scene collection '{scene_collection_name}' already exists.", err=True
|
||||
)
|
||||
err_console.print(f"Scene collection '{scene_collection_name}' already exists.")
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj.create_scene_collection(scene_collection_name)
|
||||
typer.echo(f'Created scene collection {scene_collection_name}')
|
||||
out_console.print(f'Created scene collection {scene_collection_name}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user