mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-08-05 11:31:44 +00:00
convert profile commands
This commit is contained in:
parent
4451fbf22c
commit
e658819719
@ -26,6 +26,7 @@ for sub_app in (
|
||||
'group',
|
||||
'hotkey',
|
||||
'input',
|
||||
'profile',
|
||||
'filter',
|
||||
'scene',
|
||||
):
|
||||
|
@ -2,31 +2,29 @@
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
import typer
|
||||
from cyclopts import App, Argument, Parameter
|
||||
from rich.table import Table
|
||||
from rich.text import Text
|
||||
|
||||
from . import console, util, validate
|
||||
from .alias import SubTyperAliasGroup
|
||||
from .context import Context
|
||||
from .enum import ExitCode
|
||||
from .error import OBSWSCLIError
|
||||
|
||||
app = typer.Typer(cls=SubTyperAliasGroup)
|
||||
app = App(name='profile', help='Commands for managing profiles in OBS')
|
||||
|
||||
|
||||
@app.callback()
|
||||
def main():
|
||||
"""Control profiles in OBS."""
|
||||
|
||||
|
||||
@app.command('list | ls')
|
||||
def list_(ctx: typer.Context):
|
||||
@app.command(name=['list', 'ls'])
|
||||
def list_(
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""List profiles."""
|
||||
resp = ctx.obj['obsws'].get_profile_list()
|
||||
resp = ctx.client.get_profile_list()
|
||||
|
||||
table = Table(
|
||||
title='Profiles', padding=(0, 2), border_style=ctx.obj['style'].border
|
||||
)
|
||||
table = Table(title='Profiles', padding=(0, 2), border_style=ctx.style.border)
|
||||
columns = [
|
||||
(Text('Profile Name', justify='center'), 'left', ctx.obj['style'].column),
|
||||
(Text('Profile Name', justify='center'), 'left', ctx.style.column),
|
||||
(Text('Current', justify='center'), 'center', None),
|
||||
]
|
||||
for heading, justify, style in columns:
|
||||
@ -43,70 +41,85 @@ def list_(ctx: typer.Context):
|
||||
console.out.print(table)
|
||||
|
||||
|
||||
@app.command('current | get')
|
||||
def current(ctx: typer.Context):
|
||||
@app.command(name=['current', 'get'])
|
||||
def current(
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""Get the current profile."""
|
||||
resp = ctx.obj['obsws'].get_profile_list()
|
||||
resp = ctx.client.get_profile_list()
|
||||
console.out.print(
|
||||
f'Current profile: {console.highlight(ctx, resp.current_profile_name)}'
|
||||
)
|
||||
|
||||
|
||||
@app.command('switch | set')
|
||||
@app.command(name=['switch', 'set'])
|
||||
def switch(
|
||||
ctx: typer.Context,
|
||||
profile_name: Annotated[
|
||||
str,
|
||||
typer.Argument(
|
||||
..., show_default=False, help='Name of the profile to switch to'
|
||||
),
|
||||
Argument(hint='Name of the profile to switch to'),
|
||||
],
|
||||
/,
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""Switch to a profile."""
|
||||
if not validate.profile_exists(ctx, profile_name):
|
||||
console.err.print(f'Profile [yellow]{profile_name}[/yellow] not found.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
resp = ctx.obj['obsws'].get_profile_list()
|
||||
if resp.current_profile_name == profile_name:
|
||||
console.err.print(
|
||||
f'Profile [yellow]{profile_name}[/yellow] is already the current profile.'
|
||||
raise OBSWSCLIError(
|
||||
f'Profile [yellow]{profile_name}[/yellow] not found.',
|
||||
code=ExitCode.ERROR,
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].set_current_profile(profile_name)
|
||||
resp = ctx.client.get_profile_list()
|
||||
if resp.current_profile_name == profile_name:
|
||||
raise OBSWSCLIError(
|
||||
f'Profile [yellow]{profile_name}[/yellow] is already the current profile.',
|
||||
code=ExitCode.ERROR,
|
||||
)
|
||||
|
||||
ctx.client.set_current_profile(profile_name)
|
||||
console.out.print(f'Switched to profile {console.highlight(ctx, profile_name)}.')
|
||||
|
||||
|
||||
@app.command('create | new')
|
||||
@app.command(name=['create', 'new'])
|
||||
def create(
|
||||
ctx: typer.Context,
|
||||
profile_name: Annotated[
|
||||
str,
|
||||
typer.Argument(..., show_default=False, help='Name of the profile to create.'),
|
||||
Argument(hint='Name of the profile to create.'),
|
||||
],
|
||||
/,
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""Create a new profile."""
|
||||
if validate.profile_exists(ctx, profile_name):
|
||||
console.err.print(f'Profile [yellow]{profile_name}[/yellow] already exists.')
|
||||
raise typer.Exit(1)
|
||||
raise OBSWSCLIError(
|
||||
f'Profile [yellow]{profile_name}[/yellow] already exists.',
|
||||
code=ExitCode.ERROR,
|
||||
)
|
||||
|
||||
ctx.obj['obsws'].create_profile(profile_name)
|
||||
ctx.client.create_profile(profile_name)
|
||||
console.out.print(f'Created profile {console.highlight(ctx, profile_name)}.')
|
||||
|
||||
|
||||
@app.command('remove | rm')
|
||||
@app.command(name=['remove', 'rm'])
|
||||
def remove(
|
||||
ctx: typer.Context,
|
||||
profile_name: Annotated[
|
||||
str,
|
||||
typer.Argument(..., show_default=False, help='Name of the profile to remove.'),
|
||||
Argument(hint='Name of the profile to remove.'),
|
||||
],
|
||||
/,
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""Remove a profile."""
|
||||
if not validate.profile_exists(ctx, profile_name):
|
||||
console.err.print(f'Profile [yellow]{profile_name}[/yellow] not found.')
|
||||
raise typer.Exit(1)
|
||||
raise OBSWSCLIError(
|
||||
f'Profile [yellow]{profile_name}[/yellow] not found.',
|
||||
code=ExitCode.ERROR,
|
||||
)
|
||||
|
||||
ctx.obj['obsws'].remove_profile(profile_name)
|
||||
ctx.client.remove_profile(profile_name)
|
||||
console.out.print(f'Removed profile {console.highlight(ctx, profile_name)}.')
|
||||
|
Loading…
x
Reference in New Issue
Block a user