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