mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-08-03 10:31:46 +00:00
convert text commands
This commit is contained in:
parent
eb939b735c
commit
506aff833c
@ -37,6 +37,7 @@ for sub_app in (
|
||||
'screenshot',
|
||||
'stream',
|
||||
'studiomode',
|
||||
'text',
|
||||
):
|
||||
module = importlib.import_module(f'.{sub_app}', package=__package__)
|
||||
app.command(module.app)
|
||||
|
@ -2,35 +2,34 @@
|
||||
|
||||
from typing import Annotated, Optional
|
||||
|
||||
import typer
|
||||
from cyclopts import App, Argument, Parameter
|
||||
|
||||
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()
|
||||
def main():
|
||||
"""Control text inputs in OBS."""
|
||||
|
||||
|
||||
@app.command('current | get')
|
||||
@app.command(name=['current', 'get'])
|
||||
def current(
|
||||
ctx: typer.Context,
|
||||
input_name: Annotated[str, typer.Argument(help='Name of the text input to get.')],
|
||||
input_name: Annotated[str, Argument(hint='Name of the text input to get.')],
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""Get the current text for a text input."""
|
||||
if not validate.input_in_inputs(ctx, input_name):
|
||||
console.err.print(f'Input [yellow]{input_name}[/yellow] not found.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
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 OBSWSCLIError(
|
||||
f'Input [yellow]{input_name}[/yellow] not found.', code=ExitCode.ERROR
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
raise typer.Exit(1)
|
||||
|
||||
current_text = resp.input_settings.get('text', '')
|
||||
if not current_text:
|
||||
@ -40,32 +39,31 @@ def current(
|
||||
)
|
||||
|
||||
|
||||
@app.command('update | set')
|
||||
@app.command(name=['update', 'set'])
|
||||
def update(
|
||||
ctx: typer.Context,
|
||||
input_name: Annotated[
|
||||
str, typer.Argument(help='Name of the text input to update.')
|
||||
],
|
||||
input_name: Annotated[str, Argument(hint='Name of the text input to update.')],
|
||||
new_text: Annotated[
|
||||
Optional[str],
|
||||
typer.Argument(
|
||||
help='The new text to set for the input.',
|
||||
),
|
||||
Argument(hint='The new text to set for the input.'),
|
||||
] = None,
|
||||
/,
|
||||
*,
|
||||
ctx: Annotated[Context, Parameter(parse=False)],
|
||||
):
|
||||
"""Update the text of a text input."""
|
||||
if not validate.input_in_inputs(ctx, input_name):
|
||||
console.err.print(f'Input [yellow]{input_name}[/yellow] not found.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
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 OBSWSCLIError(
|
||||
f'Input [yellow]{input_name}[/yellow] not found.', code=ExitCode.ERROR
|
||||
)
|
||||
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,
|
||||
settings={'text': new_text},
|
||||
overlay=True,
|
||||
|
Loading…
x
Reference in New Issue
Block a user