convert text commands

This commit is contained in:
onyx-and-iris 2025-07-24 04:08:07 +01:00
parent eb939b735c
commit 506aff833c
2 changed files with 35 additions and 36 deletions

View File

@ -37,6 +37,7 @@ for sub_app in (
'screenshot', 'screenshot',
'stream', 'stream',
'studiomode', 'studiomode',
'text',
): ):
module = importlib.import_module(f'.{sub_app}', package=__package__) module = importlib.import_module(f'.{sub_app}', package=__package__)
app.command(module.app) app.command(module.app)

View File

@ -2,35 +2,34 @@
from typing import Annotated, Optional from typing import Annotated, Optional
import typer from cyclopts import App, Argument, Parameter
from . import console, validate from . import console, 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='text', help='Commands for controlling text inputs in OBS.')
@app.callback() @app.command(name=['current', 'get'])
def main():
"""Control text inputs in OBS."""
@app.command('current | get')
def current( def current(
ctx: typer.Context, input_name: Annotated[str, Argument(hint='Name of the text input to get.')],
input_name: Annotated[str, typer.Argument(help='Name of the text input to get.')], *,
ctx: Annotated[Context, Parameter(parse=False)],
): ):
"""Get the current text for a text input.""" """Get the current text for a text input."""
if not validate.input_in_inputs(ctx, input_name): if not validate.input_in_inputs(ctx, input_name):
console.err.print(f'Input [yellow]{input_name}[/yellow] not found.') raise OBSWSCLIError(
raise typer.Exit(1) f'Input [yellow]{input_name}[/yellow] not found.', code=ExitCode.ERROR
)
resp = ctx.obj['obsws'].get_input_settings(name=input_name)
if not resp.input_kind.startswith('text_'): resp = ctx.client.get_input_settings(name=input_name)
console.err.print( if not resp.input_kind.startswith('text_'):
f'Input [yellow]{input_name}[/yellow] is not a text input.', raise OBSWSCLIError(
f'Input [yellow]{input_name}[/yellow] is not a text input.',
code=ExitCode.ERROR,
) )
raise typer.Exit(1)
current_text = resp.input_settings.get('text', '') current_text = resp.input_settings.get('text', '')
if not current_text: if not current_text:
@ -40,32 +39,31 @@ def current(
) )
@app.command('update | set') @app.command(name=['update', 'set'])
def update( def update(
ctx: typer.Context, input_name: Annotated[str, Argument(hint='Name of the text input to update.')],
input_name: Annotated[
str, typer.Argument(help='Name of the text input to update.')
],
new_text: Annotated[ new_text: Annotated[
Optional[str], Optional[str],
typer.Argument( Argument(hint='The new text to set for the input.'),
help='The new text to set for the input.',
),
] = None, ] = None,
/,
*,
ctx: Annotated[Context, Parameter(parse=False)],
): ):
"""Update the text of a text input.""" """Update the text of a text input."""
if not validate.input_in_inputs(ctx, input_name): if not validate.input_in_inputs(ctx, input_name):
console.err.print(f'Input [yellow]{input_name}[/yellow] not found.') raise OBSWSCLIError(
raise typer.Exit(1) f'Input [yellow]{input_name}[/yellow] not found.', code=ExitCode.ERROR
resp = ctx.obj['obsws'].get_input_settings(name=input_name)
if not resp.input_kind.startswith('text_'):
console.err.print(
f'Input [yellow]{input_name}[/yellow] is not a text input.',
) )
raise typer.Exit(1)
ctx.obj['obsws'].set_input_settings( resp = ctx.client.get_input_settings(name=input_name)
if not resp.input_kind.startswith('text_'):
raise OBSWSCLIError(
f'Input [yellow]{input_name}[/yellow] is not a text input.',
code=ExitCode.ERROR,
)
ctx.client.set_input_settings(
name=input_name, name=input_name,
settings={'text': new_text}, settings={'text': new_text},
overlay=True, overlay=True,