mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-07 20:20:32 +01:00
print profile list as rich table
patch bump
This commit is contained in:
parent
94d6c32c31
commit
5189ee1d5b
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
__version__ = "0.12.3"
|
__version__ = "0.12.4"
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
"""module containing commands for manipulating profiles in OBS."""
|
"""module containing commands for manipulating profiles in OBS."""
|
||||||
|
|
||||||
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,52 +21,62 @@ def main():
|
|||||||
def list(ctx: typer.Context):
|
def list(ctx: typer.Context):
|
||||||
"""List profiles."""
|
"""List profiles."""
|
||||||
resp = ctx.obj.get_profile_list()
|
resp = ctx.obj.get_profile_list()
|
||||||
|
|
||||||
|
table = Table(title='Profiles')
|
||||||
|
for column in ('Name', 'Current'):
|
||||||
|
table.add_column(
|
||||||
|
column, justify='left' if column == 'Name' else 'center', style='cyan'
|
||||||
|
)
|
||||||
|
|
||||||
for profile in resp.profiles:
|
for profile in resp.profiles:
|
||||||
typer.echo(profile)
|
table.add_row(
|
||||||
|
profile,
|
||||||
|
':heavy_check_mark:' if profile == resp.current_profile_name else '',
|
||||||
|
)
|
||||||
|
|
||||||
|
out_console.print(table)
|
||||||
|
|
||||||
|
|
||||||
@app.command('current | get')
|
@app.command('current | get')
|
||||||
def current(ctx: typer.Context):
|
def current(ctx: typer.Context):
|
||||||
"""Get the current profile."""
|
"""Get the current profile."""
|
||||||
resp = ctx.obj.get_profile_list()
|
resp = ctx.obj.get_profile_list()
|
||||||
typer.echo(resp.current_profile_name)
|
out_console.print(resp.current_profile_name)
|
||||||
|
|
||||||
|
|
||||||
@app.command('switch | set')
|
@app.command('switch | set')
|
||||||
def switch(ctx: typer.Context, profile_name: str):
|
def switch(ctx: typer.Context, profile_name: str):
|
||||||
"""Switch to a profile."""
|
"""Switch to a profile."""
|
||||||
if not validate.profile_exists(ctx, profile_name):
|
if not validate.profile_exists(ctx, profile_name):
|
||||||
typer.echo(f"Profile '{profile_name}' not found.", err=True)
|
err_console.print(f"Profile '{profile_name}' not found.")
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
resp = ctx.obj.get_profile_list()
|
resp = ctx.obj.get_profile_list()
|
||||||
if resp.current_profile_name == profile_name:
|
if resp.current_profile_name == profile_name:
|
||||||
typer.echo(
|
err_console.print(f"Profile '{profile_name}' is already the current profile.")
|
||||||
f"Profile '{profile_name}' is already the current profile.", err=True
|
|
||||||
)
|
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
ctx.obj.set_current_profile(profile_name)
|
ctx.obj.set_current_profile(profile_name)
|
||||||
typer.echo(f"Switched to profile '{profile_name}'.")
|
out_console.print(f"Switched to profile '{profile_name}'.")
|
||||||
|
|
||||||
|
|
||||||
@app.command('create | new')
|
@app.command('create | new')
|
||||||
def create(ctx: typer.Context, profile_name: str):
|
def create(ctx: typer.Context, profile_name: str):
|
||||||
"""Create a new profile."""
|
"""Create a new profile."""
|
||||||
if validate.profile_exists(ctx, profile_name):
|
if validate.profile_exists(ctx, profile_name):
|
||||||
typer.echo(f"Profile '{profile_name}' already exists.", err=True)
|
err_console.print(f"Profile '{profile_name}' already exists.")
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
ctx.obj.create_profile(profile_name)
|
ctx.obj.create_profile(profile_name)
|
||||||
typer.echo(f"Created profile '{profile_name}'.")
|
out_console.print(f"Created profile '{profile_name}'.")
|
||||||
|
|
||||||
|
|
||||||
@app.command('remove | rm')
|
@app.command('remove | rm')
|
||||||
def remove(ctx: typer.Context, profile_name: str):
|
def remove(ctx: typer.Context, profile_name: str):
|
||||||
"""Remove a profile."""
|
"""Remove a profile."""
|
||||||
if not validate.profile_exists(ctx, profile_name):
|
if not validate.profile_exists(ctx, profile_name):
|
||||||
typer.echo(f"Profile '{profile_name}' not found.", err=True)
|
err_console.print(f"Profile '{profile_name}' not found.")
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
ctx.obj.remove_profile(profile_name)
|
ctx.obj.remove_profile(profile_name)
|
||||||
typer.echo(f"Removed profile '{profile_name}'.")
|
out_console.print(f"Removed profile '{profile_name}'.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user